diff --git a/src/controllers/schedule.ts b/src/controllers/schedule.ts index eb1a2a4..bc60572 100644 --- a/src/controllers/schedule.ts +++ b/src/controllers/schedule.ts @@ -96,7 +96,7 @@ export class ScheduleController { /* #swagger.tags = ['Schedule'] #swagger.security = [{ "bearerAuth": [] }] - #swagger.parameters['filter'] = { in: 'query', required: false, type: 'string' } + #swagger.parameters['filter'] = { in: 'query', required: false, type: 'string', description: 'Filter by room id (optional)' } #swagger.responses[200] = { description: 'Schedule options', schema: { diff --git a/src/model/schedule.ts b/src/model/schedule.ts index e60241b..681ff13 100644 --- a/src/model/schedule.ts +++ b/src/model/schedule.ts @@ -4,6 +4,7 @@ import CommonHelper from "../helpers/common"; import { OrmHelper } from "../helpers/orm"; import dayjs from "dayjs"; import { RoomModel } from "./room"; +import { filter } from "compression"; type RecurrenceInput = { type: "daily" | "weekly" | "monthly"; @@ -59,7 +60,7 @@ export class ScheduleModel { return query; } - static async getScheduleCalendarRange(start: string, end: string, filterObj = {}, options: CalendarQueryOptions = {}): Promise { + static async getScheduleCalendarRange(start: string, end: string, filterObj: any, options: CalendarQueryOptions = {}): Promise { const startDate = dayjs(start); const endDate = dayjs(end); if (!startDate.isValid() || !endDate.isValid()) { @@ -72,6 +73,8 @@ export class ScheduleModel { throw new Error("Start date must be before end date"); } + const filterRoomId = filterObj && filterObj.roomId !== "" && filterObj.roomId !== null && filterObj.roomId !== undefined ? String(filterObj.roomId) : ""; + const page = options.page ?? 1; const limit = options.limit ?? 10; const offset = (page - 1) * limit; @@ -81,6 +84,10 @@ export class ScheduleModel { .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 }); + } + const roomTotalCount = await roomQuery .getCount(); const rooms = await roomQuery