feat: add document list to product data
This commit is contained in:
parent
c8b8b58484
commit
a811c17bde
2 changed files with 28 additions and 1 deletions
|
|
@ -1036,6 +1036,14 @@ model ProductGroup {
|
|||
product Product[]
|
||||
}
|
||||
|
||||
model ProductDocument {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
|
||||
product Product? @relation(fields: [productId], references: [id])
|
||||
productId String?
|
||||
}
|
||||
|
||||
model Product {
|
||||
id String @id @default(cuid())
|
||||
|
||||
|
|
@ -1059,6 +1067,8 @@ model Product {
|
|||
remark String?
|
||||
selectedImage String?
|
||||
|
||||
document ProductDocument[]
|
||||
|
||||
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
|
||||
productGroupId String
|
||||
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ type ProductCreate = {
|
|||
shared?: boolean;
|
||||
productGroupId: string;
|
||||
remark?: string;
|
||||
document?: string[];
|
||||
};
|
||||
|
||||
type ProductUpdate = {
|
||||
|
|
@ -80,6 +81,7 @@ type ProductUpdate = {
|
|||
selectedImage?: string;
|
||||
shared?: boolean;
|
||||
productGroupId?: string;
|
||||
document?: string[];
|
||||
};
|
||||
|
||||
@Route("api/v1/product")
|
||||
|
|
@ -270,6 +272,11 @@ export class ProductController extends Controller {
|
|||
},
|
||||
data: {
|
||||
...body,
|
||||
document: body.document
|
||||
? {
|
||||
createMany: { data: body.document.map((v) => ({ name: v })) },
|
||||
}
|
||||
: undefined,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||
createdByUserId: req.user.sub,
|
||||
|
|
@ -343,7 +350,17 @@ export class ProductController extends Controller {
|
|||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
||||
data: {
|
||||
...body,
|
||||
document: body.document
|
||||
? {
|
||||
deleteMany: {},
|
||||
createMany: { data: body.document.map((v) => ({ name: v })) },
|
||||
}
|
||||
: undefined,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
updatedByUserId: req.user.sub,
|
||||
},
|
||||
where: { id: productId },
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue