import { ALL } from '../../constants/profiles-must-have'; import { Rule } from '../../interfaces/rule'; import { TicketDto } from '../../interfaces/ticket/ticket.dto'; export class UserProfiles implements Rule { name = 'UserProfiles'; validate(ticket: TicketDto): boolean { if (!ticket?.profiles?.length) { return true; } if (ticket?.lastValidValidation) { return true; } if (!ticket?.passengers[0]?.profiles?.length) { return false; } const userProfiles = ticket.passengers[0].profiles; const ticketProfiles = ticket.profiles; if (ticket.profilesMustHave === ALL) { return ticketProfiles.every((profile) => userProfiles.includes(profile)); } return ticketProfiles.some((profile) => userProfiles.includes(profile)); } }