-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(index.js, RSVPModel.js, rsvp.js): add rsvp model and routes #16
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const mongoose = require('mongoose') | ||
|
||
const RSVP = mongoose.model('RSVP', { | ||
owner: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
required: true | ||
}, | ||
attending: { | ||
type: Boolean, | ||
required: true | ||
}, | ||
shirt: { | ||
type: Number, | ||
min: 0, | ||
max: 4, | ||
required: function () { return this.attending } | ||
}, | ||
transportation: { | ||
type: Number, | ||
min: 0, | ||
max: 2, | ||
required: function () { return this.attending } | ||
}, | ||
bus: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be "buses" |
||
type: Number, | ||
min: 0, | ||
max: 2, | ||
required: function () { return this.attending && this.travelType === 0 } | ||
}, | ||
socal: { | ||
type: Number, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the frontend sends this as a string. thoughts on number vs string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tommy and I think it is easier to store this data as a string as well, I am updating the Application model to reflect this. |
||
min: 0, | ||
max: 2, | ||
required: function () { return this.attending && this.bus === 0 } | ||
}, | ||
norcal: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
type: Number, | ||
min: 0, | ||
max: 2, | ||
required: function () { return this.attending && this.bus === 1 } | ||
}, | ||
flight: { | ||
type: String, | ||
required: function () { return this.attending && this.travelType === 1 } | ||
}, | ||
misc: { | ||
type: String | ||
}, | ||
submittedAt: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}) | ||
|
||
module.exports = RSVP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const express = require('express') | ||
const RSVP = require('../models/RSVPModel') | ||
const router = new express.Router() | ||
const authMiddleware = require('../middleware/authMiddleware') | ||
|
||
router.post('/rsvp', authMiddleware, async (req, res) => { | ||
try { | ||
const rsvp = new RSVP(req.body) | ||
rsvp.owner = req.user._id | ||
const existingRSVP = await RSVP.findOne({ owner: req.user._id }) | ||
if (existingRSVP) { | ||
throw new Error('This user has already RSVP\'d') | ||
} | ||
await rsvp.save() | ||
res.status(201).send(rsvp) | ||
} catch (err) { | ||
res.status(400).send({ errorMessage: err.message }) | ||
} | ||
}) | ||
|
||
router.get('/rsvp/:id', authMiddleware, async (req, res) => { | ||
try { | ||
const { id: userID } = req.params | ||
const rsvp = await RSVP.findOne({ owner: userID }) | ||
if ((!req.admin && userID !== req.user._id.toString())) { | ||
throw new Error() | ||
} | ||
if (!rsvp) { | ||
res.status(404).send({}) | ||
} else { | ||
res.status(200).send(rsvp) | ||
} | ||
} catch (err) { | ||
res.status(500).send({ errorMessage: err.message }) | ||
} | ||
}) | ||
|
||
module.exports = router |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think about how we should expire out RSVP, ex if user is accepted but RSVPS after 7 days how do we prevent them from creating a document