Implement getUser methods

This commit is contained in:
Michael Fatemi 2021-04-10 18:49:41 -04:00
parent 743dec9c38
commit 956ba14e29
2 changed files with 7 additions and 5 deletions

View File

@ -12,7 +12,7 @@ import {
export const router = Router(); export const router = Router();
router.get('/user', (req, res) => { router.get('/user', async (req, res) => {
if (typeof req.query.userID != 'string') { if (typeof req.query.userID != 'string') {
return; return;
} }
@ -23,7 +23,7 @@ router.get('/user', (req, res) => {
userID = req.session.accountID; userID = req.session.accountID;
} }
let user = getUserByID(userID); let user = await getUserByID(userID);
if (user) { if (user) {
res.json({ status: 'success', data: user }); res.json({ status: 'success', data: user });

View File

@ -57,8 +57,8 @@ export function getPoolsWithUser(userID: string) {
return poolIDs; return poolIDs;
} }
export function getUserByID(userID: string): Carpool.User | undefined { export async function getUserByID(userID: string) {
return users[userID]; return await UserModel.findById(userID).exec();
} }
export function getPoolByID(poolID: string): Carpool.Pool | undefined { export function getPoolByID(poolID: string): Carpool.Pool | undefined {
@ -72,7 +72,9 @@ export function getGroupByID(groupID: string): Carpool.Group | undefined {
export async function getUserByEmail( export async function getUserByEmail(
email: string email: string
): Promise<Carpool.User | undefined> { ): Promise<Carpool.User | undefined> {
return undefined; return ((await UserModel.findOne({
email,
}).exec()) as unknown) as Carpool.User;
} }
export async function registerUserFromIonProfile( export async function registerUserFromIonProfile(