Skip to content

Commit

Permalink
🚀 video and appointment Repositorys extended IRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Oct 2, 2024
1 parent 38f973e commit 2facc6a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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<IAppointment>;
update(appointment: IAppointment): Promise<IAppointment | null>;
export default interface IAppointmentRepository extends IRepository<IAppointment> {
updateManyBySlotIdsNotInStatuses(slotIds: string[], fields: IAppointment, notInStatuses:AppointmentStatus[]): Promise<IAppointment[] | null>;
findByDateAndSlot(appointmentDate: string, slotId: string): Promise<IAppointment | null>;
findManyByDateAndDoctorId(appointmentDate: string, doctorId: string): Promise<IAppointment[] | null>;
Expand Down
8 changes: 6 additions & 2 deletions server/src/domain/interface/repositories/IRepository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { PaginatedResult } from "../../../types";

export default interface IRepository<T> {
findById(id: string): Promise<T | null>;
findAll(): Promise<T[]>;
findAll?(): Promise<T[]>;
findManyByIds?(ids: string[]): Promise<T[] | null>;
findManyAsPaginated?(offset: number, limit: number): Promise<PaginatedResult<T> | null>;
create(entity: T): Promise<T>;
update(id: string, entity: T): Promise<T | null>;
delete(id: string): Promise<void>;
delete?(id: string): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import IVideoSection, { VideoSectionStatus } from "../../entities/IVideoChatSection";
import IRepository from "./IRepository";

export interface IVideoSectionRepository {
create(videoSection: IVideoSection): Promise<IVideoSection>;
findById(id: string): Promise<IVideoSection | null>;
update(id: string, videoSection: IVideoSection): Promise<IVideoSection | null>;
export default interface IVideoSectionRepository extends IRepository<IVideoSection> {
findByPatientIdAndUpdate(patientId: string, section: IVideoSection): Promise<void>;
findByDoctorIdAndUpdate(doctorId: string, section: IVideoSection): Promise<void>;
delete(id: string): Promise<void>;
findByAppointmentId(appointmentId: string): Promise<IVideoSection | null>;
findByStatus(status: VideoSectionStatus): Promise<IVideoSection | null>;
findByStartTimeRangeByDoctorId(startTime: string, endTime: string, doctorId: string): Promise<IVideoSection[] | null>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ export default class AppointmentRepository implements IAppointmentRepository {
async create(appointment: IAppointment): Promise<IAppointment> {
return (await this.model.create(appointment));
}
async update(appointment: IAppointment): Promise<IAppointment | null> {
return await this.model.findByIdAndUpdate(appointment._id, appointment, { new: true });

async findById(id: string): Promise<IAppointment | null> {
return await this.model.findById(id);
}

async update(id: string, appointment: IAppointment): Promise<IAppointment | null> {
return await this.model.findByIdAndUpdate(id, appointment, { new: true });
}

async findManyByIds(ids: string[]): Promise<IAppointment[] | null> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions server/src/use_case/appointment/UpdateAppointmentUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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({
Expand All @@ -46,7 +46,7 @@ export default class UpdateAppointmentUseCase {
async updateStatusAndNote(appointmentId: string, status: AppointmentStatus, notes: string): Promise<void> {
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({
Expand Down
2 changes: 1 addition & 1 deletion server/src/use_case/patient/PatientUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion server/src/use_case/video/GetVideoSectionUseCase.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down

1 comment on commit 2facc6a

@vercel
Copy link

@vercel vercel bot commented on 2facc6a Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.