mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-21 12:10:17 -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 });
|
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) => {
|
router.get('/:groupID', async (req, res) => {
|
||||||
let groupID = req.params.groupID;
|
let groupID = req.params.groupID;
|
||||||
let group = await getGroupByID(groupID);
|
let group = await getGroupByID(groupID);
|
||||||
|
@ -27,8 +38,11 @@ router.post('/', async (req, res) => {
|
||||||
const name = req.body.name;
|
const name = req.body.name;
|
||||||
|
|
||||||
const group = new GroupModel();
|
const group = new GroupModel();
|
||||||
group.set('name', name);
|
Object.assign(group, {
|
||||||
group.set('creator_id', userID);
|
name: name,
|
||||||
|
member_ids: [userID],
|
||||||
|
creator_id: userID,
|
||||||
|
});
|
||||||
group
|
group
|
||||||
.save()
|
.save()
|
||||||
.then((group) => {
|
.then((group) => {
|
||||||
|
|
|
@ -16,6 +16,17 @@ router.post('/:poolID/join', async (req, res) => {
|
||||||
res.json({ status: 'success' });
|
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) => {
|
router.get('/:poolID', async (req, res) => {
|
||||||
const pool = await PoolModel.findById(new ObjectID(req.params.poolID)).exec();
|
const pool = await PoolModel.findById(new ObjectID(req.params.poolID)).exec();
|
||||||
|
|
||||||
|
@ -48,7 +59,7 @@ router.post('/', requireApiAuth, async (req, res) => {
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
title,
|
title,
|
||||||
type,
|
type,
|
||||||
participant_ids: [],
|
participant_ids: [userID],
|
||||||
comments: [],
|
comments: [],
|
||||||
create_time: new Date().toISOString(),
|
create_time: new Date().toISOString(),
|
||||||
update_time: new Date().toISOString(),
|
update_time: new Date().toISOString(),
|
||||||
|
|
|
@ -9,6 +9,7 @@ mongoose.connect(process.env.DB_URL, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
});
|
});
|
||||||
|
mongoose.set('useFindAndModify', false);
|
||||||
|
|
||||||
if (!mongoose.connection) console.log('Error connecting to DB');
|
if (!mongoose.connection) console.log('Error connecting to DB');
|
||||||
else console.log('DB connected successfully');
|
else console.log('DB connected successfully');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user