Skip to content

Commit

Permalink
notificatoin use casd completed
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 22, 2024
1 parent 8d404d6 commit b9c30b0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/src/domain/interface/services/IValidatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions server/src/infrastructure/services/JoiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions server/src/use_case/notification/NotificationUseCae.ts
Original file line number Diff line number Diff line change
@@ -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<void>{
this.validatorService.validateMultipleIds(notificationIds)
await this.notificationRepository.clearAll(notificationIds)
}
async clearOn(notificationId:string):Promise<void>{
this.validatorService.validateIdFormat(notificationId);
await this.notificationRepository.clear(notificationId)
}

async getAllPatient(patientId: string): Promise<INotification[] | null> {
this.validatorService.validateIdFormat(patientId)
return await this.notificationRepository.findByPatientId(patientId);
}
async getAllDoctor(doctorId: string): Promise<INotification[] | null> {
this.validatorService.validateIdFormat(doctorId);
return await this.notificationRepository.findByDoctorId(doctorId)
}
}

0 comments on commit b9c30b0

Please sign in to comment.