Skip to content

Commit

Permalink
Notification repository added
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 22, 2024
1 parent 9164ad5 commit 8d404d6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
5 changes: 0 additions & 5 deletions server/src/domain/entities/INotification.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export enum NotificationStatus {
READ = 'read',
UNREAD = 'unread'
}
export enum NotificationTypes {
APPOINTMENT_CANCELED = 'appointment_canceled',
APPOINTMENT_CONFIRMED = 'appointment_confirmed',
Expand All @@ -17,5 +13,4 @@ export default interface INotification {
readonly createdAt?: Date;
readonly updatedAt?: Date;
readonly appointmentId?:string
status?: NotificationStatus,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import INotification from "../../entities/INotification";

export default interface INotificationRepository {
create(notification: INotification): Promise<void>;
findByPatientId(patientId: string): Promise<INotification[] | null>;
findByDoctorId(doctorId: string): Promise<INotification[] | null>;
clear(id: string): Promise<void>;
clearAll(notificationIds: string[]): Promise<void>;
}
23 changes: 23 additions & 0 deletions server/src/infrastructure/repositories/NotificationRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import INotification from "../../domain/entities/INotification";
import INotificationRepository from "../../domain/interface/repositories/INotificationRepository";
import NotificationModel from "../database/NotificationMode";

export default class NotificationRepository implements INotificationRepository {
model = NotificationModel

async create(notification: INotification): Promise<void> {
await this.model.create(notification)
}
async findByPatientId(patientId: string): Promise<INotification[] | null> {
return this.model.find({ patientId })
}
async findByDoctorId(doctorId: string): Promise<INotification[] | null> {
return this.model.find({ doctorId })
}
async clear(id: string): Promise<void> {
await this.model.findByIdAndDelete(id);
}
async clearAll(notificationIds: string[]): Promise<void> {
await this.model.deleteMany({ _id: { $in: notificationIds } })
}
}

0 comments on commit 8d404d6

Please sign in to comment.