Merge branch 'main' of https://git.shiblysolution.id/SAUDE-TL/service-master-data
This commit is contained in:
@ -24,7 +24,7 @@ const hospitalCreateUpdateSchema = {
|
|||||||
name: Joi.string().required().label("Hospital Name"),
|
name: Joi.string().required().label("Hospital Name"),
|
||||||
address: Joi.string().required().label("Hospital Address"),
|
address: Joi.string().required().label("Hospital Address"),
|
||||||
phone: Joi.string().required().label("Hospital Phone"),
|
phone: Joi.string().required().label("Hospital Phone"),
|
||||||
logo: Joi.string().required().label("Hospital Logo"),
|
logo: Joi.string().allow(null,"").label("Hospital Logo"),
|
||||||
};
|
};
|
||||||
|
|
||||||
interface FileUploadRequest extends Request {
|
interface FileUploadRequest extends Request {
|
||||||
@ -66,7 +66,7 @@ export class HospitalInformationController {
|
|||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
const err = e as Error;
|
const err = e as Error;
|
||||||
return ReturnHelper.errorResponse(res,400,401,Language.lang.failed_view,err.message);
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,13 +139,15 @@ export class HospitalInformationController {
|
|||||||
|
|
||||||
if (!hospital) throw { message: "Hospital " + Language.lang.failed_not_found };
|
if (!hospital) throw { message: "Hospital " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
if(param.logo == "" || param.logo == null || param.logo == undefined) param.logo = hospital.logo;
|
||||||
|
|
||||||
let hospitalinformation = new HospitalInformation();
|
let hospitalinformation = new HospitalInformation();
|
||||||
hospitalinformation.id = param.id;
|
hospitalinformation.id = param.id;
|
||||||
hospitalinformation.name = param.name;
|
hospitalinformation.name = param.name;
|
||||||
hospitalinformation.address = param.address;
|
hospitalinformation.address = param.address;
|
||||||
hospitalinformation.phone = param.phone;
|
hospitalinformation.phone = param.phone;
|
||||||
hospitalinformation.logo = param.logo;
|
hospitalinformation.logo = param.logo ? param.logo : hospital.logo;
|
||||||
hospitalinformation.updated_by = req.auth.data.name;
|
hospitalinformation.updated_by = req.auth?.data.name;
|
||||||
await queryRunner.manager.save(hospitalinformation);
|
await queryRunner.manager.save(hospitalinformation);
|
||||||
|
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
@ -231,7 +233,7 @@ export class HospitalInformationController {
|
|||||||
// md5: file.md5
|
// md5: file.md5
|
||||||
};
|
};
|
||||||
|
|
||||||
const folder_path ='uploads/hospital-logo/';
|
const folder_path = 'uploads/hospital-logo/';
|
||||||
const file_path = path.join(folder_path, name);
|
const file_path = path.join(folder_path, name);
|
||||||
|
|
||||||
// Create directory if it doesn't exist
|
// Create directory if it doesn't exist
|
||||||
|
|||||||
@ -36,13 +36,54 @@ export class UserToRoomController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let param: Paging = await schema.validateAsync(req.query);
|
let param: Paging = await schema.validateAsync(req.query);
|
||||||
|
|
||||||
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
||||||
|
|
||||||
const offset = (param.page - 1) * param.limit;
|
const offset = (param.page - 1) * param.limit;
|
||||||
const limit = param.limit;
|
const limit = param.limit;
|
||||||
|
|
||||||
// Query dari User sebagai root, leftJoin ke UserToRoom → Room
|
// Base filter builder (reusable untuk step 1 & count)
|
||||||
|
const applyFilters = (qb: any) => {
|
||||||
|
if (param.with_deleted) qb.withDeleted();
|
||||||
|
if (filter.name) qb.andWhere("user.name ILIKE :name", { name: `%${filter.name}%` });
|
||||||
|
if (filter.status) qb.andWhere("user.status = :status", { status: filter.status });
|
||||||
|
return qb;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 1: Ambil paginated user IDs dulu (tanpa join room)
|
||||||
|
const idQuery = OrmHelper.DB.getRepository(User)
|
||||||
|
.createQueryBuilder("user")
|
||||||
|
.select("user.id")
|
||||||
|
.orderBy("user." + param.order_field, param.order_direction as "ASC" | "DESC")
|
||||||
|
.offset(offset)
|
||||||
|
.limit(limit);
|
||||||
|
|
||||||
|
applyFilters(idQuery);
|
||||||
|
|
||||||
|
const paginatedUserIds = await idQuery.getRawMany();
|
||||||
|
const userIds = paginatedUserIds.map((row) => row.user_id);
|
||||||
|
|
||||||
|
if (userIds.length === 0) {
|
||||||
|
return ReturnHelper.successResponselist(
|
||||||
|
res,
|
||||||
|
200,
|
||||||
|
Language.lang.success_view,
|
||||||
|
0,
|
||||||
|
param.page,
|
||||||
|
0,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Count total (tanpa join room, tanpa offset/limit)
|
||||||
|
const countQuery = OrmHelper.DB.getRepository(User)
|
||||||
|
.createQueryBuilder("user")
|
||||||
|
.select("user.id");
|
||||||
|
|
||||||
|
applyFilters(countQuery);
|
||||||
|
|
||||||
|
const total_count_data = await countQuery.getCount();
|
||||||
|
|
||||||
|
// Step 3: Fetch data lengkap hanya untuk IDs yang sudah dipaginasi
|
||||||
const userQuery = OrmHelper.DB.getRepository(User)
|
const userQuery = OrmHelper.DB.getRepository(User)
|
||||||
.createQueryBuilder("user")
|
.createQueryBuilder("user")
|
||||||
.leftJoinAndSelect("user.roles", "roles")
|
.leftJoinAndSelect("user.roles", "roles")
|
||||||
@ -58,26 +99,12 @@ export class UserToRoomController {
|
|||||||
"room",
|
"room",
|
||||||
"room.id = user_to_room.room"
|
"room.id = user_to_room.room"
|
||||||
)
|
)
|
||||||
|
.whereInIds(userIds)
|
||||||
.orderBy("user." + param.order_field, param.order_direction as "ASC" | "DESC");
|
.orderBy("user." + param.order_field, param.order_direction as "ASC" | "DESC");
|
||||||
|
|
||||||
if (param.with_deleted) {
|
if (param.with_deleted) userQuery.withDeleted();
|
||||||
userQuery.withDeleted();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter jika ada
|
const users = await userQuery.getMany();
|
||||||
if (filter.name) {
|
|
||||||
userQuery.andWhere("user.name ILIKE :name", { name: `%${filter.name}%` });
|
|
||||||
}
|
|
||||||
if (filter.status) {
|
|
||||||
userQuery.andWhere("user.status = :status", { status: filter.status });
|
|
||||||
}
|
|
||||||
|
|
||||||
const total_count_data = await userQuery.clone().getCount();
|
|
||||||
|
|
||||||
const users = await userQuery
|
|
||||||
.offset(offset)
|
|
||||||
.limit(limit)
|
|
||||||
.getMany();
|
|
||||||
|
|
||||||
// Transform data
|
// Transform data
|
||||||
const list_data_return = users.map((user: any) => {
|
const list_data_return = users.map((user: any) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user