fix(settings): service

This commit is contained in:
avicenan
2026-05-26 17:27:19 +09:00
parent ba354c8f9f
commit d1c839b931
2 changed files with 21 additions and 4 deletions

View File

@ -43,8 +43,12 @@ export class ServiceController {
let param: Paging = await schema.validateAsync(req.query);
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
let filterAny = filter.any && filter.any !== "" ? filter.any : "";
var query = await ServiceModel.list(filter);
let filterObj = { ...filter } as any;
delete filterObj.any;
var query = await ServiceModel.list(filterObj, filterAny);
const offset = (param.page - 1) * param.limit;
let limit = param.limit;

View File

@ -4,16 +4,29 @@ import CommonHelper from "../helpers/common";
import { OrmHelper } from "../helpers/orm";
export class ServiceModel {
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
static async list(filterObj = {}, filterAny: string = ""): Promise<SelectQueryBuilder<any>> {
const repo = OrmHelper.DB.getRepository(Service);
let whereAttr: string[] = [];
let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) {
const filterResult = CommonHelper.handleQueryFilter(filter, "Service");
if (filterObj && Object.keys(filterObj).length > 0) {
const filterResult = CommonHelper.handleQueryFilter(filterObj, "Service");
whereAttr = [...whereAttr, ...filterResult.whereAttr];
whereVal = { ...whereVal, ...filterResult.whereVal };
}
if (filterAny && filterAny !== "" && filterAny !== null && filterAny !== undefined) {
const filterResult = CommonHelper.handleFilter({
filter: JSON.stringify({ any: filterAny }),
col_any_eq: [],
col_any_like: ["name", "serviceType.name"],
});
if (filterResult.whereAttr && filterResult.whereAttr !== "") {
whereAttr = [...whereAttr, filterResult.whereAttr];
whereVal = { ...whereVal, ...filterResult.whereVal };
}
}
var query = repo.createQueryBuilder("Service");
if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal);