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 {
|
model Service {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
|
|
||||||
code String
|
code String
|
||||||
name String
|
name String
|
||||||
detail String
|
detail String
|
||||||
|
attributes Json?
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
|
||||||
|
|
@ -554,7 +555,8 @@ model Service {
|
||||||
model Work {
|
model Work {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
|
|
||||||
name String
|
name String
|
||||||
|
attributes Json?
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
|
||||||
|
|
@ -655,8 +657,6 @@ model Product {
|
||||||
|
|
||||||
workProduct WorkProduct[]
|
workProduct WorkProduct[]
|
||||||
|
|
||||||
attributes Json?
|
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updateBy String?
|
updateBy String?
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
Queries,
|
Query,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { Prisma, Status } from "@prisma/client";
|
import { Prisma, Status } from "@prisma/client";
|
||||||
|
|
||||||
|
|
@ -34,9 +34,6 @@ type ProductCreate = {
|
||||||
price: number;
|
price: number;
|
||||||
agentPrice: number;
|
agentPrice: number;
|
||||||
serviceCharge: number;
|
serviceCharge: number;
|
||||||
attributes?: {
|
|
||||||
[key: string]: Date | string | number | null;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type ProductUpdate = {
|
type ProductUpdate = {
|
||||||
|
|
@ -46,9 +43,6 @@ type ProductUpdate = {
|
||||||
price: number;
|
price: number;
|
||||||
agentPrice: number;
|
agentPrice: number;
|
||||||
serviceCharge: number;
|
serviceCharge: number;
|
||||||
attributes?: {
|
|
||||||
[key: string]: Date | string | number | null;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function imageLocation(id: string) {
|
function imageLocation(id: string) {
|
||||||
|
|
@ -61,55 +55,12 @@ function imageLocation(id: string) {
|
||||||
export class ProductController extends Controller {
|
export class ProductController extends Controller {
|
||||||
@Get()
|
@Get()
|
||||||
async getProduct(
|
async getProduct(
|
||||||
@Queries()
|
@Query() query: string = "",
|
||||||
qs: {
|
@Query() page: number = 1,
|
||||||
query?: string;
|
@Query() pageSize: number = 30,
|
||||||
page?: number;
|
|
||||||
pageSize?: number;
|
|
||||||
filter?: string[];
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
qs.page = qs.page ?? 1;
|
|
||||||
qs.pageSize = qs.pageSize ?? 30;
|
|
||||||
qs.query = qs.query ?? "";
|
|
||||||
|
|
||||||
const { query, page, pageSize, filter } = qs;
|
|
||||||
|
|
||||||
const where = {
|
const where = {
|
||||||
OR: [{ name: { contains: query } }, { detail: { contains: query } }],
|
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;
|
} satisfies Prisma.ProductWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
@ -172,7 +123,6 @@ export class ProductController extends Controller {
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||||
attributes: body.attributes,
|
|
||||||
createdBy: req.user.name,
|
createdBy: req.user.name,
|
||||||
updateBy: req.user.name,
|
updateBy: req.user.name,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@ type ServiceCreate = {
|
||||||
code: "MOU" | "mou";
|
code: "MOU" | "mou";
|
||||||
name: string;
|
name: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
|
attributes?: {
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
workId: string[];
|
workId: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -37,6 +40,9 @@ type ServiceUpdate = {
|
||||||
name: string;
|
name: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
workId: string[];
|
workId: string[];
|
||||||
|
attributes?: {
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function imageLocation(id: string) {
|
function imageLocation(id: string) {
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,17 @@ import HttpStatus from "../../interfaces/http-status";
|
||||||
type WorkCreate = {
|
type WorkCreate = {
|
||||||
name: string;
|
name: string;
|
||||||
productId: string[];
|
productId: string[];
|
||||||
|
attributes?: {
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
type WorkUpdate = {
|
type WorkUpdate = {
|
||||||
name?: string;
|
name?: string;
|
||||||
productId?: string[];
|
productId?: string[];
|
||||||
|
attributes?: {
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@Route("api/v1/work")
|
@Route("api/v1/work")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue