fixing room to pharmacy
This commit is contained in:
@ -176,40 +176,49 @@ export class RoomToPharmacyController {
|
|||||||
.uuid()
|
.uuid()
|
||||||
.required()
|
.required()
|
||||||
.label("Pharmacy Room ID"),
|
.label("Pharmacy Room ID"),
|
||||||
|
|
||||||
|
room_id: Joi.string()
|
||||||
|
.uuid()
|
||||||
|
.required()
|
||||||
|
.label("Room ID"),
|
||||||
|
|
||||||
room_ids: Joi.array()
|
// room_ids: Joi.array()
|
||||||
.items(Joi.string().uuid().required())
|
// .items(Joi.string().uuid().required())
|
||||||
.min(1)
|
// .min(1)
|
||||||
.required()
|
// .required()
|
||||||
.label("Room IDs")
|
// .label("Room IDs")
|
||||||
});
|
});
|
||||||
|
|
||||||
const param: any = await schema.validateAsync(req.body);
|
const param: any = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
const RoomToPharmacyRepo = OrmHelper.DB.getRepository(RoomToPharmacy);
|
const data = new RoomToPharmacy()
|
||||||
const roomRepo = OrmHelper.DB.getRepository(Room);
|
data.pharmacy_room = param.pharmacy_room_id;
|
||||||
|
data.room = param.room_id;
|
||||||
|
data.created_by = req.auth.data.name;
|
||||||
|
|
||||||
await RoomToPharmacyRepo
|
await OrmHelper.DB.manager.save(data);
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(RoomToPharmacy)
|
|
||||||
.where("pharmacy_room_id = :pharmacyRoomId", { pharmacyRoomId: param.pharmacy_room_id })
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
let relation : RoomToPharmacy;
|
// await RoomToPharmacyRepo
|
||||||
for (const roomId of param.room_ids) {
|
// .createQueryBuilder()
|
||||||
relation = new RoomToPharmacy();
|
// .delete()
|
||||||
relation.room = await roomRepo.findOneBy({ id: roomId });
|
// .from(RoomToPharmacy)
|
||||||
relation.pharmacy_room = await roomRepo.findOneBy({ id: param.pharmacy_room_id });
|
// .where("pharmacy_room_id = :pharmacyRoomId", { pharmacyRoomId: param.pharmacy_room_id })
|
||||||
relation.created_by = req.auth.data.name;
|
// .execute();
|
||||||
|
|
||||||
await RoomToPharmacyRepo.save(relation);
|
// let relation : RoomToPharmacy;
|
||||||
}
|
// for (const roomId of param.room_ids) {
|
||||||
|
// relation = new RoomToPharmacy();
|
||||||
|
// relation.room = await roomRepo.findOneBy({ id: roomId });
|
||||||
|
// relation.pharmacy_room = await roomRepo.findOneBy({ id: param.pharmacy_room_id });
|
||||||
|
// relation.created_by = req.auth.data.name;
|
||||||
|
|
||||||
const data = await RoomToPharmacyRepo.createQueryBuilder("room_to_pharmacy")
|
// await RoomToPharmacyRepo.save(relation);
|
||||||
.leftJoinAndSelect("room_to_pharmacy.room", "room")
|
// }
|
||||||
.leftJoinAndSelect("room_to_pharmacy.pharmacy_room", "pharmacy_room")
|
|
||||||
.where("room_to_pharmacy.pharmacy_room_id = :pharmacyRoomId", { pharmacyRoomId: param.pharmacy_room_id }).getMany();
|
// const data = await RoomToPharmacyRepo.createQueryBuilder("room_to_pharmacy")
|
||||||
|
// .leftJoinAndSelect("room_to_pharmacy.room", "room")
|
||||||
|
// .leftJoinAndSelect("room_to_pharmacy.pharmacy_room", "pharmacy_room")
|
||||||
|
// .where("room_to_pharmacy.pharmacy_room_id = :pharmacyRoomId", { pharmacyRoomId: param.pharmacy_room_id }).getMany();
|
||||||
|
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_insert, data);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_insert, data);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
@ -219,4 +228,93 @@ export class RoomToPharmacyController {
|
|||||||
return ReturnHelper.errorResponse(res, 500, 401, Language.lang.failed_insert, err.message);
|
return ReturnHelper.errorResponse(res, 500, 401, Language.lang.failed_insert, err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async update(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['RoomToPharmacy']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
|
||||||
|
#swagger.requestBody = {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: {
|
||||||
|
$ref: "#/components/schemas/room_to_pharmacy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
const schema = Joi.object().keys({
|
||||||
|
|
||||||
|
id: Joi.string().uuid().required().label('ID'),
|
||||||
|
|
||||||
|
pharmacy_room_id: Joi.string()
|
||||||
|
.uuid()
|
||||||
|
.required()
|
||||||
|
.label("Pharmacy Room ID"),
|
||||||
|
|
||||||
|
room_id: Joi.string()
|
||||||
|
.uuid()
|
||||||
|
.required()
|
||||||
|
.label("Room ID"),
|
||||||
|
|
||||||
|
// room_ids: Joi.array()
|
||||||
|
// .items(Joi.string().uuid().required())
|
||||||
|
// .min(1)
|
||||||
|
// .required()
|
||||||
|
// .label("Room IDs")
|
||||||
|
});
|
||||||
|
|
||||||
|
req.body.id = req.params['id'];
|
||||||
|
|
||||||
|
const param: any = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
|
const repo = OrmHelper.DB.getRepository(RoomToPharmacy);
|
||||||
|
|
||||||
|
const data = await repo.findOneBy({ id: param.id });
|
||||||
|
|
||||||
|
if (data != null) {
|
||||||
|
data.pharmacy_room = param.pharmacy_room_id;
|
||||||
|
data.room = param.room_id;
|
||||||
|
data.updated_by = req.auth.data.name;
|
||||||
|
|
||||||
|
await repo.save(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_update, data);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
log.error(e);
|
||||||
|
const err = e as Error;
|
||||||
|
|
||||||
|
return ReturnHelper.errorResponse(res, 500, 401, Language.lang.failed_update, err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async detail(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['RoomToPharmacy']
|
||||||
|
#swagger.security = [{ "bearerAuth": [] }]
|
||||||
|
#swagger.parameters['id'] = { description: '', in: 'path', type: 'string' }
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
const schema = Joi.object().keys({
|
||||||
|
id: Joi.string().uuid().required().label("RoomToPharmacy Id"),
|
||||||
|
});
|
||||||
|
|
||||||
|
let param: any = await schema.validateAsync(req.params);
|
||||||
|
|
||||||
|
let data = await RoomToPharmacyModel.list({ "id": param.id }).then((q) => q.getOne());
|
||||||
|
if (!data) throw { message: "RoomToPharmacy Not Found" };
|
||||||
|
|
||||||
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -450,6 +450,8 @@ export class RoutePrivate {
|
|||||||
app.get('/api/room-to-pharmacy/list', RoomToPharmacyController.list)
|
app.get('/api/room-to-pharmacy/list', RoomToPharmacyController.list)
|
||||||
app.get('/api/room-to-pharmacy/export', RoomToPharmacyController.export)
|
app.get('/api/room-to-pharmacy/export', RoomToPharmacyController.export)
|
||||||
app.post('/api/room-to-pharmacy/create', RoomToPharmacyController.create)
|
app.post('/api/room-to-pharmacy/create', RoomToPharmacyController.create)
|
||||||
|
app.put('/api/room-to-pharmacy/update/:id', RoomToPharmacyController.update)
|
||||||
|
app.get('/api/room-to-pharmacy/view/:id', RoomToPharmacyController.detail)
|
||||||
|
|
||||||
app.get('/api/pharmacy/planning-verificator/list', PlanningVerificatorController.list)
|
app.get('/api/pharmacy/planning-verificator/list', PlanningVerificatorController.list)
|
||||||
app.get('/api/pharmacy/planning-verificator/export', PlanningVerificatorController.export)
|
app.get('/api/pharmacy/planning-verificator/export', PlanningVerificatorController.export)
|
||||||
|
|||||||
Reference in New Issue
Block a user