upd: add detail for room services
This commit is contained in:
@ -67,8 +67,8 @@ export class RoomServicesController {
|
||||
name: room.department.name
|
||||
} : null,
|
||||
services: room.services ? room.services.map(service => ({
|
||||
service_id: service.id,
|
||||
service_name: service.name
|
||||
id: service.id,
|
||||
name: service.name
|
||||
})) : []
|
||||
}));
|
||||
|
||||
@ -173,6 +173,56 @@ export class RoomServicesController {
|
||||
}
|
||||
}
|
||||
|
||||
static async detail(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||
/*
|
||||
#swagger.tags = ['Room Services']
|
||||
#swagger.security = [{ "bearerAuth": [] }]
|
||||
#swagger.parameters['id'] = { description: 'Room ID', in: 'path', type: 'string' }
|
||||
*/
|
||||
try {
|
||||
const schema = Joi.object().keys({
|
||||
id: Joi.string().uuid().required().label("Room ID"),
|
||||
});
|
||||
|
||||
let param: any = await schema.validateAsync(req.params);
|
||||
|
||||
let room = await RoomModel.list({ "Room.id": param.id })
|
||||
.then((q) => q.leftJoinAndSelect("Room.services", "s")
|
||||
.leftJoinAndSelect("Room.department", "department").getOne());
|
||||
|
||||
if (!room) throw { message: "Room " + Language.lang.failed_not_found };
|
||||
|
||||
// Transform data: Format room with services
|
||||
const detail_data = {
|
||||
id: room.id,
|
||||
room: room.room,
|
||||
code: room.code,
|
||||
description: room.description,
|
||||
status: room.status,
|
||||
department: room.department ? {
|
||||
id: room.department.id,
|
||||
name: room.department.name
|
||||
} : null,
|
||||
services: room.services ? room.services.map(service => ({
|
||||
id: service.id,
|
||||
name: service.name
|
||||
})) : []
|
||||
};
|
||||
|
||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, detail_data);
|
||||
} catch (e: unknown) {
|
||||
log.error(e);
|
||||
const err = e as Error;
|
||||
return ReturnHelper.errorResponse(
|
||||
res,
|
||||
400,
|
||||
401,
|
||||
Language.lang.failed_not_found,
|
||||
err.message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static async update(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||
/*
|
||||
#swagger.tags = ['Room Services']
|
||||
|
||||
Reference in New Issue
Block a user