Skip to content

Commit

Permalink
endpoint public/seminar/:id
Browse files Browse the repository at this point in the history
  • Loading branch information
paolini committed Oct 22, 2023
1 parent 1751027 commit 28ea867
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
51 changes: 51 additions & 0 deletions server/controllers/public/seminar.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 28ea867

Please sign in to comment.