From 95ccfc884c905962a034959a88800dc2ad93264e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Sat, 4 Jan 2025 19:04:48 +0100 Subject: [PATCH] feat: add validation to prevent class creation for past dates --- src/modules/class/class.service.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/class/class.service.ts b/src/modules/class/class.service.ts index 33fb586..c1515cd 100644 --- a/src/modules/class/class.service.ts +++ b/src/modules/class/class.service.ts @@ -110,6 +110,10 @@ export class ClassService { const date = moment(createRoomClassDto.date); + // Check if the date is before the current date + if (date.isBefore(moment().startOf("day"))) + throw new HttpException("Can't create a room for a class that has passed", 400); + const firstTimeStart = createRoomClassDto.times.reduce((prev, current) => moment(current.start, "HH:mm").isBefore(moment(prev.start, "HH:mm")) ? current