refactor!: remove deprecated
This commit is contained in:
parent
1f6ab0027d
commit
916ea84565
1 changed files with 0 additions and 107 deletions
|
|
@ -1,107 +0,0 @@
|
|||
import { Controller, Get, Query, Route, Security } from "tsoa";
|
||||
import { sql } from "kysely";
|
||||
|
||||
import prisma from "../db";
|
||||
|
||||
@Route("/api/v1/product-service")
|
||||
export class ProductServiceController extends Controller {
|
||||
@Get()
|
||||
@Security("keycloak")
|
||||
async getProductService(
|
||||
@Query() status?: "ACTIVE" | "INACTIVE",
|
||||
@Query() query = "",
|
||||
@Query() productGroupId?: string,
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
@Query() registeredBranchId?: string,
|
||||
) {
|
||||
const union = prisma.$kysely
|
||||
.selectFrom((eb) =>
|
||||
eb
|
||||
.selectFrom("Product")
|
||||
.select([
|
||||
"id",
|
||||
"code",
|
||||
"name",
|
||||
"detail",
|
||||
"price",
|
||||
"agentPrice",
|
||||
"serviceCharge",
|
||||
"process",
|
||||
"remark",
|
||||
"status",
|
||||
"statusOrder",
|
||||
"productGroupId",
|
||||
"registeredBranchId",
|
||||
"createdByUserId",
|
||||
"createdAt",
|
||||
"updatedByUserId",
|
||||
"updatedAt",
|
||||
sql<string>`'product'`.as("type"),
|
||||
])
|
||||
.union((eb) =>
|
||||
eb
|
||||
.selectFrom("Service")
|
||||
.select([
|
||||
"id",
|
||||
"code",
|
||||
"name",
|
||||
"detail",
|
||||
sql<number>`-1`.as("price"),
|
||||
sql<number>`-1`.as("agentPrice"),
|
||||
sql<number>`-1`.as("serviceCharge"),
|
||||
sql<number>`-1`.as("process"),
|
||||
sql<string>`''`.as("remark"),
|
||||
"status",
|
||||
"statusOrder",
|
||||
"productGroupId",
|
||||
"registeredBranchId",
|
||||
"createdByUserId",
|
||||
"createdAt",
|
||||
"updatedByUserId",
|
||||
"updatedAt",
|
||||
sql<string>`'service'`.as("type"),
|
||||
]),
|
||||
)
|
||||
.as("p"),
|
||||
)
|
||||
.where((eb) => {
|
||||
const condStatus = status ? eb("status", "=", status) : undefined;
|
||||
const condQuery = query ? eb("name", "like", `%${query}%`) : undefined;
|
||||
const condProductGroupId = productGroupId
|
||||
? eb("productGroupId", "=", productGroupId)
|
||||
: undefined;
|
||||
const condRegisteredBranchId = registeredBranchId
|
||||
? eb("registeredBranchId", "=", registeredBranchId).or("registeredBranchId", "is", null)
|
||||
: undefined;
|
||||
|
||||
return eb.and(
|
||||
[condStatus, condQuery, condProductGroupId, condRegisteredBranchId].filter((v) => !!v),
|
||||
);
|
||||
});
|
||||
|
||||
const record = await union
|
||||
.selectAll()
|
||||
.orderBy("statusOrder asc")
|
||||
.orderBy("createdAt asc")
|
||||
.limit(pageSize)
|
||||
.offset((page - 1) * pageSize)
|
||||
.execute();
|
||||
const count = await union
|
||||
.select((eb) => eb.fn.count<number>("id").as("total"))
|
||||
.executeTakeFirst();
|
||||
|
||||
const work = await prisma.work.findMany({
|
||||
where: { serviceId: { in: record.flatMap((v) => (v.type === "service" ? v.id : [])) } },
|
||||
});
|
||||
|
||||
return {
|
||||
result: record.map((v) =>
|
||||
v.type === "service" ? { ...v, work: work.filter((w) => w.serviceId === v.id) || [] } : v,
|
||||
),
|
||||
page,
|
||||
pageSize,
|
||||
total: +String(count?.total || 0),
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue