From 38bca877f5bd1f4bff0746e8b661ded5d0a8c0cb Mon Sep 17 00:00:00 2001 From: Sinan Date: Thu, 26 Sep 2024 22:37:34 +0530 Subject: [PATCH] get chat secction usecase added --- .../repositories/IVideoSectionRepository.ts | 3 +- .../repositories/VideoSectionRepository.ts | 10 +++--- .../use_case/video/GetVideoSectionUseCase.ts | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 server/src/use_case/video/GetVideoSectionUseCase.ts diff --git a/server/src/domain/interface/repositories/IVideoSectionRepository.ts b/server/src/domain/interface/repositories/IVideoSectionRepository.ts index 6f830e8e..668e5b39 100644 --- a/server/src/domain/interface/repositories/IVideoSectionRepository.ts +++ b/server/src/domain/interface/repositories/IVideoSectionRepository.ts @@ -6,9 +6,8 @@ export interface IVideoSectionRepository { update(id: string, videoSection: IVideoSection): Promise; delete(id: string): Promise; findByAppointmentId(appointmentId: string): Promise; - findByStartTime(startTime: Date): Promise; - findByEndTime(endTime: Date): Promise; findByStatus(status: VideoSectionStatus): Promise; + findByStartTimeRange(startTime: string, endTime: string): Promise; } diff --git a/server/src/infrastructure/repositories/VideoSectionRepository.ts b/server/src/infrastructure/repositories/VideoSectionRepository.ts index 9ae8c378..f81283b2 100644 --- a/server/src/infrastructure/repositories/VideoSectionRepository.ts +++ b/server/src/infrastructure/repositories/VideoSectionRepository.ts @@ -25,12 +25,10 @@ export default class VideoSectionRepository implements IVideoSectionRepository { return await this.model.findOne({ appointmentId }); } - async findByStartTime(startTime: Date): Promise { - return await this.model.findOne({ startTime }); - } - - async findByEndTime(endTime: Date): Promise { - return await this.model.findOne({ endTime }); + async findByStartTimeRange(startTime: string, endTime: string): Promise { + return await this.model.find({ + startTime: { $gte: startTime, $lte: endTime } + }); } async findByStatus(status: VideoSectionStatus): Promise { diff --git a/server/src/use_case/video/GetVideoSectionUseCase.ts b/server/src/use_case/video/GetVideoSectionUseCase.ts new file mode 100644 index 00000000..1630259a --- /dev/null +++ b/server/src/use_case/video/GetVideoSectionUseCase.ts @@ -0,0 +1,31 @@ +import IVideoSection from "../../domain/entities/IVideoChatSection"; +// import IAppointmentRepository from "../../domain/interface/repositories/IAppointmentRepository"; +import { IVideoSectionRepository } from "../../domain/interface/repositories/IVideoSectionRepository"; +import IValidatorService from "../../domain/interface/services/IValidatorService"; + +export default class GetVideoSectionUseCase { + constructor( + private readonly videoSectionRepository: IVideoSectionRepository, + private readonly validatorService: IValidatorService + // private readonly appointmentRepository: IAppointmentRepository + ) { } + + async getSectionById(id: string): Promise { + this.validatorService.validateIdFormat(id) + return await this.videoSectionRepository.findById(id); + } + + async getSectionByAppointmentId(appointmentId: string): Promise { + this.validatorService.validateIdFormat(appointmentId) + return await this.videoSectionRepository.findByAppointmentId(appointmentId); + } + + async getSectionsInOneHour(): Promise { + const currentTime = new Date(); + const afterOneHour = new Date(currentTime.getTime() + 60 * 60 * 1000); + const sections = await this.videoSectionRepository.findByStartTimeRange(currentTime.toISOString(), afterOneHour.toISOString()); + return sections ?? []; + } + + +}