From dff7e3486c1be1792598aaaf47f214f3081dbdc7 Mon Sep 17 00:00:00 2001 From: Birloi Florian Date: Tue, 20 Aug 2024 14:08:56 +0300 Subject: [PATCH] fix: 348 - allow active or archived users to join public events regardless if they have a volunteer profile or not --- .../event/exceptions/event-rsvp.exceptions.ts | 2 +- .../event/RSVP/create-rsvp.usecase.ts | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/src/modules/event/exceptions/event-rsvp.exceptions.ts b/backend/src/modules/event/exceptions/event-rsvp.exceptions.ts index 8b1cba208..2d5a4f322 100644 --- a/backend/src/modules/event/exceptions/event-rsvp.exceptions.ts +++ b/backend/src/modules/event/exceptions/event-rsvp.exceptions.ts @@ -28,7 +28,7 @@ export const EventRSVPExceptionMessages: Record< }, [EventsRSVPExceptionCodes.EVENT_RSVP_003]: { code_error: EventsRSVPExceptionCodes.EVENT_RSVP_003, - message: 'Only ACTIVE volunteers can join events.', + message: 'Only ACTIVE or ARCHIVED volunteers can join events.', }, [EventsRSVPExceptionCodes.EVENT_RSVP_004]: { code_error: EventsRSVPExceptionCodes.EVENT_RSVP_004, diff --git a/backend/src/usecases/event/RSVP/create-rsvp.usecase.ts b/backend/src/usecases/event/RSVP/create-rsvp.usecase.ts index 382bd9e0c..5be29b5d5 100644 --- a/backend/src/usecases/event/RSVP/create-rsvp.usecase.ts +++ b/backend/src/usecases/event/RSVP/create-rsvp.usecase.ts @@ -52,27 +52,27 @@ export class CreateEventRSVPUseCase organizationId: event.organization.id, }); - if (volunteer) { - // 4. Only ACTIVE volunteers can join events. In case the user is already a volunteer and is BLOCKED or ARCHIVED. Non-volunteers will pass this validation for public events - if (volunteer.status !== VolunteerStatus.ACTIVE) { - this.exceptionsService.badRequestException( - EventRSVPExceptionMessages.EVENT_RSVP_003, - ); - } else if (!volunteer.volunteerProfile) { - // 5. Volunteers must have the profile completed to RSVP. - this.exceptionsService.badRequestException( - EventRSVPExceptionMessages.EVENT_RSVP_005, - ); - } + // 4. If the volunteer is blocked the user should not be able to join the event + if (volunteer?.status === VolunteerStatus.BLOCKED) { + this.exceptionsService.badRequestException( + EventRSVPExceptionMessages.EVENT_RSVP_003, + ); } - // 6. For "private" events, check if the USER is VOLUNTEER in the ORGANIZATION of the EVENT + // 5. For "private" events, check if the USER is VOLUNTEER in the ORGANIZATION of the EVENT if (!event.isPublic && !volunteer) { this.exceptionsService.badRequestException( EventRSVPExceptionMessages.EVENT_RSVP_002, ); } + // 6. For private events volunteers must have the profile completed to RSVP. + if (!event.isPublic && volunteer && !volunteer.volunteerProfile) { + this.exceptionsService.badRequestException( + EventRSVPExceptionMessages.EVENT_RSVP_005, + ); + } + // 7. Check if userId and eventId is unique in RSVP, if exists, update only the "going" response const existingRSVP = await this.eventFacade.findRSVP({ userId: data.userId,