feat: change status of product type after used
This commit is contained in:
parent
9c56d4ad91
commit
bf7676be77
1 changed files with 19 additions and 5 deletions
|
|
@ -180,6 +180,13 @@ export class ProductController extends Controller {
|
|||
},
|
||||
);
|
||||
|
||||
if (productType.status === "CREATED") {
|
||||
await prisma.productType.update({
|
||||
where: { id: body.productTypeId },
|
||||
data: { status: Status.ACTIVE },
|
||||
});
|
||||
}
|
||||
|
||||
this.setStatus(HttpStatus.CREATED);
|
||||
|
||||
return Object.assign(record, {
|
||||
|
|
@ -207,11 +214,6 @@ export class ProductController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "Product cannot be found.", "productNotFound");
|
||||
}
|
||||
|
||||
const record = await prisma.product.update({
|
||||
data: { ...body, updateBy: req.user.name },
|
||||
where: { id: productId },
|
||||
});
|
||||
|
||||
const productType = await prisma.productType.findFirst({
|
||||
where: { id: body.productTypeId },
|
||||
});
|
||||
|
|
@ -224,6 +226,18 @@ export class ProductController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
const record = await prisma.product.update({
|
||||
data: { ...body, updateBy: req.user.name },
|
||||
where: { id: productId },
|
||||
});
|
||||
|
||||
if (productType.status === "CREATED") {
|
||||
await prisma.productType.update({
|
||||
where: { id: body.productTypeId },
|
||||
data: { status: Status.ACTIVE },
|
||||
});
|
||||
}
|
||||
|
||||
return Object.assign(record, {
|
||||
imageUrl: await presignedGetObjectIfExist(
|
||||
MINIO_BUCKET,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue