fix: wrong understanding of system
This commit is contained in:
parent
ea10a5c3d9
commit
96618c6e06
5 changed files with 36 additions and 60 deletions
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `attributes` on the `Product` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "Product" DROP COLUMN "attributes";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Service" ADD COLUMN "attributes" JSONB;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Work" ADD COLUMN "attributes" JSONB;
|
||||
|
|
@ -537,9 +537,10 @@ model EmployeeOtherInfo {
|
|||
model Service {
|
||||
id String @id @default(uuid())
|
||||
|
||||
code String
|
||||
name String
|
||||
detail String
|
||||
code String
|
||||
name String
|
||||
detail String
|
||||
attributes Json?
|
||||
|
||||
status Status @default(CREATED)
|
||||
|
||||
|
|
@ -554,7 +555,8 @@ model Service {
|
|||
model Work {
|
||||
id String @id @default(uuid())
|
||||
|
||||
name String
|
||||
name String
|
||||
attributes Json?
|
||||
|
||||
status Status @default(CREATED)
|
||||
|
||||
|
|
@ -655,8 +657,6 @@ model Product {
|
|||
|
||||
workProduct WorkProduct[]
|
||||
|
||||
attributes Json?
|
||||
|
||||
createdBy String?
|
||||
createdAt DateTime @default(now())
|
||||
updateBy String?
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {
|
|||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Queries,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { Prisma, Status } from "@prisma/client";
|
||||
|
||||
|
|
@ -34,9 +34,6 @@ type ProductCreate = {
|
|||
price: number;
|
||||
agentPrice: number;
|
||||
serviceCharge: number;
|
||||
attributes?: {
|
||||
[key: string]: Date | string | number | null;
|
||||
};
|
||||
};
|
||||
|
||||
type ProductUpdate = {
|
||||
|
|
@ -46,9 +43,6 @@ type ProductUpdate = {
|
|||
price: number;
|
||||
agentPrice: number;
|
||||
serviceCharge: number;
|
||||
attributes?: {
|
||||
[key: string]: Date | string | number | null;
|
||||
};
|
||||
};
|
||||
|
||||
function imageLocation(id: string) {
|
||||
|
|
@ -61,55 +55,12 @@ function imageLocation(id: string) {
|
|||
export class ProductController extends Controller {
|
||||
@Get()
|
||||
async getProduct(
|
||||
@Queries()
|
||||
qs: {
|
||||
query?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
filter?: string[];
|
||||
},
|
||||
@Query() query: string = "",
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
) {
|
||||
qs.page = qs.page ?? 1;
|
||||
qs.pageSize = qs.pageSize ?? 30;
|
||||
qs.query = qs.query ?? "";
|
||||
|
||||
const { query, page, pageSize, filter } = qs;
|
||||
|
||||
const where = {
|
||||
OR: [{ name: { contains: query } }, { detail: { contains: query } }],
|
||||
AND: filter
|
||||
?.map((v) => {
|
||||
const match = /[\w\-]+:[\W\w]+$/.exec(v);
|
||||
|
||||
if (!match) return [];
|
||||
|
||||
const [key, ...rest] = v.split(":");
|
||||
const val = rest.join();
|
||||
|
||||
return {
|
||||
OR: [
|
||||
{
|
||||
attributes: {
|
||||
path: [key],
|
||||
string_contains: val,
|
||||
},
|
||||
},
|
||||
{
|
||||
attributes: {
|
||||
path: [key],
|
||||
equals: Number.isFinite(+val)
|
||||
? +val
|
||||
: val === "true"
|
||||
? true
|
||||
: val === "false"
|
||||
? false
|
||||
: val,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
})
|
||||
.flat(),
|
||||
} satisfies Prisma.ProductWhereInput;
|
||||
|
||||
const [result, total] = await prisma.$transaction([
|
||||
|
|
@ -172,7 +123,6 @@ export class ProductController extends Controller {
|
|||
data: {
|
||||
...body,
|
||||
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||
attributes: body.attributes,
|
||||
createdBy: req.user.name,
|
||||
updateBy: req.user.name,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ type ServiceCreate = {
|
|||
code: "MOU" | "mou";
|
||||
name: string;
|
||||
detail: string;
|
||||
attributes?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
workId: string[];
|
||||
};
|
||||
|
||||
|
|
@ -37,6 +40,9 @@ type ServiceUpdate = {
|
|||
name: string;
|
||||
detail: string;
|
||||
workId: string[];
|
||||
attributes?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
function imageLocation(id: string) {
|
||||
|
|
|
|||
|
|
@ -22,11 +22,17 @@ import HttpStatus from "../../interfaces/http-status";
|
|||
type WorkCreate = {
|
||||
name: string;
|
||||
productId: string[];
|
||||
attributes?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
type WorkUpdate = {
|
||||
name?: string;
|
||||
productId?: string[];
|
||||
attributes?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
@Route("api/v1/work")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue