From b9c30b0fa78bfb9f2ef60365602defdff7fca14d Mon Sep 17 00:00:00 2001 From: Sinan Date: Sun, 22 Sep 2024 11:31:18 +0530 Subject: [PATCH] notificatoin use casd completed --- .../interface/services/IValidatorService.ts | 1 + .../src/infrastructure/services/JoiService.ts | 9 ++++++ .../notification/NotificationUseCae.ts | 28 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 server/src/use_case/notification/NotificationUseCae.ts diff --git a/server/src/domain/interface/services/IValidatorService.ts b/server/src/domain/interface/services/IValidatorService.ts index cd3132b7..87b9756f 100644 --- a/server/src/domain/interface/services/IValidatorService.ts +++ b/server/src/domain/interface/services/IValidatorService.ts @@ -9,4 +9,5 @@ export default interface IValidatorService { validateEnum(field: string, enumValues: string[]): boolean; validatePassword(password: string): boolean; validateBoolean(value: any): boolean; + validateMultipleIds(ids:string[]):boolean; } diff --git a/server/src/infrastructure/services/JoiService.ts b/server/src/infrastructure/services/JoiService.ts index db62716d..d31531dc 100644 --- a/server/src/infrastructure/services/JoiService.ts +++ b/server/src/infrastructure/services/JoiService.ts @@ -51,6 +51,15 @@ export default class JoiService implements IValidatorService { return true; } + public validateMultipleIds(ids: string[]): boolean { + const schema = Joi.array().items(Joi.string().pattern(new RegExp("^[a-fA-F0-9]{24}$"))); + const { error } = schema.validate(ids); + if (error) { + throw new CustomError("Invalid ID format", StatusCode.BadRequest); + } + return true; + } + public validatePhoneNumber(phoneNumber: string): boolean { const schema = Joi.string().min(4).max(15); const { error } = schema.validate(phoneNumber); diff --git a/server/src/use_case/notification/NotificationUseCae.ts b/server/src/use_case/notification/NotificationUseCae.ts new file mode 100644 index 00000000..4417fec2 --- /dev/null +++ b/server/src/use_case/notification/NotificationUseCae.ts @@ -0,0 +1,28 @@ +import INotification from "../../domain/entities/INotification"; +import INotificationRepository from "../../domain/interface/repositories/INotificationRepository"; +import IValidatorService from "../../domain/interface/services/IValidatorService"; + +export default class NotificationUseCae { + constructor( + private notificationRepository: INotificationRepository, + private validatorService: IValidatorService + ) { }; + + async clearAll(notificationIds:string[]):Promise{ + this.validatorService.validateMultipleIds(notificationIds) + await this.notificationRepository.clearAll(notificationIds) + } + async clearOn(notificationId:string):Promise{ + this.validatorService.validateIdFormat(notificationId); + await this.notificationRepository.clear(notificationId) + } + + async getAllPatient(patientId: string): Promise { + this.validatorService.validateIdFormat(patientId) + return await this.notificationRepository.findByPatientId(patientId); + } + async getAllDoctor(doctorId: string): Promise { + this.validatorService.validateIdFormat(doctorId); + return await this.notificationRepository.findByDoctorId(doctorId) + } +} \ No newline at end of file