diff --git a/src/api.ts b/src/api.ts index fa7cdeb..42e406d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -12,7 +12,7 @@ import { export const router = Router(); -router.get('/user', (req, res) => { +router.get('/user', async (req, res) => { if (typeof req.query.userID != 'string') { return; } @@ -23,7 +23,7 @@ router.get('/user', (req, res) => { userID = req.session.accountID; } - let user = getUserByID(userID); + let user = await getUserByID(userID); if (user) { res.json({ status: 'success', data: user }); diff --git a/src/data.ts b/src/data.ts index 9f359b4..9a57bab 100644 --- a/src/data.ts +++ b/src/data.ts @@ -57,8 +57,8 @@ export function getPoolsWithUser(userID: string) { return poolIDs; } -export function getUserByID(userID: string): Carpool.User | undefined { - return users[userID]; +export async function getUserByID(userID: string) { + return await UserModel.findById(userID).exec(); } export function getPoolByID(poolID: string): Carpool.Pool | undefined { @@ -72,7 +72,9 @@ export function getGroupByID(groupID: string): Carpool.Group | undefined { export async function getUserByEmail( email: string ): Promise<Carpool.User | undefined> { - return undefined; + return ((await UserModel.findOne({ + email, + }).exec()) as unknown) as Carpool.User; } export async function registerUserFromIonProfile(