From c273f3560c089de207ad0d531cac96a251b5d8c7 Mon Sep 17 00:00:00 2001 From: Bastien Seree Date: Mon, 30 Dec 2024 15:19:50 +0100 Subject: [PATCH] EDF: [#177] add getter for reservable tickets in event schema --- backend/web/server/plugins/entreprisedufutur/event.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/web/server/plugins/entreprisedufutur/event.js b/backend/web/server/plugins/entreprisedufutur/event.js index 7676e449b..d404fb384 100644 --- a/backend/web/server/plugins/entreprisedufutur/event.js +++ b/backend/web/server/plugins/entreprisedufutur/event.js @@ -25,7 +25,16 @@ const getRegisteredNumber = async function (userId, params, data,fields) { return userTickets.map(ticket=> ticket.user).length } +const getReservableTickets = async function (userId, params, data,fields) { + const user = await User.findById(userId) + const eventTickets = await EventTicket.find({event: data._id}) + return eventTickets.filter((t) => { + return t.targeted_roles.includes(user.role) + }) +} + module.exports = { getRegistered, getRegisteredNumber, + getReservableTickets, } \ No newline at end of file