From c330d78fb318b85c9ce954bd95293af1a962d9a2 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 22 Jan 2023 19:49:27 +0100 Subject: [PATCH] Created account.ts#getSimpleAccountObjectById --- src/controller/account.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/controller/account.ts b/src/controller/account.ts index caed0ab..bd678cf 100644 --- a/src/controller/account.ts +++ b/src/controller/account.ts @@ -59,4 +59,13 @@ export const updateTOTP = async (id: ObjectId | undefined, status: boolean) => { }; await Account.findByIdAndUpdate(id, { totpEnabled: status }); -}; \ No newline at end of file +}; + +export const getSimpleAccountObjectById = async (id: string) => { + if (!Types.ObjectId.isValid(id)) return { code: 3, message: "Invalid object id provided" }; + + const account = await Account.findById(id); + if (account === null) return {}; + + return {id: account._id, username: account.username, email: account.email}; +} \ No newline at end of file