update room to pharmacy
This commit is contained in:
@ -422,11 +422,7 @@ export class RoomToPharmacyController {
|
|||||||
relations: ["room", "pharmacy_room"]
|
relations: ["room", "pharmacy_room"]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!data) {
|
// ambil pharmacy room
|
||||||
throw new Error("RoomToPharmacy data not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ✅ ambil pharmacy room baru
|
|
||||||
const pharmacyRoom = await OrmHelper.DB.getRepository(Room).findOneBy({
|
const pharmacyRoom = await OrmHelper.DB.getRepository(Room).findOneBy({
|
||||||
id: param.pharmacy_room_id
|
id: param.pharmacy_room_id
|
||||||
});
|
});
|
||||||
@ -435,11 +431,28 @@ export class RoomToPharmacyController {
|
|||||||
throw new Error("Pharmacy Room not found");
|
throw new Error("Pharmacy Room not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ update
|
if (data) {
|
||||||
data.pharmacy_room = pharmacyRoom;
|
// ✅ UPDATE (replace pharmacy_room)
|
||||||
data.updated_by = req.auth?.data.name;
|
data.pharmacy_room = pharmacyRoom;
|
||||||
|
data.updated_by = req.auth?.data.name;
|
||||||
|
|
||||||
await repo.save(data);
|
await repo.save(data);
|
||||||
|
} else {
|
||||||
|
// ✅ INSERT baru
|
||||||
|
const room = await OrmHelper.DB.getRepository(Room).findOneBy({
|
||||||
|
id: param.room_id
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!room) throw new Error("Room not found");
|
||||||
|
|
||||||
|
data = new RoomToPharmacy();
|
||||||
|
data.room = room;
|
||||||
|
data.pharmacy_room = pharmacyRoom;
|
||||||
|
data.created_by = req.auth?.data.name;
|
||||||
|
data.updated_by = req.auth?.data.name;
|
||||||
|
|
||||||
|
await repo.save(data);
|
||||||
|
}
|
||||||
|
|
||||||
return ReturnHelper.successResponseAny(
|
return ReturnHelper.successResponseAny(
|
||||||
res,
|
res,
|
||||||
|
|||||||
Reference in New Issue
Block a user