use ObjectIDs

This commit is contained in:
Michael Fatemi 2021-04-10 20:50:46 -04:00
parent ad7f746d88
commit c4d9830ea6
2 changed files with 9 additions and 6 deletions

View File

@ -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;
}

View File

@ -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();
}