fixing room services

This commit is contained in:
avicenan
2026-03-13 09:51:50 +07:00
parent a930c29e7f
commit c0fc0b9177

View File

@ -9,7 +9,7 @@ export class RoomServicesModel {
const repo = OrmHelper.DB.getRepository(Service); const repo = OrmHelper.DB.getRepository(Service);
let whereAttr: string[] = []; let whereAttr: string[] = [];
let whereVal: any = {}; let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) { if (filter && Object.keys(filter).length > 0) {
const filterResult = CommonHelper.handleQueryFilter(filter); const filterResult = CommonHelper.handleQueryFilter(filter);
whereAttr = [...whereAttr, ...filterResult.whereAttr]; whereAttr = [...whereAttr, ...filterResult.whereAttr];
@ -18,7 +18,8 @@ export class RoomServicesModel {
let query = repo.createQueryBuilder("Service") let query = repo.createQueryBuilder("Service")
.leftJoinAndSelect("Service.rooms", "Room") .leftJoinAndSelect("Service.rooms", "Room")
.leftJoinAndSelect("Room.department", "Department"); .leftJoinAndSelect("Room.department", "Department")
.leftJoinAndSelect("Service.serviceType", "ServiceType");
if (whereAttr.length != 0) { if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal); query = query.where(whereAttr.join(" and "), whereVal);
@ -35,7 +36,7 @@ export class RoomServicesModel {
const repo = OrmHelper.DB.getRepository(Room); const repo = OrmHelper.DB.getRepository(Room);
let whereAttr: string[] = []; let whereAttr: string[] = [];
let whereVal: any = {}; let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) { if (filter && Object.keys(filter).length > 0) {
const filterResult = CommonHelper.handleQueryFilter(filter, "Room"); const filterResult = CommonHelper.handleQueryFilter(filter, "Room");
whereAttr = [...whereAttr, ...filterResult.whereAttr]; whereAttr = [...whereAttr, ...filterResult.whereAttr];
@ -44,7 +45,8 @@ export class RoomServicesModel {
let query = repo.createQueryBuilder("Room") let query = repo.createQueryBuilder("Room")
.leftJoinAndSelect("Room.services", "Service") .leftJoinAndSelect("Room.services", "Service")
.leftJoinAndSelect("Room.department", "Department"); .leftJoinAndSelect("Room.department", "Department")
.leftJoinAndSelect("Service.serviceType", "ServiceType");
if (whereAttr.length != 0) { if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal); query = query.where(whereAttr.join(" and "), whereVal);
@ -60,7 +62,7 @@ export class RoomServicesModel {
// Method untuk count rooms (bukan relationships) // Method untuk count rooms (bukan relationships)
static async countRooms(filter = {}, withDeleted = false): Promise<number> { static async countRooms(filter = {}, withDeleted = false): Promise<number> {
const repo = OrmHelper.DB.getRepository(Service); const repo = OrmHelper.DB.getRepository(Service);
// Query untuk menghitung total unique rooms yang punya services // Query untuk menghitung total unique rooms yang punya services
let queryBuilder = repo.createQueryBuilder("Service") let queryBuilder = repo.createQueryBuilder("Service")
.innerJoin("Service.rooms", "Room") .innerJoin("Service.rooms", "Room")
@ -84,7 +86,7 @@ export class RoomServicesModel {
// Method untuk count services // Method untuk count services
static async countServices(filter = {}, withDeleted = false): Promise<number> { static async countServices(filter = {}, withDeleted = false): Promise<number> {
const repo = OrmHelper.DB.getRepository(Room); const repo = OrmHelper.DB.getRepository(Room);
// Query untuk menghitung total unique services yang punya rooms // Query untuk menghitung total unique services yang punya rooms
let queryBuilder = repo.createQueryBuilder("Room") let queryBuilder = repo.createQueryBuilder("Room")
.innerJoin("Room.services", "Service") .innerJoin("Room.services", "Service")