feat: add product type to service
This commit is contained in:
parent
648f101fd7
commit
68bed31800
2 changed files with 22 additions and 3 deletions
|
|
@ -46,7 +46,7 @@ export class ProductServiceController extends Controller {
|
|||
null as "remark",
|
||||
"status",
|
||||
"statusOrder",
|
||||
null as "productTypeId",
|
||||
"productTypeId",
|
||||
"createdByUserId",
|
||||
"createdAt",
|
||||
"updatedByUserId",
|
||||
|
|
@ -61,7 +61,7 @@ export class ProductServiceController extends Controller {
|
|||
if (query) or.push(Prisma.sql`"name" LIKE ${`%${query}%`}`);
|
||||
if (status) and.push(Prisma.sql`"status" = ${status}::"Status"`);
|
||||
if (productTypeId) {
|
||||
and.push(Prisma.sql`("productTypeId" = ${productTypeId} OR ("type" = 'service'))`);
|
||||
and.push(Prisma.sql`("productTypeId" = ${productTypeId})`);
|
||||
}
|
||||
|
||||
const where = Prisma.sql`
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ type ServiceCreate = {
|
|||
productId: string[];
|
||||
attributes?: { [key: string]: any };
|
||||
}[];
|
||||
productTypeId: string;
|
||||
};
|
||||
|
||||
type ServiceUpdate = {
|
||||
|
|
@ -53,6 +54,7 @@ type ServiceUpdate = {
|
|||
productId: string[];
|
||||
attributes?: { [key: string]: any };
|
||||
}[];
|
||||
productTypeId?: string;
|
||||
};
|
||||
|
||||
function imageLocation(id: string) {
|
||||
|
|
@ -198,7 +200,23 @@ export class ServiceController extends Controller {
|
|||
@Post()
|
||||
@Security("keycloak")
|
||||
async createService(@Request() req: RequestWithUser, @Body() body: ServiceCreate) {
|
||||
const { work, ...payload } = body;
|
||||
const { work, productTypeId, ...payload } = body;
|
||||
|
||||
const productType = await prisma.productType.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: body.productTypeId },
|
||||
});
|
||||
|
||||
if (!productType) {
|
||||
throw new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"Product Type cannot be found.",
|
||||
"relationProductTypeNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
const record = await prisma.$transaction(
|
||||
async (tx) => {
|
||||
|
|
@ -250,6 +268,7 @@ export class ServiceController extends Controller {
|
|||
},
|
||||
data: {
|
||||
...payload,
|
||||
productTypeId,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||
work: { connect: workList.map((v) => ({ id: v.id })) },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue