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;
|
name: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
remark: string;
|
remark: string;
|
||||||
|
status?: Status;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ProductGroupUpdate = {
|
type ProductGroupUpdate = {
|
||||||
name?: string;
|
name?: string;
|
||||||
detail?: string;
|
detail?: string;
|
||||||
remark?: string;
|
remark?: string;
|
||||||
|
status?: "ACTIVE" | "INACTIVE";
|
||||||
};
|
};
|
||||||
|
|
||||||
@Route("api/v1/product-group")
|
@Route("api/v1/product-group")
|
||||||
|
|
@ -66,7 +68,11 @@ export class ProductGroup extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!record)
|
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;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +116,11 @@ export class ProductGroup extends Controller {
|
||||||
@Path() groupId: string,
|
@Path() groupId: string,
|
||||||
) {
|
) {
|
||||||
if (!(await prisma.productGroup.findUnique({ where: { id: groupId } }))) {
|
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({
|
const record = await prisma.productGroup.update({
|
||||||
|
|
@ -126,7 +136,11 @@ export class ProductGroup extends Controller {
|
||||||
const record = await prisma.productGroup.findFirst({ where: { id: groupId } });
|
const record = await prisma.productGroup.findFirst({ where: { id: groupId } });
|
||||||
|
|
||||||
if (!record) {
|
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) {
|
if (record.status !== Status.CREATED) {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ type ProductTypeCreate = {
|
||||||
name: string;
|
name: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
remark: string;
|
remark: string;
|
||||||
|
status?: Status;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ProductTypeUpdate = {
|
type ProductTypeUpdate = {
|
||||||
|
|
@ -31,6 +32,7 @@ type ProductTypeUpdate = {
|
||||||
name?: string;
|
name?: string;
|
||||||
detail?: string;
|
detail?: string;
|
||||||
remark?: string;
|
remark?: string;
|
||||||
|
status?: "ACTIVE" | "INACTIVE";
|
||||||
};
|
};
|
||||||
|
|
||||||
@Route("api/v1/product-type")
|
@Route("api/v1/product-type")
|
||||||
|
|
@ -139,10 +141,10 @@ export class ProductType extends Controller {
|
||||||
@Body() body: ProductTypeUpdate,
|
@Body() body: ProductTypeUpdate,
|
||||||
@Path() typeId: string,
|
@Path() typeId: string,
|
||||||
) {
|
) {
|
||||||
if (
|
const productGroup = await prisma.productGroup.findFirst({
|
||||||
body.productGroupId &&
|
where: { id: body.productGroupId },
|
||||||
!(await prisma.productGroup.findFirst({ where: { id: body.productGroupId } }))
|
});
|
||||||
) {
|
if (body.productGroupId && !productGroup) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
"Product group cannot be found.",
|
"Product group cannot be found.",
|
||||||
|
|
@ -163,6 +165,13 @@ export class ProductType extends Controller {
|
||||||
where: { id: typeId },
|
where: { id: typeId },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (productGroup?.status === "CREATED") {
|
||||||
|
await prisma.productGroup.update({
|
||||||
|
where: { id: body.productGroupId },
|
||||||
|
data: { status: Status.ACTIVE },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue