update
This commit is contained in:
@ -49,8 +49,14 @@ export class QueueMonitoringController {
|
||||
|
||||
const res_count = query;
|
||||
const res_list = query
|
||||
.leftJoinAndSelect("QueueMonitoring.rooms", "rooms")
|
||||
.leftJoinAndSelect("rooms.department", "department")
|
||||
.leftJoinAndMapMany(
|
||||
"QueueMonitoring.queue_monitoring_rooms", //
|
||||
QueueMonitoringRooms,
|
||||
"qmr",
|
||||
'qmr."queueMonitoringId" = "QueueMonitoring"."id"',
|
||||
)
|
||||
.leftJoinAndSelect("qmr.room", "room")
|
||||
.leftJoinAndSelect("room.department", "department")
|
||||
.orderBy("QueueMonitoring." + param.order_field, param.order_direction)
|
||||
.offset(offset)
|
||||
.limit(limit);
|
||||
@ -62,9 +68,20 @@ export class QueueMonitoringController {
|
||||
|
||||
const current_page = param.page;
|
||||
const total_count_data = await res_count.getCount();
|
||||
const list_data = await res_list.getMany();
|
||||
let list_data = await res_list.getMany();
|
||||
const count_data = CommonHelper.countObject(list_data);
|
||||
|
||||
if (list_data && list_data.length > 0) {
|
||||
list_data = list_data.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
rooms: (item.queue_monitoring_rooms || []).map((qmr) => qmr.room),
|
||||
};
|
||||
});
|
||||
|
||||
list_data = list_data.map(({ queue_monitoring_rooms, ...rest }) => rest);
|
||||
}
|
||||
|
||||
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, list_data);
|
||||
} catch (e: unknown) {
|
||||
log.error(e);
|
||||
@ -86,10 +103,27 @@ export class QueueMonitoringController {
|
||||
|
||||
const param: any = await schema.validateAsync(req.params);
|
||||
|
||||
const queueMonitoring = await QueueMonitoringModel.list({ "QueueMonitoring.slug": param.slug }).then((q) => q.leftJoinAndSelect("QueueMonitoring.rooms", "rooms").leftJoinAndSelect("rooms.department", "department").getOne());
|
||||
const queueMonitoring = await QueueMonitoringModel.list({ "QueueMonitoring.slug": param.slug }).then((q) =>
|
||||
q //
|
||||
.leftJoinAndMapMany(
|
||||
"QueueMonitoring.queue_monitoring_rooms", //
|
||||
QueueMonitoringRooms,
|
||||
"qmr",
|
||||
'qmr."queueMonitoringId" = "QueueMonitoring"."id"',
|
||||
)
|
||||
.leftJoinAndSelect("qmr.room", "room")
|
||||
.leftJoinAndSelect("room.department", "department")
|
||||
.getOne(),
|
||||
);
|
||||
|
||||
if (!queueMonitoring) throw { message: "Queue Monitoring Not Found" };
|
||||
|
||||
if (queueMonitoring) {
|
||||
queueMonitoring.rooms = (queueMonitoring.queue_monitoring_rooms || []).map((item) => item.room);
|
||||
|
||||
delete queueMonitoring.queue_monitoring_rooms;
|
||||
}
|
||||
|
||||
if (queueMonitoring.rooms && queueMonitoring.rooms.length > 0) {
|
||||
try {
|
||||
const roomIds = queueMonitoring.rooms.map((room: any) => room.id);
|
||||
@ -215,6 +249,8 @@ export class QueueMonitoringController {
|
||||
await queryRunner.manager.save(queueMonitoring);
|
||||
|
||||
if (param.room_ids && param.room_ids.length > 0) {
|
||||
await queryRunner.manager.getRepository(QueueMonitoringRooms).createQueryBuilder().delete().from(QueueMonitoringRooms).where('qmr."queueMonitoringId" = :id', { id: queueMonitoring.id }).execute();
|
||||
|
||||
for (const roomId of param.room_ids) {
|
||||
const room = await RoomModel.list({ id: roomId }).then((q) => q.getOne());
|
||||
if (!room) throw { message: `Room with id ${roomId} not found` };
|
||||
@ -255,10 +291,27 @@ export class QueueMonitoringController {
|
||||
|
||||
let param: any = await schema.validateAsync(req.params);
|
||||
|
||||
let queueMonitoring = await QueueMonitoringModel.list({ "QueueMonitoring.id": param.id }).then((q) => q.leftJoinAndSelect("QueueMonitoring.rooms", "rooms").leftJoinAndSelect("rooms.department", "department").getOne());
|
||||
let queueMonitoring = await QueueMonitoringModel.list({ "QueueMonitoring.id": param.id }).then((q) =>
|
||||
q //
|
||||
.leftJoinAndMapMany(
|
||||
"QueueMonitoring.queue_monitoring_rooms", //
|
||||
QueueMonitoringRooms,
|
||||
"qmr",
|
||||
'qmr."queueMonitoringId" = "QueueMonitoring"."id"',
|
||||
)
|
||||
.leftJoinAndSelect("qmr.room", "room")
|
||||
.leftJoinAndSelect("room.department", "department")
|
||||
.getOne(),
|
||||
);
|
||||
|
||||
if (!queueMonitoring) throw { message: "Queue Monitoring Not Found" };
|
||||
|
||||
if (queueMonitoring) {
|
||||
queueMonitoring.rooms = (queueMonitoring.queue_monitoring_rooms || []).map((item) => item.room);
|
||||
|
||||
delete queueMonitoring.queue_monitoring_rooms;
|
||||
}
|
||||
|
||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, queueMonitoring);
|
||||
} catch (e: unknown) {
|
||||
log.error(e);
|
||||
@ -294,22 +347,35 @@ export class QueueMonitoringController {
|
||||
|
||||
if (!queueMonitoring) throw { message: "Queue Monitoring " + Language.lang.failed_not_found };
|
||||
|
||||
let rooms: any[] = [];
|
||||
if (param.room_ids && param.room_ids.length > 0) {
|
||||
for (const roomId of param.room_ids) {
|
||||
const room = await RoomModel.list({ id: roomId }).then((q) => q.getOne());
|
||||
if (!room) throw { message: `Room with id ${roomId} not found` };
|
||||
rooms.push(room);
|
||||
}
|
||||
}
|
||||
|
||||
queueMonitoring.slug = param.slug;
|
||||
queueMonitoring.name = param.name;
|
||||
queueMonitoring.rooms = rooms;
|
||||
queueMonitoring.status = param.status;
|
||||
queueMonitoring.updated_by = req.auth.data.name;
|
||||
await queryRunner.manager.save(queueMonitoring);
|
||||
|
||||
if (param.room_ids && param.room_ids.length > 0) {
|
||||
await queryRunner.manager //
|
||||
.getRepository(QueueMonitoringRooms)
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(QueueMonitoringRooms)
|
||||
.where('"queueMonitoringId" = :id', { id: queueMonitoring.id })
|
||||
.execute();
|
||||
|
||||
for (const roomId of param.room_ids) {
|
||||
const room = await RoomModel.list({ id: roomId }).then((q) => q.getOne());
|
||||
if (!room) throw { message: `Room with id ${roomId} not found` };
|
||||
|
||||
let queueMonitoringRooms = new QueueMonitoringRooms();
|
||||
queueMonitoringRooms.queue_monitoring = queueMonitoring;
|
||||
queueMonitoringRooms.room = room;
|
||||
queueMonitoringRooms.status = param.status;
|
||||
queueMonitoringRooms.created_by = req.auth.data.name;
|
||||
queueMonitoringRooms.updated_by = req.auth.data.name;
|
||||
await queryRunner.manager.save(queueMonitoringRooms);
|
||||
}
|
||||
}
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_update, queueMonitoring);
|
||||
|
||||
Reference in New Issue
Block a user