feat: change status of product type after used

This commit is contained in:
Methapon2001 2024-06-19 17:08:47 +07:00
parent 9c56d4ad91
commit bf7676be77

View file

@ -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); this.setStatus(HttpStatus.CREATED);
return Object.assign(record, { return Object.assign(record, {
@ -207,11 +214,6 @@ export class ProductController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "Product cannot be found.", "productNotFound"); 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({ const productType = await prisma.productType.findFirst({
where: { id: body.productTypeId }, 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, { return Object.assign(record, {
imageUrl: await presignedGetObjectIfExist( imageUrl: await presignedGetObjectIfExist(
MINIO_BUCKET, MINIO_BUCKET,