From 2d0438535a048de09ab2aa83e075c3dd7c82ff60 Mon Sep 17 00:00:00 2001 From: avicenan Date: Mon, 20 Apr 2026 11:59:58 +0700 Subject: [PATCH] fix(schedule): calendar add doctor filter --- src/model/schedule.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/model/schedule.ts b/src/model/schedule.ts index d028bcd..323c429 100644 --- a/src/model/schedule.ts +++ b/src/model/schedule.ts @@ -74,6 +74,7 @@ export class ScheduleModel { } const filterRoomId = filterObj && filterObj.roomId !== "" && filterObj.roomId !== null && filterObj.roomId !== undefined ? String(filterObj.roomId) : ""; + const filterDoctorId = filterObj && filterObj.doctorId !== "" && filterObj.doctorId !== null && filterObj.doctorId !== undefined ? String(filterObj.doctorId) : ""; const page = options.page ?? 1; const limit = options.limit ?? 10; @@ -83,10 +84,8 @@ export class ScheduleModel { const roomQuery = query .select(["Room.id", "Room.room", "Room.code", "Room.picture", "Room.location", "Room.status", "Department.name"]) .leftJoin("Room.department", "Department") - .where("Department.name = :departmentName", { departmentName: "Outpatient" }); - if (filterRoomId !== "") { - roomQuery.andWhere("Room.id = :roomId", { roomId: filterRoomId }); - } + .where("Department.name = :departmentName", { departmentName: "Outpatient" }) + .andWhere(filterRoomId !== "" ? "Room.id = :roomId" : "1=1", { roomId: filterRoomId }); const roomTotalCount = await roomQuery .getCount(); @@ -103,6 +102,7 @@ export class ScheduleModel { .andWhere("ScheduleSeries.start_date <= :rangeEndDate", { rangeEndDate: dayjs(rangeEnd).format("YYYY-MM-DD") }) .andWhere("(ScheduleSeries.until_date IS NULL OR ScheduleSeries.until_date >= :rangeStartDate)", { rangeStartDate: dayjs(rangeStart).format("YYYY-MM-DD") }) .andWhere("ScheduleSeries.deleted_at IS NULL") + .andWhere(filterDoctorId !== "" ? "ScheduleSeries.doctor_id = :doctorId" : "1=1", { doctorId: filterDoctorId }) .orderBy("ScheduleSeries.start_time", "ASC") .getMany();