diff --git a/src/modules/host/dto/createActivity.schema.ts b/src/modules/host/dto/createActivity.schema.ts index 44148ce..c232f2b 100644 --- a/src/modules/host/dto/createActivity.schema.ts +++ b/src/modules/host/dto/createActivity.schema.ts @@ -136,6 +136,7 @@ export const CreateActivityDto = z.object({ equipmentIsChargeable: z.boolean().optional().default(false), cancellationAvailable: z.boolean().optional().default(false), + cancellationAllowedBeforeMins:z.number().optional().default(null), /* MONEY / CURRENCY */ currencyXid: z.number().int().nullable().optional(), diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index d71e243..e042941 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -2409,6 +2409,37 @@ export class HostService { payload.alcoholAvailable = toBool(payload.alcoholAvailable); payload.trainerTotalAmount = toNumber(payload.trainerTotalAmount); + payload.cancellationAllowedBeforeMins = toNumber( + payload.cancellationAllowedBeforeMins, + ); + + /* ===================================================== + * CANCELLATION VALIDATION (NO CONVERSION) + * ===================================================== */ + if (payload.cancellationAvailable) { + if ( + typeof payload.cancellationAllowedBeforeMins !== 'number' || + Number.isNaN(payload.cancellationAllowedBeforeMins) || + payload.cancellationAllowedBeforeMins <= 0 + ) { + throw new ApiError( + 400, + 'cancellationAllowedBeforeMins must be a positive number (in minutes)', + ); + } + + if ( + activityDurationMins > 0 && + payload.cancellationAllowedBeforeMins >= activityDurationMins + ) { + throw new ApiError( + 400, + 'cancellationAllowedBeforeMins must be less than activity duration', + ); + } + } else { + delete payload.cancellationAllowedBeforeMins; + } if (payload.trainerAvailable) { if (