Skip to content

Commit

Permalink
get chat secction usecase added
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 26, 2024
1 parent 2ed0342 commit 38bca87
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export interface IVideoSectionRepository {
update(id: string, videoSection: IVideoSection): Promise<IVideoSection | null>;
delete(id: string): Promise<void>;
findByAppointmentId(appointmentId: string): Promise<IVideoSection | null>;
findByStartTime(startTime: Date): Promise<IVideoSection | null>;
findByEndTime(endTime: Date): Promise<IVideoSection | null>;
findByStatus(status: VideoSectionStatus): Promise<IVideoSection | null>;
findByStartTimeRange(startTime: string, endTime: string): Promise<IVideoSection[] | null>;
}


10 changes: 4 additions & 6 deletions server/src/infrastructure/repositories/VideoSectionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ export default class VideoSectionRepository implements IVideoSectionRepository {
return await this.model.findOne({ appointmentId });
}

async findByStartTime(startTime: Date): Promise<IVideoSection | null> {
return await this.model.findOne({ startTime });
}

async findByEndTime(endTime: Date): Promise<IVideoSection | null> {
return await this.model.findOne({ endTime });
async findByStartTimeRange(startTime: string, endTime: string): Promise<IVideoSection[] | null> {
return await this.model.find({
startTime: { $gte: startTime, $lte: endTime }
});
}

async findByStatus(status: VideoSectionStatus): Promise<IVideoSection | null> {
Expand Down
31 changes: 31 additions & 0 deletions server/src/use_case/video/GetVideoSectionUseCase.ts
Original file line number Diff line number Diff line change
@@ -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<IVideoSection | null> {
this.validatorService.validateIdFormat(id)
return await this.videoSectionRepository.findById(id);
}

async getSectionByAppointmentId(appointmentId: string): Promise<IVideoSection | null> {
this.validatorService.validateIdFormat(appointmentId)
return await this.videoSectionRepository.findByAppointmentId(appointmentId);
}

async getSectionsInOneHour(): Promise<IVideoSection[] | []> {
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 ?? [];
}


}

1 comment on commit 38bca87

@vercel
Copy link

@vercel vercel bot commented on 38bca87 Sep 26, 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.