add join_pool API method

This commit is contained in:
Michael Fatemi 2021-04-10 20:06:42 -04:00
parent fa4c931742
commit 0d53ed2352

View File

@ -6,6 +6,7 @@ import {
getPoolsWithUser,
getUserByID,
} from './data';
import { PoolModel } from './models';
export const router = Router();
@ -114,6 +115,21 @@ router.get('/group', (req, res) => {
}
});
router.post('/join_pool', async (req, res) => {
if (!req.session.accountID) {
return res.json({ status: 'error', error: 'need_login' });
} else {
let poolID = req.body.id;
let userID = req.session.accountID;
await PoolModel.findByIdAndUpdate(poolID, {
$addToSet: { participant_ids: userID },
}).exec();
res.json({ status: 'success' });
}
});
router.post('/group', (req, res) => {
// if (req.body.groupID in groups) {
// res.json({ status: 'error', error: 'already_exists' });