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;
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' });
}

View File

@ -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 {

View File

@ -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) {