update: Add service class relation to room entity and update related code
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Room, Paging } from "entity";
|
||||
import { Room, Paging, Service } from "entity";
|
||||
import { NextFunction, Response } from "express";
|
||||
import { Request } from "express-jwt";
|
||||
import Joi from "joi";
|
||||
@ -8,6 +8,7 @@ import { ReturnHelper } from "../helpers/express/return";
|
||||
import { Language } from "../langs/lang";
|
||||
import { RoomModel } from "../model/room";
|
||||
import { DepartmentModel } from "../model/department";
|
||||
import { ServiceClassModel } from "../model/service_class";
|
||||
import { OrmHelper } from "../helpers/orm";
|
||||
import moment from "moment";
|
||||
import fileUpload from "express-fileupload";
|
||||
@ -56,6 +57,7 @@ export class RoomController {
|
||||
const res_count = query;
|
||||
const res_list = query
|
||||
.leftJoinAndSelect("Room.department", "department")
|
||||
.leftJoinAndSelect("Room.serviceclass", "serviceclass")
|
||||
.orderBy("Room." + param.order_field, param.order_direction)
|
||||
.offset(offset)
|
||||
.limit(param.limit);
|
||||
@ -125,6 +127,7 @@ export class RoomController {
|
||||
code: Joi.string().max(128).required().label("Code"),
|
||||
description: Joi.string().allow("").max(512).optional().label("Description"),
|
||||
department_id: Joi.string().uuid().required().label("Department ID"),
|
||||
serviceclass: Joi.string().uuid().required().label("Service Class ID"),
|
||||
status: Joi.string().required().label("Status"),
|
||||
location: Joi.string().required().label("Location"),
|
||||
picture: Joi.string().required().label("picture"),
|
||||
@ -138,11 +141,15 @@ export class RoomController {
|
||||
let department = await DepartmentModel.list({ id: param.department_id }).then((q) => q.getOne());
|
||||
if (!department) throw { message: "Department not found" };
|
||||
|
||||
let serviceclass = await ServiceClassModel.list({ id: param.serviceclass }).then((q) => q.getOne());
|
||||
if (!serviceclass) throw { message: "Class not found" };
|
||||
|
||||
let room = new Room();
|
||||
room.room = param.room;
|
||||
room.code = param.code;
|
||||
room.description = param.description || null;
|
||||
room.department = department;
|
||||
room.serviceclass = param.serviceclass;
|
||||
room.status = param.status;
|
||||
room.location = param.location;
|
||||
room.picture = param.picture;
|
||||
@ -174,7 +181,7 @@ export class RoomController {
|
||||
});
|
||||
let param: any = await schema.validateAsync(req.params);
|
||||
let room = await RoomModel.list({ "Room.id": param.id })
|
||||
.then((q) => q.leftJoinAndSelect("Room.department", "department").getOne());
|
||||
.then((q) => q.leftJoinAndSelect("Room.department", "department").leftJoinAndSelect("Room.serviceclass", "serviceclass").getOne());
|
||||
if (!room) throw { message: "Room Not Found" };
|
||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, room);
|
||||
} catch (e: unknown) {
|
||||
@ -201,6 +208,7 @@ export class RoomController {
|
||||
code: Joi.string().max(128).required().label("Code"),
|
||||
description: Joi.string().allow("").max(512).optional().label("Description"),
|
||||
department_id: Joi.string().uuid().required().label("Department ID"),
|
||||
serviceclass: Joi.string().uuid().required().label("Service Class ID"),
|
||||
status: Joi.string().required().label("Status"),
|
||||
location: Joi.string().required().label("Location"),
|
||||
picture: Joi.string().required().label("picture"),
|
||||
@ -213,12 +221,16 @@ export class RoomController {
|
||||
let department = await DepartmentModel.list({ id: param.department_id }).then((q) => q.getOne());
|
||||
if (!department) throw { message: "Department not found" };
|
||||
|
||||
let serviceclass = await ServiceClassModel.list({ id: param.serviceclass }).then((q) => q.getOne());
|
||||
if (!serviceclass) throw { message: "Class not found" };
|
||||
|
||||
let room = await RoomModel.list({ "Room.id": param.id }).then((q) => q.getOne());
|
||||
if (!room) throw { message: "Room " + Language.lang.failed_not_found };
|
||||
|
||||
room.room = param.room;
|
||||
room.code = param.code;
|
||||
room.description = param.description || null;
|
||||
room.serviceclass = param.serviceclass;
|
||||
room.department = department;
|
||||
room.status = param.status;
|
||||
room.location = param.location;
|
||||
|
||||
Reference in New Issue
Block a user