update: list in room to pharmacy

This commit is contained in:
wayanrivan
2026-04-09 15:52:35 +07:00
parent c4aed0c142
commit 81b9105523
2 changed files with 147 additions and 69 deletions

View File

@ -1,24 +1,34 @@
import { SelectQueryBuilder } from "typeorm";
import CommonHelper from "../helpers/common";
import { OrmHelper } from "../helpers/orm";
import { RoomToPharmacy } from "entity";
import { RoomToPharmacy, Room } from "entity";
export class RoomToPharmacyModel {
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
const repo = OrmHelper.DB.getRepository(RoomToPharmacy);
let whereAttr: string[] = [];
let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) {
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter, "room_to_pharmacy").whereAttr];
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter, "room_to_pharmacy").whereVal };
}
const repo = OrmHelper.DB.getRepository(Room);
var query = repo.createQueryBuilder("room_to_pharmacy")
.leftJoinAndSelect("room_to_pharmacy.room", "room")
.leftJoinAndSelect("room_to_pharmacy.pharmacy_room", "pharmacy_room");
if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal);
}
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',
]
});
return query;
}