Skip to content

Commit

Permalink
feat(api): No ticket - Ajout d'une route publique pour avoir la liste…
Browse files Browse the repository at this point in the history
… des cohortes (#4527)
  • Loading branch information
nicobret authored Nov 8, 2024
1 parent 339874c commit 25a69bd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/src/cohort/cohortController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express, { Response } from "express";
import Joi from "joi";
import passport from "passport";

import { ROLES, isSuperAdmin, COHORT_TYPE, formatDateTimeZone } from "snu-lib";
import { ROLES, isSuperAdmin, COHORT_TYPE, formatDateTimeZone, COHORT_STATUS } from "snu-lib";

import { CohortModel, ClasseModel, YoungModel, SessionPhase1Model } from "../models";
import ClasseStateManager from "../cle/classe/stateManager";
Expand Down Expand Up @@ -191,6 +191,17 @@ router.get("/", passport.authenticate(["referent", "young"], { session: false, f
}
});

router.get("/public", async (_req: UserRequest, res: Response) => {
try {
let cohorts = await CohortModel.find({}, { name: 1, type: 1, status: 1, dateStart: 1, dateEnd: 1 }).lean();
for (let cohort of cohorts) delete cohort._id;
return res.status(200).send({ ok: true, data: cohorts });
} catch (error) {
capture(error);
return res.status(500).send({ ok: false, code: ERRORS.SERVER_ERROR, error });
}
});

router.get("/:cohort", passport.authenticate(["referent", "young"], { session: false, failWithError: true }), async (req: UserRequest, res: Response) => {
try {
const { error, value } = Joi.object({
Expand Down

0 comments on commit 25a69bd

Please sign in to comment.