From 2facc6a728cbe7b40f0dc06b8418f0d3538554be Mon Sep 17 00:00:00 2001 From: Sinan Date: Wed, 2 Oct 2024 08:51:53 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20video=20and=20appointment=20Repo?= =?UTF-8?q?sitorys=20extended=20IRepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interface/repositories/IAppointmentRepository.ts | 5 ++--- server/src/domain/interface/repositories/IRepository.ts | 8 ++++++-- .../interface/repositories/IVideoSectionRepository.ts | 7 ++----- .../infrastructure/repositories/AppointmentRepository.ts | 9 +++++++-- .../repositories/VideoSectionRepository.ts | 2 +- .../src/use_case/appointment/CreateAppointmentUseCase.ts | 2 +- .../src/use_case/appointment/UpdateAppointmentUseCase.ts | 6 +++--- server/src/use_case/patient/PatientUseCases.ts | 2 +- server/src/use_case/video/GetVideoSectionUseCase.ts | 2 +- 9 files changed, 24 insertions(+), 19 deletions(-) diff --git a/server/src/domain/interface/repositories/IAppointmentRepository.ts b/server/src/domain/interface/repositories/IAppointmentRepository.ts index b5e51056..f5d8ced9 100644 --- a/server/src/domain/interface/repositories/IAppointmentRepository.ts +++ b/server/src/domain/interface/repositories/IAppointmentRepository.ts @@ -1,9 +1,8 @@ import { PaginatedResult } from "../../../types"; import IAppointment, { AppointmentStatus, IExtendedAppointment } from "../../entities/IAppointment"; +import IRepository from "./IRepository"; -export default interface IAppointmentRepository { - create(appointment: IAppointment): Promise; - update(appointment: IAppointment): Promise; +export default interface IAppointmentRepository extends IRepository { updateManyBySlotIdsNotInStatuses(slotIds: string[], fields: IAppointment, notInStatuses:AppointmentStatus[]): Promise; findByDateAndSlot(appointmentDate: string, slotId: string): Promise; findManyByDateAndDoctorId(appointmentDate: string, doctorId: string): Promise; diff --git a/server/src/domain/interface/repositories/IRepository.ts b/server/src/domain/interface/repositories/IRepository.ts index 84fb18e5..98199283 100644 --- a/server/src/domain/interface/repositories/IRepository.ts +++ b/server/src/domain/interface/repositories/IRepository.ts @@ -1,7 +1,11 @@ +import { PaginatedResult } from "../../../types"; + export default interface IRepository { findById(id: string): Promise; - findAll(): Promise; + findAll?(): Promise; + findManyByIds?(ids: string[]): Promise; + findManyAsPaginated?(offset: number, limit: number): Promise | null>; create(entity: T): Promise; update(id: string, entity: T): Promise; - delete(id: string): Promise; + delete?(id: string): Promise; } diff --git a/server/src/domain/interface/repositories/IVideoSectionRepository.ts b/server/src/domain/interface/repositories/IVideoSectionRepository.ts index b83da551..60b0b444 100644 --- a/server/src/domain/interface/repositories/IVideoSectionRepository.ts +++ b/server/src/domain/interface/repositories/IVideoSectionRepository.ts @@ -1,12 +1,9 @@ import IVideoSection, { VideoSectionStatus } from "../../entities/IVideoChatSection"; +import IRepository from "./IRepository"; -export interface IVideoSectionRepository { - create(videoSection: IVideoSection): Promise; - findById(id: string): Promise; - update(id: string, videoSection: IVideoSection): Promise; +export default interface IVideoSectionRepository extends IRepository { findByPatientIdAndUpdate(patientId: string, section: IVideoSection): Promise; findByDoctorIdAndUpdate(doctorId: string, section: IVideoSection): Promise; - delete(id: string): Promise; findByAppointmentId(appointmentId: string): Promise; findByStatus(status: VideoSectionStatus): Promise; findByStartTimeRangeByDoctorId(startTime: string, endTime: string, doctorId: string): Promise; diff --git a/server/src/infrastructure/repositories/AppointmentRepository.ts b/server/src/infrastructure/repositories/AppointmentRepository.ts index c611fb00..9831f391 100644 --- a/server/src/infrastructure/repositories/AppointmentRepository.ts +++ b/server/src/infrastructure/repositories/AppointmentRepository.ts @@ -11,8 +11,13 @@ export default class AppointmentRepository implements IAppointmentRepository { async create(appointment: IAppointment): Promise { return (await this.model.create(appointment)); } - async update(appointment: IAppointment): Promise { - return await this.model.findByIdAndUpdate(appointment._id, appointment, { new: true }); + + async findById(id: string): Promise { + return await this.model.findById(id); + } + + async update(id: string, appointment: IAppointment): Promise { + return await this.model.findByIdAndUpdate(id, appointment, { new: true }); } async findManyByIds(ids: string[]): Promise { diff --git a/server/src/infrastructure/repositories/VideoSectionRepository.ts b/server/src/infrastructure/repositories/VideoSectionRepository.ts index 2ca33ed5..480fc98a 100644 --- a/server/src/infrastructure/repositories/VideoSectionRepository.ts +++ b/server/src/infrastructure/repositories/VideoSectionRepository.ts @@ -1,5 +1,5 @@ import IVideoSection, { VideoSectionStatus } from "../../domain/entities/IVideoChatSection"; -import { IVideoSectionRepository } from "../../domain/interface/repositories/IVideoSectionRepository"; +import IVideoSectionRepository from "../../domain/interface/repositories/IVideoSectionRepository"; import VideoSectionModel from "../model/VideoSectionModel"; export default class VideoSectionRepository implements IVideoSectionRepository { diff --git a/server/src/use_case/appointment/CreateAppointmentUseCase.ts b/server/src/use_case/appointment/CreateAppointmentUseCase.ts index 93785252..93902d9e 100644 --- a/server/src/use_case/appointment/CreateAppointmentUseCase.ts +++ b/server/src/use_case/appointment/CreateAppointmentUseCase.ts @@ -7,7 +7,7 @@ import IPaymentRepository from "../../domain/interface/repositories/IPaymentRepo import IPayment, { PaymentStatus } from "../../domain/entities/IPayment"; import IAppointment, { AppointmentStatus, AppointmentType } from "../../domain/entities/IAppointment"; import { StatusCode } from "../../types"; -import { IVideoSectionRepository } from "../../domain/interface/repositories/IVideoSectionRepository"; +import IVideoSectionRepository from "../../domain/interface/repositories/IVideoSectionRepository"; import IPatientRepository from "../../domain/interface/repositories/IPatientRepository"; import IDoctorRepository from "../../domain/interface/repositories/IDoctorRepository"; import IDoctor from "../../domain/entities/IDoctor"; diff --git a/server/src/use_case/appointment/UpdateAppointmentUseCase.ts b/server/src/use_case/appointment/UpdateAppointmentUseCase.ts index 28d78cd0..07f90f39 100644 --- a/server/src/use_case/appointment/UpdateAppointmentUseCase.ts +++ b/server/src/use_case/appointment/UpdateAppointmentUseCase.ts @@ -3,7 +3,7 @@ import INotificationRepository from "../../domain/interface/repositories/INotifi import IValidatorService from "../../domain/interface/services/IValidatorService"; import { AppointmentStatus } from "../../domain/entities/IAppointment"; import { NotificationTypes } from "../../domain/entities/INotification"; -import { IVideoSectionRepository } from "../../domain/interface/repositories/IVideoSectionRepository"; +import IVideoSectionRepository from "../../domain/interface/repositories/IVideoSectionRepository"; import { VideoSectionStatus } from "../../domain/entities/IVideoChatSection"; export default class UpdateAppointmentUseCase { @@ -19,7 +19,7 @@ export default class UpdateAppointmentUseCase { this.validatorService.validateRequiredFields({ appointmentId, status }); this.validatorService.validateIdFormat(appointmentId); this.validatorService.validateEnum(status, Object.values(AppointmentStatus)); - const appointment = await this.appointmentRepository.update({ _id: appointmentId, status }); + const appointment = await this.appointmentRepository.update(appointmentId, { status }); // notify patient if (status === AppointmentStatus.CANCELLED && appointment) { await this.notificationRepository.create({ @@ -46,7 +46,7 @@ export default class UpdateAppointmentUseCase { async updateStatusAndNote(appointmentId: string, status: AppointmentStatus, notes: string): Promise { this.validatorService.validateRequiredFields({ appointmentId, status, notes }); this.validatorService.validateEnum(status, Object.values(AppointmentStatus)); - const appointment = await this.appointmentRepository.update({ _id: appointmentId, status, notes }); + const appointment = await this.appointmentRepository.update(appointmentId, { status, notes }); // notify doctor if (status === AppointmentStatus.CANCELLED && appointment) { await this.notificationRepository.create({ diff --git a/server/src/use_case/patient/PatientUseCases.ts b/server/src/use_case/patient/PatientUseCases.ts index dcdb451c..aa1c7eca 100644 --- a/server/src/use_case/patient/PatientUseCases.ts +++ b/server/src/use_case/patient/PatientUseCases.ts @@ -6,7 +6,7 @@ import CustomError from "../../domain/entities/CustomError"; import { StatusCode } from "../../types"; import { AWS_REGION, S3_BUCKET_NAME } from "../../config/env"; import IChatRepository from "../../domain/interface/repositories/IChatRepository"; -import { IVideoSectionRepository } from "../../domain/interface/repositories/IVideoSectionRepository"; +import IVideoSectionRepository from "../../domain/interface/repositories/IVideoSectionRepository"; export default class PatientUseCase { constructor( diff --git a/server/src/use_case/video/GetVideoSectionUseCase.ts b/server/src/use_case/video/GetVideoSectionUseCase.ts index bb5eb9f9..145c489b 100644 --- a/server/src/use_case/video/GetVideoSectionUseCase.ts +++ b/server/src/use_case/video/GetVideoSectionUseCase.ts @@ -1,7 +1,7 @@ import IAppointment, { AppointmentStatus } from "../../domain/entities/IAppointment"; import IVideoSection, { VideoSectionStatus } from "../../domain/entities/IVideoChatSection"; import IAppointmentRepository from "../../domain/interface/repositories/IAppointmentRepository"; -import { IVideoSectionRepository } from "../../domain/interface/repositories/IVideoSectionRepository"; +import IVideoSectionRepository from "../../domain/interface/repositories/IVideoSectionRepository"; import IValidatorService from "../../domain/interface/services/IValidatorService"; import { addDays } from "../../utils/date-formatter";