feat(api)!: replace doctor favorite item endpoints

This commit is contained in:
avicenan
2026-03-17 11:18:48 +07:00
parent 68df2841aa
commit 520ad68f84
7 changed files with 320 additions and 237 deletions

View File

@ -1,24 +1,22 @@
import { DoctorFavoriteItem } from "entity";
import { DoctorItem } from "entity";
import { SelectQueryBuilder } from "typeorm";
import CommonHelper from "../helpers/common";
import { OrmHelper } from "../helpers/orm";
export class DoctorFavoriteItemModel {
export class DoctorItemModel {
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
const repo = OrmHelper.DB.getRepository(DoctorFavoriteItem);
const repo = OrmHelper.DB.getRepository(DoctorItem);
let whereAttr: string[] = [];
let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) {
const filterResult = CommonHelper.handleQueryFilter(filter, "DoctorFavoriteItem");
const filterResult = CommonHelper.handleQueryFilter(filter, "DoctorItem");
whereAttr = [...whereAttr, ...filterResult.whereAttr];
whereVal = { ...whereVal, ...filterResult.whereVal };
}
let query = repo
.createQueryBuilder("DoctorFavoriteItem")
.leftJoinAndSelect("DoctorFavoriteItem.doctor", "Doctor")
.leftJoinAndSelect("DoctorFavoriteItem.item_master", "ItemMaster");
.createQueryBuilder("DoctorItem")
if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal);

View File

@ -4,7 +4,7 @@ import CommonHelper from "../helpers/common";
import { OrmHelper } from "../helpers/orm";
export class DoctorItemPackageModel {
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
static async list(filter = {}, filterAny: string = ""): Promise<SelectQueryBuilder<any>> {
const repo = OrmHelper.DB.getRepository(DoctorItemPackage);
let whereAttr: string[] = [];
let whereVal: any = {};
@ -14,11 +14,24 @@ export class DoctorItemPackageModel {
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: ["DoctorItemPackage.name"],
});
if (filterResult.whereAttr && filterResult.whereAttr !== "") {
whereAttr = [...whereAttr, filterResult.whereAttr];
whereVal = { ...whereVal, ...filterResult.whereVal };
}
}
let query = repo
.createQueryBuilder("DoctorItemPackage")
.leftJoinAndSelect("DoctorItemPackage.doctor", "Doctor")
.leftJoinAndSelect("DoctorItemPackage.items", "ItemMaster");
.leftJoinAndSelect("DoctorItemPackage.items", "ItemMaster")
.leftJoinAndSelect("ItemMaster.generic_name", "GenericName");
if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal);