mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-18 10:50:18 -04:00
use ObjectIDs
This commit is contained in:
parent
ad7f746d88
commit
c4d9830ea6
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
10
src/data.ts
10
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user