Revert "remove keys from object helper func"
This reverts commit 4cff2ec886869b8a391ca294d65adcae4b2ccf19.
This commit is contained in:
parent
4cff2ec886
commit
4ea70c18ee
@ -1,15 +1,18 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
import config from "@/config.json";
|
||||
import { removeKeysFromObject } from "@/src/helpers/general";
|
||||
|
||||
import { toLoginRequest } from "@/src/helpers/loginHelpers";
|
||||
import { Account } from "@/src/models/loginModel";
|
||||
import { createAccount, isCorrectPassword } from "@/src/services/loginService";
|
||||
import { ILoginResponse } from "@/src/types/loginTypes";
|
||||
import { DTLS, HUB, IRC, NRS, Nonce, groups, platformCDNs } from "@/static/fixed_responses/login_static";
|
||||
import { RequestHandler } from "express";
|
||||
import { DTLS, groups, HUB, IRC, Nonce, NRS, platformCDNs } from "@/static/fixed_responses/login_static";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
const loginController: RequestHandler = async (request, response) => {
|
||||
const body: unknown = JSON.parse(String(request.body));
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
|
||||
const body = JSON.parse(request.body); // parse octet stream of json data to json object
|
||||
const loginRequest = toLoginRequest(body);
|
||||
|
||||
const account = await Account.findOne({ email: loginRequest.email }); //{ _id: 0, __v: 0 }
|
||||
@ -27,8 +30,9 @@ const loginController: RequestHandler = async (request, response) => {
|
||||
ConsentNeeded: false,
|
||||
TrackedSettings: []
|
||||
});
|
||||
|
||||
const databaseAccount = removeKeysFromObject(newAccount, ["email", "password"]);
|
||||
console.log("creating new account");
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { email, password, ...databaseAccount } = newAccount;
|
||||
const newLoginResponse: ILoginResponse = {
|
||||
...databaseAccount,
|
||||
Groups: groups,
|
||||
@ -57,7 +61,7 @@ const loginController: RequestHandler = async (request, response) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const databaseAccount = removeKeysFromObject(account.toJSON(), ["email", "password"]);
|
||||
const { email, password, ...databaseAccount } = account.toJSON();
|
||||
const newLoginResponse: ILoginResponse = {
|
||||
...databaseAccount,
|
||||
Groups: groups,
|
||||
|
@ -55,21 +55,4 @@ const parseBoolean = (booleanCandidate: unknown): boolean => {
|
||||
return booleanCandidate;
|
||||
};
|
||||
|
||||
function removeKeysFromObject<T>(object: T, keys: Array<keyof T>): Partial<T> {
|
||||
const newObject: Partial<T> = object;
|
||||
for (const key of keys) {
|
||||
delete newObject[key];
|
||||
}
|
||||
return newObject;
|
||||
}
|
||||
|
||||
export {
|
||||
isString,
|
||||
isNumber,
|
||||
parseString,
|
||||
parseNumber,
|
||||
parseDateNumber,
|
||||
parseBoolean,
|
||||
parseEmail,
|
||||
removeKeysFromObject
|
||||
};
|
||||
export { isString, isNumber, parseString, parseNumber, parseDateNumber, parseBoolean, parseEmail };
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { removeKeysFromObject } from "@/src/helpers/general";
|
||||
import { IInventoryDatabase } from "@/src/types/inventoryTypes";
|
||||
import { IInventoryDatabase, IInventoryResponse } from "@/src/types/inventoryTypes";
|
||||
|
||||
const toInventoryResponse = (inventoryDatabase: IInventoryDatabase) => {
|
||||
return removeKeysFromObject(inventoryDatabase, ["accountOwnerId"]);
|
||||
const toInventoryResponse = (inventoryDatabase: IInventoryDatabase): IInventoryResponse => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { accountOwnerId, ...inventoreResponse } = inventoryDatabase;
|
||||
return inventoreResponse;
|
||||
};
|
||||
|
||||
export { toInventoryResponse };
|
||||
|
@ -1,4 +1,4 @@
|
||||
export interface ILoginResponse extends Omit<Partial<IDatabaseAccountDocument>, "email" | "password"> {
|
||||
export interface ILoginResponse extends Omit<IDatabaseAccountDocument, "email" | "password"> {
|
||||
Groups: IGroup[];
|
||||
Nonce: number;
|
||||
BuildLabel: string;
|
||||
|
Loading…
x
Reference in New Issue
Block a user