Skip to content

Commit

Permalink
EDF: [premieroctet#134] validate order throws an error if user alread…
Browse files Browse the repository at this point in the history
…y got a ticket
  • Loading branch information
Bastien-Wappizy committed Dec 19, 2024
1 parent 02126ee commit d32aa20
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions backend/web/server/plugins/entreprisedufutur/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ const validateOrder = async ({value}, user) => {
return !!user
})

//Check that known users don't already have a ticket
knownUserTickets.forEach(async (orderTicket) => {
const user = await User.findOne({email:orderTicket.email})
const ticket = UserTicket.findOne({user: user._id, event_ticket: order.event_ticket})
if (!!ticket) {
throw new ForbiddenError(`Un billet a déjà été pris pour cette événement avec l'email ${orderTicket.email}`)
}
})

const unknownUserTickets = lodash.differenceWith(
order.order_tickets,
knownUserTickets,
Expand All @@ -199,11 +208,6 @@ const validateOrder = async ({value}, user) => {
}
)

//TODO déplacer dans isActionAllowed
knownUserTickets.forEach(orderTicket => {
// le user n'a pas déjà un ticket
})

unknownUserTickets.foreach(orderTicket => {
//TODO popup validation de création de user
//création de user
Expand Down

0 comments on commit d32aa20

Please sign in to comment.