update: filter in registrationfee
This commit is contained in:
@ -15,7 +15,7 @@ const log: Logger<ILogObj> = new Logger({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const RegistrationFeeCreateAndUpdateSchema = {
|
const RegistrationFeeCreateAndUpdateSchema = {
|
||||||
service: Joi.array().items(Joi.string().allow(null,"").uuid()).optional().label("Service"),
|
service: Joi.array().items(Joi.string().allow(null, "").uuid()).optional().label("Service"),
|
||||||
type: Joi.string().valid("emergency", "outpatient").required().label("Type"),
|
type: Joi.string().valid("emergency", "outpatient").required().label("Type"),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,15 +24,23 @@ export class RegistrationFeeController {
|
|||||||
/*
|
/*
|
||||||
#swagger.tags = ['Registration Fee']
|
#swagger.tags = ['Registration Fee']
|
||||||
#swagger.security = [{ "bearerAuth": [] }]
|
#swagger.security = [{ "bearerAuth": [] }]
|
||||||
|
#swagger.parameters['filter'] = { description: '', in: 'query', type: 'string' }
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const result = await OrmHelper.DB.getRepository(RegistrationFee)
|
const schema = Joi.object().keys({
|
||||||
|
filter: Joi.string().allow("").optional().label("Filter"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const param = await schema.validateAsync(req.query);
|
||||||
|
const filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
||||||
|
|
||||||
|
const query = OrmHelper.DB.getRepository(RegistrationFee)
|
||||||
.createQueryBuilder("RegistrationFee")
|
.createQueryBuilder("RegistrationFee")
|
||||||
.leftJoinAndMapMany(
|
.leftJoinAndMapMany(
|
||||||
"RegistrationFee.services", // ← property yang akan diisi
|
"RegistrationFee.services",
|
||||||
Service,
|
Service,
|
||||||
"service",
|
"service",
|
||||||
"service.id::text = ANY(RegistrationFee.service)" // ← join langsung ke kolom array
|
"service.id::text = ANY(RegistrationFee.service)"
|
||||||
)
|
)
|
||||||
.select([
|
.select([
|
||||||
"RegistrationFee.id",
|
"RegistrationFee.id",
|
||||||
@ -42,8 +50,19 @@ export class RegistrationFeeController {
|
|||||||
"RegistrationFee.updated_at",
|
"RegistrationFee.updated_at",
|
||||||
"service.id",
|
"service.id",
|
||||||
"service.name",
|
"service.name",
|
||||||
])
|
]);
|
||||||
.getMany();
|
|
||||||
|
// ── Filter RegistrationFee.type ───────────────────────────────────
|
||||||
|
if (filter.type && filter.type !== "") {
|
||||||
|
query.andWhere("RegistrationFee.type = :type", { type: filter.type });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Filter service.name ───────────────────────────────────────────
|
||||||
|
if (filter.service_name && filter.service_name !== "") {
|
||||||
|
query.andWhere("service.name ILIKE :service_name", { service_name: `%${filter.service_name}%` });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await query.getMany();
|
||||||
|
|
||||||
if (!result || result.length === 0) throw { message: "Registration Fee " + Language.lang.failed_not_found };
|
if (!result || result.length === 0) throw { message: "Registration Fee " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
|||||||
@ -374,12 +374,12 @@ export class UserToRoomController {
|
|||||||
.where("user = :userId", { userId: param.user_id })
|
.where("user = :userId", { userId: param.user_id })
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
let relation: UserToRoom;
|
let relation: UserToRoom | any;
|
||||||
for (const roomId of param.room_ids) {
|
for (const roomId of param.room_ids) {
|
||||||
relation = new UserToRoom();
|
relation = new UserToRoom();
|
||||||
relation.user = await userRepo.findOneBy({ id: param.user_id });
|
relation.user = await userRepo.findOneBy({ id: param.user_id });
|
||||||
relation.room = await roomRepo.findOneBy({ id: roomId });
|
relation.room = await roomRepo.findOneBy({ id: roomId });
|
||||||
relation.created_by = req.auth.data.name;
|
relation.created_by = req.auth?.data.name;
|
||||||
|
|
||||||
await userToRoomRepo.save(relation);
|
await userToRoomRepo.save(relation);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user