Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
Resolves #277 attendee backend
Browse files Browse the repository at this point in the history
* modified event and attendee models to handle checkin/tardiness

* wrote attendee endpoints

* forgot yarn format again

* fixing stuff
  • Loading branch information
alicesf2 authored Jul 4, 2019
1 parent a57dfba commit 70c25e2
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 11 deletions.
126 changes: 126 additions & 0 deletions backend/src/api/attendees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
const express = require('express')
const mongodb = require('mongodb')
const router = express.Router()
const { errorWrap } = require('../middleware')
const { Attendee, Candidate } = require('../models')

// get all attendees
router.get(
'/',
errorWrap(async (req, res) => {
const attendees = await Attendee.find({})
res.json({
code: 200,
result: attendees,
success: true
})
})
)

// get one attendee
router.get(
'/:attendeeId',
errorWrap(async (req, res) => {
const attendeeId = req.params.attendeeId
const attendee = await Attendee.findById(attendeeId)
res.json({
code: 200,
result: attendee,
success: true
})
})
)

// create a new attendee
router.post(
'/',
errorWrap(async (req, res) => {
const data = req.body
const newAttendee = new Attendee({
name: data.name,
email: data.email,
year: data.year
})

await newAttendee.save()
res.json({
code: 200,
message: 'Attendee Successfully Created',
success: true
})
})
)

// update an attendee
router.put(
'/:attendeeId',
errorWrap(async (req, res) => {
const data = req.body
const attendeeId = req.params.attendeeId
let fieldsToUpdate = {}

if (data.name !== undefined) {
fieldsToUpdate['name'] = data.name
}
if (data.email !== undefined) {
fieldsToUpdate['email'] = data.email
}
if (data.year !== undefined) {
fieldsToUpdate['year'] = data.year
}

const attendee = await Attendee.findByIdAndUpdate(
attendeeId,
{ $set: fieldsToUpdate },
{ new: true }
)
const ret = attendee
? {
code: 200,
message: 'Attendee Updated Successfully',
success: true
}
: {
code: 404,
message: 'Attendee Not Found',
success: false
}
res.json(ret)
})
)

// delete an attendee
router.delete(
'/:attendeeId',
errorWrap(async (req, res) => {
const attendeeId = req.params.attendeeId
const attendee = await Attendee.findByIdAndRemove(attendeeId)
const ret = attendee
? {
code: 200,
message: 'Attendee Deleted Successfully',
success: true
}
: {
code: 404,
message: 'Attendee Not Found',
success: false
}
res.json(ret)
})
)

// delete all events
router.delete(
'/',
errorWrap(async (req, res) => {
await Attendee.deleteMany({})
res.json({
code: 200,
message: 'Attendees Deleted Successfully',
success: true
})
})
)

module.exports = router
1 change: 0 additions & 1 deletion backend/src/api/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ router.post(
endTime: data.endTime,
location: data.location,
description: data.description,
attendees: [],
fbLink: data.fbLink
})
await newEvent.save()
Expand Down
4 changes: 3 additions & 1 deletion backend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const matchCandidates = require('./matchCandidates')
const matches = require('./matches')
const structure = require('./structure')
const events = require('./events')
const attendees = require('./attendees')

module.exports = {
candidates,
Expand All @@ -13,5 +14,6 @@ module.exports = {
matchCandidates,
matches,
structure,
events
events,
attendees
}
12 changes: 6 additions & 6 deletions backend/src/models/attendee.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const mongoose = require('mongoose')

const Attendee = new mongoose.Schema({
name: { type: String, required: true },
netid: { type: String, required: true },
year: { type: Number, required: true },
candidate_id: { type: mongoose.Schema.Types.ObjectId, required: true },
eventsAttended: { type: [String], required: true },
email: { type: String, required: true, unique: true },
year: { type: String, required: true },
attendedEvents: { type: [mongoose.Schema.Types.ObjectId], default: [] },
lateEvents: { type: [mongoose.Schema.Types.ObjectId], default: [] },
candidateId: { type: mongoose.Schema.Types.ObjectId, default: null },
workspaceId: { type: String }
})

module.exports.AttendeeSchema = Attendee
module.exports.AttendeeModel = mongoose.model('Attendee', Attendee)
module.exports = mongoose.model('Attendee', Attendee)
3 changes: 2 additions & 1 deletion backend/src/models/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const Event = new mongoose.Schema({
endTime: { type: String, required: true },
location: { type: String, required: true },
description: { type: String, required: true },
attendees: { type: [AttendeeSchema], required: true }, // subdocument
attendees: { type: [mongoose.Schema.Types.ObjectId], default: [] },
lateAttendees: { type: [mongoose.Schema.Types.ObjectId], default: [] },
fbLink: { type: String, required: true },
workspaceId: { type: String }
})
Expand Down
4 changes: 3 additions & 1 deletion backend/src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Match = require('./match')
const Comment = require('./comment').CommentModel
const Structure = require('./structure')
const Event = require('./event')
const Attendee = require('./attendee')

module.exports = {
Candidate,
Expand All @@ -16,5 +17,6 @@ module.exports = {
Comment,
Structure,
FutureInterview,
Event
Event,
Attendee
}
4 changes: 3 additions & 1 deletion backend/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const {
matchCandidates,
matches,
structure,
events
events,
attendees
} = require('./api')
var XLSX = require('xlsx')

Expand All @@ -24,5 +25,6 @@ router.use('/matchCandidates', matchCandidates)
router.use('/matches', matches)
router.use('/structure', structure)
router.use('/events', events)
router.use('/attendees', attendees)

module.exports = router

0 comments on commit 70c25e2

Please sign in to comment.