feat: update add status
This commit is contained in:
parent
9ebbb5260f
commit
9c56d4ad91
2 changed files with 30 additions and 7 deletions
|
|
@ -23,12 +23,14 @@ type ProductGroupCreate = {
|
|||
name: string;
|
||||
detail: string;
|
||||
remark: string;
|
||||
status?: Status;
|
||||
};
|
||||
|
||||
type ProductGroupUpdate = {
|
||||
name?: string;
|
||||
detail?: string;
|
||||
remark?: string;
|
||||
status?: "ACTIVE" | "INACTIVE";
|
||||
};
|
||||
|
||||
@Route("api/v1/product-group")
|
||||
|
|
@ -66,7 +68,11 @@ export class ProductGroup extends Controller {
|
|||
});
|
||||
|
||||
if (!record)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Product group cannot be found.", "productGroupNotFound");
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Product group cannot be found.",
|
||||
"productGroupNotFound",
|
||||
);
|
||||
|
||||
return record;
|
||||
}
|
||||
|
|
@ -110,7 +116,11 @@ export class ProductGroup extends Controller {
|
|||
@Path() groupId: string,
|
||||
) {
|
||||
if (!(await prisma.productGroup.findUnique({ where: { id: groupId } }))) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Product group cannot be found.", "productGroupNotFound");
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Product group cannot be found.",
|
||||
"productGroupNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
const record = await prisma.productGroup.update({
|
||||
|
|
@ -126,7 +136,11 @@ export class ProductGroup extends Controller {
|
|||
const record = await prisma.productGroup.findFirst({ where: { id: groupId } });
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Product group cannot be found.", "productGroupNotFound");
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Product group cannot be found.",
|
||||
"productGroupNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
if (record.status !== Status.CREATED) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type ProductTypeCreate = {
|
|||
name: string;
|
||||
detail: string;
|
||||
remark: string;
|
||||
status?: Status;
|
||||
};
|
||||
|
||||
type ProductTypeUpdate = {
|
||||
|
|
@ -31,6 +32,7 @@ type ProductTypeUpdate = {
|
|||
name?: string;
|
||||
detail?: string;
|
||||
remark?: string;
|
||||
status?: "ACTIVE" | "INACTIVE";
|
||||
};
|
||||
|
||||
@Route("api/v1/product-type")
|
||||
|
|
@ -139,10 +141,10 @@ export class ProductType extends Controller {
|
|||
@Body() body: ProductTypeUpdate,
|
||||
@Path() typeId: string,
|
||||
) {
|
||||
if (
|
||||
body.productGroupId &&
|
||||
!(await prisma.productGroup.findFirst({ where: { id: body.productGroupId } }))
|
||||
) {
|
||||
const productGroup = await prisma.productGroup.findFirst({
|
||||
where: { id: body.productGroupId },
|
||||
});
|
||||
if (body.productGroupId && !productGroup) {
|
||||
throw new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"Product group cannot be found.",
|
||||
|
|
@ -163,6 +165,13 @@ export class ProductType extends Controller {
|
|||
where: { id: typeId },
|
||||
});
|
||||
|
||||
if (productGroup?.status === "CREATED") {
|
||||
await prisma.productGroup.update({
|
||||
where: { id: body.productGroupId },
|
||||
data: { status: Status.ACTIVE },
|
||||
});
|
||||
}
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue