diff --git a/api/src/cohortGroup/cohortGroupController.ts b/api/src/cohortGroup/cohortGroupController.ts index 7985c950b9..7ea736a30e 100644 --- a/api/src/cohortGroup/cohortGroupController.ts +++ b/api/src/cohortGroup/cohortGroupController.ts @@ -1,7 +1,7 @@ import express from "express"; import { RouteRequest, RouteResponse } from "../controllers/request"; import { capture } from "../sentry"; -import { CohortGroupRoutes, ERRORS, ROLES } from "snu-lib"; +import { COHORT_TYPE_LIST, CohortGroupRoutes, ERRORS, ROLES } from "snu-lib"; import { accessControlMiddleware } from "../middlewares/accessControlMiddleware"; import { CohortGroupModel } from "../models/cohortGroup"; import Joi from "joi"; @@ -25,13 +25,15 @@ router.post( requestValidatorMiddleware({ body: Joi.object({ name: Joi.string().required(), + type: Joi.string().valid(COHORT_TYPE_LIST), + year: Joi.number(), }), }), accessControlMiddleware([ROLES.ADMIN]), async (req: RouteRequest, res: RouteResponse) => { try { - const { name } = req.body; - const data = new CohortGroupModel({ name }); + const { name, type, year } = req.body; + const data = new CohortGroupModel({ name, type, year }); await data.save({ fromUser: req.user }); return res.json({ ok: true, data }); } catch (error) { @@ -55,12 +57,12 @@ router.put( async (req: RouteRequest, res: RouteResponse) => { try { const { id } = req.params; - const { name } = req.body; + const { name, type, year } = req.body; const data = await CohortGroupModel.findById(id); if (!data) { return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND }); } - data.name = name; + data.set({ name, type, year }); await data.save({ fromUser: req.user }); return res.json({ ok: true, data }); } catch (error) { diff --git a/packages/lib/src/mongoSchema/cohortGroup.ts b/packages/lib/src/mongoSchema/cohortGroup.ts index 030f65fcf5..0a56786f7a 100644 --- a/packages/lib/src/mongoSchema/cohortGroup.ts +++ b/packages/lib/src/mongoSchema/cohortGroup.ts @@ -1,6 +1,6 @@ import { Schema, InferSchemaType } from "mongoose"; -import { InterfaceExtended } from ".."; +import { COHORT_TYPE_LIST, InterfaceExtended } from ".."; export const CohortGroupSchema = { name: { @@ -10,6 +10,19 @@ export const CohortGroupSchema = { description: "Nom du groupe de cohortes. Exp: CLE 2024, HTS 2025.", }, }, + type: { + type: String, + enum: COHORT_TYPE_LIST, + documentation: { + description: "Type de cohortes : CLE ou VOLONTAIRE.", + }, + }, + year: { + type: Number, + documentation: { + description: "Année de la cohorte.", + }, + }, createdAt: { type: Date, default: Date.now }, updatedAt: { type: Date, default: Date.now }, }; diff --git a/packages/lib/src/routes/cohortGroup/index.ts b/packages/lib/src/routes/cohortGroup/index.ts index 181d5e6652..ed3239900b 100644 --- a/packages/lib/src/routes/cohortGroup/index.ts +++ b/packages/lib/src/routes/cohortGroup/index.ts @@ -4,7 +4,7 @@ import { BasicRoute, RouteResponseBody } from ".."; interface PostCohortGroupRoute extends BasicRoute { method: "POST"; path: "/cohort-group"; - payload: { name: string }; + payload: { name: string; type: string; year: number }; response: RouteResponseBody; } @@ -18,7 +18,7 @@ interface PutCohortGroupRoute extends BasicRoute { method: "PUT"; path: "/cohort-group/:id"; params: { id: string }; - payload: { name: string }; + payload: { name: string; type: string; year: number }; response: RouteResponseBody; }