fix(surgery-type): fix the list from clause

This commit is contained in:
avicenan
2026-05-04 14:23:55 +07:00
parent acce0861a9
commit 1c0474600f
2 changed files with 12 additions and 6 deletions

View File

@ -47,7 +47,7 @@ export class SurgeryTypeController {
const res_count = query;
const res_list = query
.orderBy("SurgeryType." + param.order_field, param.order_direction)
.orderBy("st." + param.order_field, param.order_direction)
.offset(offset)
.limit(limit);
@ -110,7 +110,7 @@ export class SurgeryTypeController {
let param: { id: string } = await schema.validateAsync(req.params);
let surgeryType = await SurgeryTypeModel.list({ "SurgeryType.id": param.id }).then((q) => q.getOne());
let surgeryType = await SurgeryTypeModel.list({ "st.id": param.id }).then((q) => q.getOne());
if (!surgeryType) throw { message: "Surgery Type " + Language.lang.failed_not_found };
@ -142,7 +142,7 @@ export class SurgeryTypeController {
let exist = await SurgeryTypeModel.list({ name: param.name }).then((q) => q.getOne());
if (exist && exist.id != param.id) throw { message: "Surgery Type " + Language.lang.failed_duplicate };
let surgeryType = await SurgeryTypeModel.list({ "SurgeryType.id": param.id }).then((q) => q.getOne());
let surgeryType = await SurgeryTypeModel.list({ "st.id": param.id }).then((q) => q.getOne());
if (!surgeryType) throw { message: "Surgery Type " + Language.lang.failed_not_found };

View File

@ -9,11 +9,17 @@ export class SurgeryTypeModel {
let whereAttr: string[] = [];
let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) {
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter).whereAttr];
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter).whereVal };
const normalized: Record<string, unknown> = {};
for (const key of Object.keys(filter)) {
const nk = key.replace(/^SurgeryType\./, "st.");
normalized[nk] = (filter as Record<string, unknown>)[key];
}
const parsed = CommonHelper.handleQueryFilter(normalized, "st");
whereAttr = [...whereAttr, ...parsed.whereAttr];
whereVal = { ...whereVal, ...parsed.whereVal };
}
var query = repo.createQueryBuilder("SurgeryType");
var query = repo.createQueryBuilder("st");
if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal);
}