From fa4c9317420a3be699660452125b228362a51f39 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sat, 10 Apr 2021 19:56:19 -0400 Subject: [PATCH] fix sending promise through json --- src/api.ts | 13 ++++++++----- src/auth.ts | 1 - src/data.ts | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/api.ts b/src/api.ts index 50ae54b..7b9bf44 100644 --- a/src/api.ts +++ b/src/api.ts @@ -15,7 +15,6 @@ router.get('/user', async (req, res) => { } let userID = req.query.userID; - console.log(req.session, userID); if (userID === '@me') { userID = req.session.accountID; } @@ -127,10 +126,14 @@ router.post('/group', (req, res) => { // } }); -router.get('/my_pools', (req, res) => { - let groupsWithUser = getPoolsWithUser(req.session.accountID); - if (groupsWithUser) { - res.json({ status: 'success', data: groupsWithUser }); +router.get('/my_pools', async (req, res) => { + if (req.session.accountID == null) { + res.status(401); + return res.json({ status: 'error', error: 'need_login' }); + } + let pools = await getPoolsWithUser(req.session.accountID); + if (pools) { + res.json({ status: 'success', data: pools }); } else { res.json({ status: 'error', error: 'not_found' }); } diff --git a/src/auth.ts b/src/auth.ts index 82709d0..c4bed7c 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -26,7 +26,6 @@ export function createSession(accountID: string): string { } export function getSessionByToken(token: string): SessionData { - console.log(sessions); if (token in sessions) { return sessions[token]; } else { diff --git a/src/data.ts b/src/data.ts index 8079dba..88f2aff 100644 --- a/src/data.ts +++ b/src/data.ts @@ -15,8 +15,10 @@ export function getGroupsWithUser(userID: string) { * @param userID The userID to find * @returns The post IDs with that userID as the author */ -export function getPoolsWithUser(userID: string) { - return undefined; +export async function getPoolsWithUser(userID: string) { + return await PoolModel.find({ + participant_ids: { $all: [userID] }, + }).exec(); } export async function getUserByID(userID: string) {