diff --git a/src/api.ts b/src/api.ts index e744483..e196a49 100644 --- a/src/api.ts +++ b/src/api.ts @@ -100,13 +100,13 @@ router.patch('/pool', (req, res) => { router.delete('/pool', (req, res) => {}); -router.get('/group', (req, res) => { +router.get('/group', async (req, res) => { if (typeof req.query.groupID != 'string') { return res.json({ status: 'error' }); } let groupID = req.query.groupID; - let group = getGroupByID(groupID); + let group = await getGroupByID(groupID); if (group) { res.json({ status: 'success', data: group }); @@ -117,6 +117,7 @@ router.get('/group', (req, res) => { router.get('/group_pools', async (req, res) => { if (typeof req.query.groupID != 'string') { + res.json({ status: 'error', error: 'need_group_id' }); return; } diff --git a/src/data.ts b/src/data.ts index 88f2aff..2596426 100644 --- a/src/data.ts +++ b/src/data.ts @@ -1,5 +1,6 @@ import { IonProfile } from './auth_ion'; import { GroupModel, PoolModel, UserModel } from './models'; +import { ObjectId } from 'mongodb'; /** * @@ -17,7 +18,7 @@ export function getGroupsWithUser(userID: string) { */ export async function getPoolsWithUser(userID: string) { return await PoolModel.find({ - participant_ids: { $all: [userID] }, + participant_ids: { $all: [new ObjectId(userID)] }, }).exec(); } @@ -25,16 +26,17 @@ export async function getUserByID(userID: string) { if (userID == null) { return undefined; } - return (await UserModel.findById(userID).exec()).toJSON(); + let doc = await UserModel.findById(new ObjectId(userID)).exec(); + return doc?.toJSON(); } export async function getPoolByID(poolID: string) { - let doc = await PoolModel.findById(poolID).exec(); + let doc = await PoolModel.findById(new ObjectId(poolID)).exec(); return doc?.toJSON(); } export async function getGroupByID(groupID: string) { - let doc = await GroupModel.findById(groupID).exec(); + let doc = await GroupModel.findById(new ObjectId(groupID)).exec(); return doc?.toJSON(); }