diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-30 01:54:09 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-30 01:54:09 +0000 |
| commit | d59a5175210c18fcc675cde93865339abf37a406 (patch) | |
| tree | 085834900e7b65c60364602432c38f3030d456e2 /lib/items-tech/service.ts | |
| parent | 3bdd648ad4cb863043db181291ddaebbc025965b (diff) | |
(최겸) 기술영업 아이템리스트 filter, sort 적용
Diffstat (limited to 'lib/items-tech/service.ts')
| -rw-r--r-- | lib/items-tech/service.ts | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/lib/items-tech/service.ts b/lib/items-tech/service.ts index 9fa35148..6047552f 100644 --- a/lib/items-tech/service.ts +++ b/lib/items-tech/service.ts @@ -9,7 +9,7 @@ import { unstable_cache } from "@/lib/unstable-cache"; import { getErrorMessage } from "@/lib/handle-error";
import { asc, desc, ilike, and, or, eq, count, inArray, sql } from "drizzle-orm";
-import { GetItemsSchema, UpdateItemSchema, ShipbuildingItemCreateData, TypedItemCreateData, OffshoreTopItemCreateData, OffshoreHullItemCreateData } from "./validations";
+import { GetShipbuildingSchema, GetOffshoreTopSchema, GetOffshoreHullSchema, UpdateItemSchema, ShipbuildingItemCreateData, TypedItemCreateData, OffshoreTopItemCreateData, OffshoreHullItemCreateData } from "./validations";
import { Item, items, itemShipbuilding, itemOffshoreTop, itemOffshoreHull, ItemOffshoreTop, ItemOffshoreHull } from "@/db/schema/items";
import { findAllItems } from "./repository";
import { findAllOffshoreItems } from "./repository";
@@ -23,7 +23,7 @@ import { findAllOffshoreItems } from "./repository"; * 총 개수에 따라 pageCount를 계산해서 리턴.
* Next.js의 unstable_cache를 사용해 일정 시간 캐시.
*/
-export async function getShipbuildingItems(input: GetItemsSchema) {
+export async function getShipbuildingItems(input: GetShipbuildingSchema) {
return unstable_cache(
async () => {
try {
@@ -34,6 +34,12 @@ export async function getShipbuildingItems(input: GetItemsSchema) { table: items,
filters: input.filters,
joinOperator: input.joinOperator,
+ joinedTables: { itemShipbuilding },
+ customColumnMapping: {
+ workType: { table: itemShipbuilding, column: "workType" },
+ shipTypes: { table: itemShipbuilding, column: "shipTypes" },
+ itemList: { table: itemShipbuilding, column: "itemList" },
+ },
});
let globalWhere;
@@ -41,8 +47,7 @@ export async function getShipbuildingItems(input: GetItemsSchema) { const s = `%${input.search}%`;
globalWhere = or(
ilike(items.itemCode, s),
- ilike(items.itemName, s),
- ilike(items.description, s)
+ ilike(itemShipbuilding.itemList, s)
);
}
@@ -55,10 +60,13 @@ export async function getShipbuildingItems(input: GetItemsSchema) { const orderBy =
input.sort.length > 0
- ? input.sort.map((item) =>
- item.desc ? desc(items[item.id]) : asc(items[item.id])
- )
- : [asc(items.createdAt)];
+ ? input.sort.map((item) => {
+ const column = item.id === "workType" || item.id === "shipTypes" || item.id === "itemList"
+ ? itemShipbuilding[item.id]
+ : items[item.id];
+ return item.desc ? desc(column) : asc(column);
+ })
+ : [desc(items.createdAt)];
// 조선 아이템 테이블과 기본 아이템 테이블 조인하여 조회
const result = await db.select({
@@ -103,7 +111,7 @@ export async function getShipbuildingItems(input: GetItemsSchema) { )();
}
-export async function getOffshoreTopItems(input: GetItemsSchema) {
+export async function getOffshoreTopItems(input: GetOffshoreTopSchema) {
return unstable_cache(
async () => {
try {
@@ -114,6 +122,12 @@ export async function getOffshoreTopItems(input: GetItemsSchema) { table: items,
filters: input.filters,
joinOperator: input.joinOperator,
+ joinedTables: { itemOffshoreTop },
+ customColumnMapping: {
+ workType: { table: itemOffshoreTop, column: "workType" },
+ itemList: { table: itemOffshoreTop, column: "itemList" },
+ subItemList: { table: itemOffshoreTop, column: "subItemList" },
+ },
});
let globalWhere;
@@ -121,8 +135,8 @@ export async function getOffshoreTopItems(input: GetItemsSchema) { const s = `%${input.search}%`;
globalWhere = or(
ilike(items.itemCode, s),
- ilike(items.itemName, s),
- ilike(items.description, s)
+ ilike(itemOffshoreTop.itemList, s),
+ ilike(itemOffshoreTop.subItemList, s)
);
}
@@ -135,10 +149,13 @@ export async function getOffshoreTopItems(input: GetItemsSchema) { const orderBy =
input.sort.length > 0
- ? input.sort.map((item) =>
- item.desc ? desc(items[item.id]) : asc(items[item.id])
- )
- : [asc(items.createdAt)];
+ ? input.sort.map((item) => {
+ const column = item.id === "workType" || item.id === "itemList" || item.id === "subItemList"
+ ? itemOffshoreTop[item.id]
+ : items[item.id];
+ return item.desc ? desc(column) : asc(column);
+ })
+ : [desc(items.createdAt)];
// 해양 TOP 아이템 테이블과 기본 아이템 테이블 조인하여 조회
const result = await db.select({
@@ -183,7 +200,7 @@ export async function getOffshoreTopItems(input: GetItemsSchema) { )();
}
-export async function getOffshoreHullItems(input: GetItemsSchema) {
+export async function getOffshoreHullItems(input: GetOffshoreHullSchema) {
return unstable_cache(
async () => {
try {
@@ -194,6 +211,12 @@ export async function getOffshoreHullItems(input: GetItemsSchema) { table: items,
filters: input.filters,
joinOperator: input.joinOperator,
+ joinedTables: { itemOffshoreHull },
+ customColumnMapping: {
+ workType: { table: itemOffshoreHull, column: "workType" },
+ itemList: { table: itemOffshoreHull, column: "itemList" },
+ subItemList: { table: itemOffshoreHull, column: "subItemList" },
+ },
});
let globalWhere;
@@ -201,8 +224,8 @@ export async function getOffshoreHullItems(input: GetItemsSchema) { const s = `%${input.search}%`;
globalWhere = or(
ilike(items.itemCode, s),
- ilike(items.itemName, s),
- ilike(items.description, s)
+ ilike(itemOffshoreHull.itemList, s),
+ ilike(itemOffshoreHull.subItemList, s)
);
}
@@ -215,10 +238,13 @@ export async function getOffshoreHullItems(input: GetItemsSchema) { const orderBy =
input.sort.length > 0
- ? input.sort.map((item) =>
- item.desc ? desc(items[item.id]) : asc(items[item.id])
- )
- : [asc(items.createdAt)];
+ ? input.sort.map((item) => {
+ const column = item.id === "workType" || item.id === "itemList" || item.id === "subItemList"
+ ? itemOffshoreHull[item.id]
+ : items[item.id];
+ return item.desc ? desc(column) : asc(column);
+ })
+ : [desc(items.createdAt)];
// 해양 HULL 아이템 테이블과 기본 아이템 테이블 조인하여 조회
const result = await db.select({
|
