summaryrefslogtreecommitdiff
path: root/lib/form-list/service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/form-list/service.ts')
-rw-r--r--lib/form-list/service.ts28
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/form-list/service.ts b/lib/form-list/service.ts
index 64156cf4..310930be 100644
--- a/lib/form-list/service.ts
+++ b/lib/form-list/service.ts
@@ -8,6 +8,7 @@ import { filterColumns } from "@/lib/filter-columns";
import { tagTypeClassFormMappings } from "@/db/schema/vendorData";
import { asc, desc, ilike, inArray, and, gte, lte, not, or } from "drizzle-orm";
import { countFormLists, selectFormLists } from "./repository";
+import { projects } from "@/db/schema";
export async function getFormLists(input: GetFormListsSchema) {
@@ -31,7 +32,9 @@ export async function getFormLists(input: GetFormListsSchema) {
if (input.search) {
const s = `%${input.search}%`
globalWhere = or(ilike(tagTypeClassFormMappings.formCode, s), ilike(tagTypeClassFormMappings.formName, s)
- , ilike(tagTypeClassFormMappings.tagTypeLabel, s) , ilike(tagTypeClassFormMappings.classLabel, s)
+ , ilike(tagTypeClassFormMappings.tagTypeLabel, s) , ilike(tagTypeClassFormMappings.classLabel, s),
+ ilike(projects.name, s),
+ ilike(projects.code, s),
)
// 필요시 여러 칼럼 OR조건 (status, priority, etc)
}
@@ -48,12 +51,21 @@ export async function getFormLists(input: GetFormListsSchema) {
const orderBy =
- input.sort.length > 0
- ? input.sort.map((item) =>
- item.desc ? desc(tagTypeClassFormMappings[item.id]) : asc(tagTypeClassFormMappings[item.id])
- )
- : [asc(tagTypeClassFormMappings.createdAt)];
-
+ input.sort.length > 0
+ ? input.sort.map((item) => {
+ // 프로젝트 관련 필드 정렬 처리
+ if (item.id === 'projectCode') {
+ return item.desc ? desc(projects.code) : asc(projects.code);
+ } else if (item.id === 'projectName') {
+ return item.desc ? desc(projects.name) : asc(projects.name);
+ } else {
+ // 기존 필드 정렬
+ return item.desc
+ ? desc(tagTypeClassFormMappings[item.id])
+ : asc(tagTypeClassFormMappings[item.id]);
+ }
+ })
+ : [asc(tagTypeClassFormMappings.createdAt)];
// 트랜잭션 내부에서 Repository 호출
const { data, total } = await db.transaction(async (tx) => {
const data = await selectFormLists(tx, {
@@ -78,7 +90,7 @@ export async function getFormLists(input: GetFormListsSchema) {
[JSON.stringify(input)], // 캐싱 키
{
revalidate: 3600,
- tags: ["form-lists"], // revalidateTag("items") 호출 시 무효화
+ tags: ["form-lists"],
}
)();
} \ No newline at end of file