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",
|
null as "remark",
|
||||||
"status",
|
"status",
|
||||||
"statusOrder",
|
"statusOrder",
|
||||||
null as "productTypeId",
|
"productTypeId",
|
||||||
"createdByUserId",
|
"createdByUserId",
|
||||||
"createdAt",
|
"createdAt",
|
||||||
"updatedByUserId",
|
"updatedByUserId",
|
||||||
|
|
@ -61,7 +61,7 @@ export class ProductServiceController extends Controller {
|
||||||
if (query) or.push(Prisma.sql`"name" LIKE ${`%${query}%`}`);
|
if (query) or.push(Prisma.sql`"name" LIKE ${`%${query}%`}`);
|
||||||
if (status) and.push(Prisma.sql`"status" = ${status}::"Status"`);
|
if (status) and.push(Prisma.sql`"status" = ${status}::"Status"`);
|
||||||
if (productTypeId) {
|
if (productTypeId) {
|
||||||
and.push(Prisma.sql`("productTypeId" = ${productTypeId} OR ("type" = 'service'))`);
|
and.push(Prisma.sql`("productTypeId" = ${productTypeId})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const where = Prisma.sql`
|
const where = Prisma.sql`
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ type ServiceCreate = {
|
||||||
productId: string[];
|
productId: string[];
|
||||||
attributes?: { [key: string]: any };
|
attributes?: { [key: string]: any };
|
||||||
}[];
|
}[];
|
||||||
|
productTypeId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ServiceUpdate = {
|
type ServiceUpdate = {
|
||||||
|
|
@ -53,6 +54,7 @@ type ServiceUpdate = {
|
||||||
productId: string[];
|
productId: string[];
|
||||||
attributes?: { [key: string]: any };
|
attributes?: { [key: string]: any };
|
||||||
}[];
|
}[];
|
||||||
|
productTypeId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function imageLocation(id: string) {
|
function imageLocation(id: string) {
|
||||||
|
|
@ -198,7 +200,23 @@ export class ServiceController extends Controller {
|
||||||
@Post()
|
@Post()
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
async createService(@Request() req: RequestWithUser, @Body() body: ServiceCreate) {
|
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(
|
const record = await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
|
|
@ -250,6 +268,7 @@ export class ServiceController extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...payload,
|
...payload,
|
||||||
|
productTypeId,
|
||||||
statusOrder: +(body.status === "INACTIVE"),
|
statusOrder: +(body.status === "INACTIVE"),
|
||||||
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||||
work: { connect: workList.map((v) => ({ id: v.id })) },
|
work: { connect: workList.map((v) => ({ id: v.id })) },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue