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[]
|
product Product[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model ProductDocument {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
name String
|
||||||
|
|
||||||
|
product Product? @relation(fields: [productId], references: [id])
|
||||||
|
productId String?
|
||||||
|
}
|
||||||
|
|
||||||
model Product {
|
model Product {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
|
|
||||||
|
|
@ -1059,6 +1067,8 @@ model Product {
|
||||||
remark String?
|
remark String?
|
||||||
selectedImage String?
|
selectedImage String?
|
||||||
|
|
||||||
|
document ProductDocument[]
|
||||||
|
|
||||||
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
|
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
|
||||||
productGroupId String
|
productGroupId String
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ type ProductCreate = {
|
||||||
shared?: boolean;
|
shared?: boolean;
|
||||||
productGroupId: string;
|
productGroupId: string;
|
||||||
remark?: string;
|
remark?: string;
|
||||||
|
document?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type ProductUpdate = {
|
type ProductUpdate = {
|
||||||
|
|
@ -80,6 +81,7 @@ type ProductUpdate = {
|
||||||
selectedImage?: string;
|
selectedImage?: string;
|
||||||
shared?: boolean;
|
shared?: boolean;
|
||||||
productGroupId?: string;
|
productGroupId?: string;
|
||||||
|
document?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@Route("api/v1/product")
|
@Route("api/v1/product")
|
||||||
|
|
@ -270,6 +272,11 @@ export class ProductController extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
|
document: body.document
|
||||||
|
? {
|
||||||
|
createMany: { data: body.document.map((v) => ({ name: v })) },
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
statusOrder: +(body.status === "INACTIVE"),
|
statusOrder: +(body.status === "INACTIVE"),
|
||||||
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||||
createdByUserId: req.user.sub,
|
createdByUserId: req.user.sub,
|
||||||
|
|
@ -343,7 +350,17 @@ export class ProductController extends Controller {
|
||||||
createdBy: true,
|
createdBy: true,
|
||||||
updatedBy: 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 },
|
where: { id: productId },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue