fix sending promise through json

This commit is contained in:
Michael Fatemi 2021-04-10 19:56:19 -04:00
parent 9622ede6e0
commit fa4c931742
3 changed files with 12 additions and 8 deletions

View File

@ -15,7 +15,6 @@ router.get('/user', async (req, res) => {
} }
let userID = req.query.userID; let userID = req.query.userID;
console.log(req.session, userID);
if (userID === '@me') { if (userID === '@me') {
userID = req.session.accountID; userID = req.session.accountID;
} }
@ -127,10 +126,14 @@ router.post('/group', (req, res) => {
// } // }
}); });
router.get('/my_pools', (req, res) => { router.get('/my_pools', async (req, res) => {
let groupsWithUser = getPoolsWithUser(req.session.accountID); if (req.session.accountID == null) {
if (groupsWithUser) { res.status(401);
res.json({ status: 'success', data: groupsWithUser }); return res.json({ status: 'error', error: 'need_login' });
}
let pools = await getPoolsWithUser(req.session.accountID);
if (pools) {
res.json({ status: 'success', data: pools });
} else { } else {
res.json({ status: 'error', error: 'not_found' }); res.json({ status: 'error', error: 'not_found' });
} }

View File

@ -26,7 +26,6 @@ export function createSession(accountID: string): string {
} }
export function getSessionByToken(token: string): SessionData { export function getSessionByToken(token: string): SessionData {
console.log(sessions);
if (token in sessions) { if (token in sessions) {
return sessions[token]; return sessions[token];
} else { } else {

View File

@ -15,8 +15,10 @@ export function getGroupsWithUser(userID: string) {
* @param userID The userID to find * @param userID The userID to find
* @returns The post IDs with that userID as the author * @returns The post IDs with that userID as the author
*/ */
export function getPoolsWithUser(userID: string) { export async function getPoolsWithUser(userID: string) {
return undefined; return await PoolModel.find({
participant_ids: { $all: [userID] },
}).exec();
} }
export async function getUserByID(userID: string) { export async function getUserByID(userID: string) {