mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-18 10:50:18 -04:00
feat: didn't go to sleep
This commit is contained in:
parent
446ecf5c78
commit
db69fa2443
|
@ -11,6 +11,17 @@ router.get('/:groupID/pools', async (req, res) => {
|
|||
res.json({ status: 'success', data: pools });
|
||||
});
|
||||
|
||||
router.post('/:groupID/join', async (req, res) => {
|
||||
const userID = req.session.accountID;
|
||||
const groupID = req.params.groupID;
|
||||
|
||||
await GroupModel.findByIdAndUpdate(groupID, {
|
||||
$addToSet: { member_ids: userID },
|
||||
}).exec();
|
||||
|
||||
res.json({ status: 'success' });
|
||||
});
|
||||
|
||||
router.get('/:groupID', async (req, res) => {
|
||||
let groupID = req.params.groupID;
|
||||
let group = await getGroupByID(groupID);
|
||||
|
@ -27,8 +38,11 @@ router.post('/', async (req, res) => {
|
|||
const name = req.body.name;
|
||||
|
||||
const group = new GroupModel();
|
||||
group.set('name', name);
|
||||
group.set('creator_id', userID);
|
||||
Object.assign(group, {
|
||||
name: name,
|
||||
member_ids: [userID],
|
||||
creator_id: userID,
|
||||
});
|
||||
group
|
||||
.save()
|
||||
.then((group) => {
|
||||
|
|
|
@ -16,6 +16,17 @@ router.post('/:poolID/join', async (req, res) => {
|
|||
res.json({ status: 'success' });
|
||||
});
|
||||
|
||||
router.post('/:poolID/leave', async (req, res) => {
|
||||
const userID = req.session.accountID;
|
||||
const poolID = req.params.poolID;
|
||||
|
||||
await PoolModel.findByIdAndUpdate(poolID, {
|
||||
$pull: { participant_ids: userID },
|
||||
}).exec();
|
||||
|
||||
res.json({ status: 'success' });
|
||||
});
|
||||
|
||||
router.get('/:poolID', async (req, res) => {
|
||||
const pool = await PoolModel.findById(new ObjectID(req.params.poolID)).exec();
|
||||
|
||||
|
@ -48,7 +59,7 @@ router.post('/', requireApiAuth, async (req, res) => {
|
|||
status: 'pending',
|
||||
title,
|
||||
type,
|
||||
participant_ids: [],
|
||||
participant_ids: [userID],
|
||||
comments: [],
|
||||
create_time: new Date().toISOString(),
|
||||
update_time: new Date().toISOString(),
|
||||
|
|
|
@ -9,6 +9,7 @@ mongoose.connect(process.env.DB_URL, {
|
|||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
mongoose.set('useFindAndModify', false);
|
||||
|
||||
if (!mongoose.connection) console.log('Error connecting to DB');
|
||||
else console.log('DB connected successfully');
|
||||
|
|
Loading…
Reference in New Issue
Block a user