From 8469f34b39d7d33eb10cc79abf9d025e572c29f3 Mon Sep 17 00:00:00 2001 From: lesion Date: Wed, 25 May 2022 10:55:39 +0200 Subject: [PATCH] add withFilters param to cohort.getAll --- server/api/controller/cohort.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/server/api/controller/cohort.js b/server/api/controller/cohort.js index 8532009a..6be7ed8d 100644 --- a/server/api/controller/cohort.js +++ b/server/api/controller/cohort.js @@ -9,20 +9,31 @@ const dayjs = require('dayjs') // const { sequelize } = require('../models/index') -const { Op, literal, QueryTypes, SequelizeScopeError, Sequelize } = require('sequelize') +const { Op, Sequelize } = require('sequelize') const cohortController = { async getAll (req, res) { - const cohorts = await Cohort.findAll({ raw: true }) + const withFilters = req.query.withFilters + let cohorts + if (withFilters) { + cohorts = await Cohort.findAll({ include: [Filter] }) + + } else { + cohorts = await Cohort.findAll() + } + return res.json(cohorts) }, // return events from cohort async getEvents (req, res) { const name = req.params.name - const cohort = await Cohort.findOne({ where: { name } }) + const cohort = await Cohort.findOne({ where: { name } }) + if (!cohort) { + return res.sendStatus(404) + } const filters = await Filter.findAll({ where: { cohortId: cohort.id } }) const start = dayjs().unix()