update room to pharmacy

This commit is contained in:
wayanrivan
2026-04-10 16:02:00 +07:00
parent 81b9105523
commit 4496afcbb9
2 changed files with 33 additions and 27 deletions

View File

@ -5,30 +5,19 @@ import { RoomToPharmacy, Room } from "entity";
export class RoomToPharmacyModel {
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
const repo = OrmHelper.DB.getRepository(Room);
const query = repo
.createQueryBuilder("room")
.leftJoinAndSelect("room.department", "department")
.leftJoinAndMapMany(
"room.roomToPharmacies",
RoomToPharmacy,
"room_to_pharmacy",
"room_to_pharmacy.room_id = room.id"
)
.leftJoinAndMapOne(
"room_to_pharmacy.pharmacy_room",
Room,
"pharmacy_room",
"pharmacy_room.id = room_to_pharmacy.pharmacy_room_id"
)
.where("department.id IN (:...departmentIds)", {
departmentIds: [
'42bc42a7-e2a7-4f95-a788-9d9e51a51a20',
'3fc39ff1-b4bc-4276-92ef-def7ca9432fb',
'a0d2ef11-6927-4e5c-8628-6acf26351071',
]
});
const repo = OrmHelper.DB.getRepository(RoomToPharmacy);
let whereAttr: string[] = [];
let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) {
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter).whereAttr];
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter).whereVal };
}
var query = repo.createQueryBuilder("room_to_pharmacy");
if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal);
}
return query;
}