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