diff --git a/src/controllers/product/product-controller.ts b/src/controllers/product/product-controller.ts index b0fcf80..1cb86f7 100644 --- a/src/controllers/product/product-controller.ts +++ b/src/controllers/product/product-controller.ts @@ -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,