diff --git a/server/api.js b/server/api.js index 955ed4b4..f558e043 100644 --- a/server/api.js +++ b/server/api.js @@ -5,6 +5,7 @@ const profile = require('./controllers/profile') const staffQuery = require('./controllers/public/staff') const visitsQuery = require('./controllers/public/visits') const seminarsQuery = require('./controllers/public/seminars') +const seminarQuery = require('./controllers/public/seminar') const router = express.Router() @@ -72,5 +73,10 @@ router.get('/public/seminars', async (req, res) => { res.send(await seminarsQuery(req)) }) -module.exports = router +router.get('/public/seminar/:id', async (req, res) => { + res.send(await seminarQuery(req)) +}) + +module.exports = + router module.exports.ModelSchemas = ModelSchemas \ No newline at end of file diff --git a/server/controllers/public/seminar.js b/server/controllers/public/seminar.js new file mode 100644 index 00000000..d27ad349 --- /dev/null +++ b/server/controllers/public/seminar.js @@ -0,0 +1,51 @@ +const EventSeminar = require('../../models/EventSeminar') +const ObjectId = require('mongoose').Types.ObjectId + +async function seminarQuery(req) { + const seminar_id = req.params.id + const pipeline = [ + { $match: { + startDatetime: {$gte: new Date()}, + _id: new ObjectId(seminar_id), + }}, + { $lookup: { + from: 'people', + localField: 'speaker', + foreignField: '_id', + as: 'speaker', + }}, + { $unwind: { + path: '$speaker', + preserveNullAndEmptyArrays: true + }}, + {$lookup: { + from: 'institutions', + localField: 'affiliations', + foreignField: '_id', + as: 'affiliations' + }}, + { $project: { + _id: 1, + title: 1, + startDatetime: 1, + conferenceRoom: 1, + category: 1, + duration: 1, + speaker: { + _id: 1, + firstName: 1, + lastName: 1, + affiliations: 1, + }, + abstract: 1, + }} + ] + + // console.log(JSON.stringify({pipeline})) + + const seminars = await EventSeminar.aggregate(pipeline) + + return seminars +} + +module.exports = seminarQuery