Merge branch 'feat/product-n-service' into dev
This commit is contained in:
commit
68af0eb821
6 changed files with 350 additions and 43 deletions
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `serviceId` on the `Work` table. All the data in the column will be lost.
|
||||||
|
- Added the required column `order` to the `WorkProduct` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Work" DROP CONSTRAINT "Work_serviceId_fkey";
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Work" DROP COLUMN "serviceId";
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "WorkProduct" ADD COLUMN "order" INTEGER NOT NULL;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "WorkService" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"order" INTEGER NOT NULL,
|
||||||
|
"workId" TEXT NOT NULL,
|
||||||
|
"serviceId" TEXT NOT NULL,
|
||||||
|
"createdBy" TEXT,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updateBy" TEXT,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"productId" TEXT,
|
||||||
|
|
||||||
|
CONSTRAINT "WorkService_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "WorkService" ADD CONSTRAINT "WorkService_workId_fkey" FOREIGN KEY ("workId") REFERENCES "Work"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "WorkService" ADD CONSTRAINT "WorkService_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "Service"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `order` on the `Work` table. All the data in the column will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Work" DROP COLUMN "order";
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- The primary key for the `WorkProduct` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||||
|
- You are about to drop the column `id` on the `WorkProduct` table. All the data in the column will be lost.
|
||||||
|
- The primary key for the `WorkService` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||||
|
- You are about to drop the column `id` on the `WorkService` table. All the data in the column will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "WorkProduct" DROP CONSTRAINT "WorkProduct_pkey",
|
||||||
|
DROP COLUMN "id",
|
||||||
|
ADD CONSTRAINT "WorkProduct_pkey" PRIMARY KEY ("workId", "productId");
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "WorkService" DROP CONSTRAINT "WorkService_pkey",
|
||||||
|
DROP COLUMN "id",
|
||||||
|
ADD CONSTRAINT "WorkService_pkey" PRIMARY KEY ("workId", "serviceId");
|
||||||
|
|
@ -547,30 +547,44 @@ model Service {
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updateBy String?
|
updateBy String?
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
work Work[]
|
|
||||||
|
workOnService WorkService[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model Work {
|
model Work {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
|
|
||||||
order Int
|
name String
|
||||||
name String
|
|
||||||
|
|
||||||
service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
|
|
||||||
serviceId String
|
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updateBy String?
|
updateBy String?
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
WorkProduct WorkProduct[]
|
|
||||||
|
productOnWork WorkProduct[]
|
||||||
|
serviceOnWork WorkService[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model WorkService {
|
||||||
|
order Int
|
||||||
|
work Work @relation(fields: [workId], references: [id], onDelete: Cascade)
|
||||||
|
workId String
|
||||||
|
service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
|
||||||
|
serviceId String
|
||||||
|
|
||||||
|
createdBy String?
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updateBy String?
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
productId String?
|
||||||
|
|
||||||
|
@@id([workId, serviceId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model WorkProduct {
|
model WorkProduct {
|
||||||
id String @id @default(uuid())
|
order Int
|
||||||
|
|
||||||
work Work @relation(fields: [workId], references: [id], onDelete: Cascade)
|
work Work @relation(fields: [workId], references: [id], onDelete: Cascade)
|
||||||
workId String
|
workId String
|
||||||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||||||
|
|
@ -580,6 +594,8 @@ model WorkProduct {
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updateBy String?
|
updateBy String?
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
|
||||||
|
@@id([workId, productId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model ProductGroup {
|
model ProductGroup {
|
||||||
|
|
|
||||||
|
|
@ -27,19 +27,20 @@ if (!process.env.MINIO_BUCKET) {
|
||||||
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
||||||
|
|
||||||
type ServiceCreate = {
|
type ServiceCreate = {
|
||||||
code: string;
|
code: "MOU" | "mou";
|
||||||
name: string;
|
name: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
|
workId: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type ServiceUpdate = {
|
type ServiceUpdate = {
|
||||||
code: string;
|
|
||||||
name: string;
|
name: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
|
workId: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
function imageLocation(id: string) {
|
function imageLocation(id: string) {
|
||||||
return `service/img-${id}`;
|
return `service/${id}/product-image`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Route("api/v1/service")
|
@Route("api/v1/service")
|
||||||
|
|
@ -63,6 +64,13 @@ export class ServiceController extends Controller {
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
prisma.service.findMany({
|
prisma.service.findMany({
|
||||||
|
include: {
|
||||||
|
workOnService: {
|
||||||
|
include: {
|
||||||
|
service: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
orderBy: { createdAt: "asc" },
|
orderBy: { createdAt: "asc" },
|
||||||
where,
|
where,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
|
|
@ -87,6 +95,23 @@ export class ServiceController extends Controller {
|
||||||
@Get("{serviceId}")
|
@Get("{serviceId}")
|
||||||
async getServiceById(@Path() serviceId: string) {
|
async getServiceById(@Path() serviceId: string) {
|
||||||
const record = await prisma.service.findFirst({
|
const record = await prisma.service.findFirst({
|
||||||
|
include: {
|
||||||
|
workOnService: {
|
||||||
|
orderBy: { order: "asc" },
|
||||||
|
include: {
|
||||||
|
work: {
|
||||||
|
include: {
|
||||||
|
productOnWork: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
orderBy: { order: "asc" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
where: { id: serviceId },
|
where: { id: serviceId },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -94,7 +119,7 @@ export class ServiceController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "data_not_found");
|
throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "data_not_found");
|
||||||
|
|
||||||
return Object.assign(record, {
|
return Object.assign(record, {
|
||||||
imageUrl: await minio.presignedGetObject(MINIO_BUCKET, `service/img-${record.id}`, 60 * 60),
|
imageUrl: await minio.presignedGetObject(MINIO_BUCKET, imageLocation(record.id), 60 * 60),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,27 +129,96 @@ export class ServiceController extends Controller {
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
) {
|
) {
|
||||||
|
const where = {
|
||||||
|
serviceOnWork: {
|
||||||
|
some: { serviceId },
|
||||||
|
},
|
||||||
|
} satisfies Prisma.WorkWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
prisma.work.findMany({
|
prisma.work.findMany({
|
||||||
where: { serviceId },
|
include: {
|
||||||
|
productOnWork: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
where,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
skip: (page - 1) * pageSize,
|
skip: (page - 1) * pageSize,
|
||||||
}),
|
}),
|
||||||
prisma.work.count({ where: { serviceId } }),
|
prisma.work.count({ where }),
|
||||||
]);
|
]);
|
||||||
return { result, page, pageSize, total };
|
return { result, page, pageSize, total };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async createService(@Request() req: RequestWithUser, @Body() body: ServiceCreate) {
|
async createService(@Request() req: RequestWithUser, @Body() body: ServiceCreate) {
|
||||||
const record = await prisma.service.create({
|
const { workId, ...payload } = body;
|
||||||
data: {
|
|
||||||
...body,
|
const workList = await prisma.work.findMany({
|
||||||
createdBy: req.user.name,
|
where: { id: { in: workId } },
|
||||||
updateBy: req.user.name,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (workList.length !== workList.length) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"Some product not found.",
|
||||||
|
"missing_or_invalid_parameter",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const record = await prisma.$transaction(
|
||||||
|
async (tx) => {
|
||||||
|
const last = await tx.runningNo.upsert({
|
||||||
|
where: {
|
||||||
|
key: `SERVICE_${body.code.toLocaleUpperCase()}`,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
key: `SERVICE_${body.code.toLocaleUpperCase()}`,
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
update: { value: { increment: 1 } },
|
||||||
|
});
|
||||||
|
|
||||||
|
return tx.service.create({
|
||||||
|
include: {
|
||||||
|
workOnService: {
|
||||||
|
orderBy: { order: "asc" },
|
||||||
|
include: {
|
||||||
|
work: {
|
||||||
|
include: {
|
||||||
|
productOnWork: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
orderBy: { order: "asc" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
...payload,
|
||||||
|
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||||
|
workOnService: {
|
||||||
|
createMany: {
|
||||||
|
data: workId.map((v, i) => ({
|
||||||
|
order: i + 1,
|
||||||
|
workId: v,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
createdBy: req.user.name,
|
||||||
|
updateBy: req.user.name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||||
|
);
|
||||||
|
|
||||||
this.setStatus(HttpStatus.CREATED);
|
this.setStatus(HttpStatus.CREATED);
|
||||||
|
|
||||||
return Object.assign(record, {
|
return Object.assign(record, {
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,13 @@ import HttpError from "../../interfaces/http-error";
|
||||||
import HttpStatus from "../../interfaces/http-status";
|
import HttpStatus from "../../interfaces/http-status";
|
||||||
|
|
||||||
type WorkCreate = {
|
type WorkCreate = {
|
||||||
order: number;
|
|
||||||
name: string;
|
name: string;
|
||||||
serviceId: string;
|
productId: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type WorkUpdate = {
|
type WorkUpdate = {
|
||||||
order?: number;
|
|
||||||
name?: string;
|
name?: string;
|
||||||
serviceId?: string;
|
productId?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@Route("api/v1/work")
|
@Route("api/v1/work")
|
||||||
|
|
@ -47,8 +45,17 @@ export class WorkController extends Controller {
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
prisma.work.findMany({
|
prisma.work.findMany({
|
||||||
|
include: {
|
||||||
|
productOnWork: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
order: "asc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
orderBy: { createdAt: "asc" },
|
orderBy: { createdAt: "asc" },
|
||||||
include: { service: true },
|
|
||||||
where,
|
where,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
skip: (page - 1) * pageSize,
|
skip: (page - 1) * pageSize,
|
||||||
|
|
@ -62,7 +69,6 @@ export class WorkController extends Controller {
|
||||||
@Get("{workId}")
|
@Get("{workId}")
|
||||||
async getWorkById(@Path() workId: string) {
|
async getWorkById(@Path() workId: string) {
|
||||||
const record = await prisma.work.findFirst({
|
const record = await prisma.work.findFirst({
|
||||||
include: { service: true },
|
|
||||||
where: { id: workId },
|
where: { id: workId },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -71,6 +77,7 @@ export class WorkController extends Controller {
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("{workId}/product")
|
@Get("{workId}/product")
|
||||||
async getProductOfWork(
|
async getProductOfWork(
|
||||||
@Path() workId: string,
|
@Path() workId: string,
|
||||||
|
|
@ -81,9 +88,7 @@ export class WorkController extends Controller {
|
||||||
const where = {
|
const where = {
|
||||||
AND: [
|
AND: [
|
||||||
{
|
{
|
||||||
workProduct: {
|
workProduct: { some: { workId } },
|
||||||
some: { workId },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
OR: [{ name: { contains: query } }],
|
OR: [{ name: { contains: query } }],
|
||||||
|
|
@ -107,28 +112,85 @@ export class WorkController extends Controller {
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async createWork(@Request() req: RequestWithUser, @Body() body: WorkCreate) {
|
async createWork(@Request() req: RequestWithUser, @Body() body: WorkCreate) {
|
||||||
const service = await prisma.service.findFirst({
|
const { productId, ...payload } = body;
|
||||||
where: { id: body.serviceId },
|
|
||||||
|
const exist = await prisma.work.findFirst({
|
||||||
|
include: {
|
||||||
|
productOnWork: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
productOnWork: {
|
||||||
|
every: {
|
||||||
|
productId: { in: productId },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NOT: {
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
productOnWork: {
|
||||||
|
some: {
|
||||||
|
productId: { notIn: productId },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
productOnWork: {
|
||||||
|
none: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!service) {
|
if (exist) return exist;
|
||||||
|
|
||||||
|
const productList = await prisma.product.findMany({
|
||||||
|
where: { id: { in: productId } },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (productList.length !== productId.length) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
"Service not found.",
|
"Some product not found.",
|
||||||
"missing_or_invalid_parameter",
|
"missing_or_invalid_parameter",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const record = await prisma.work.create({
|
const record = await prisma.work.create({
|
||||||
|
include: {
|
||||||
|
productOnWork: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
order: "asc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...payload,
|
||||||
|
productOnWork: {
|
||||||
|
createMany: {
|
||||||
|
data: productId.map((v, i) => ({
|
||||||
|
order: i + 1,
|
||||||
|
productId: v,
|
||||||
|
createdBy: req.user.name,
|
||||||
|
updateBy: req.user.name,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
createdBy: req.user.name,
|
createdBy: req.user.name,
|
||||||
updateBy: req.user.name,
|
updateBy: req.user.name,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.service.updateMany({
|
await prisma.product.updateMany({
|
||||||
where: { id: service.id },
|
where: { id: { in: body.productId }, status: Status.CREATED },
|
||||||
data: { status: Status.ACTIVE },
|
data: { status: Status.ACTIVE },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -138,18 +200,91 @@ export class WorkController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("{workId}")
|
@Put("{workId}")
|
||||||
async editService(
|
async editWork(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Body() body: WorkUpdate,
|
@Body() body: WorkUpdate,
|
||||||
@Path() workId: string,
|
@Path() workId: string,
|
||||||
) {
|
) {
|
||||||
|
const { productId, ...payload } = body;
|
||||||
|
|
||||||
if (!(await prisma.work.findUnique({ where: { id: workId } }))) {
|
if (!(await prisma.work.findUnique({ where: { id: workId } }))) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "data_not_found");
|
throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "data_not_found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const exist = await prisma.work.findFirst({
|
||||||
|
include: {
|
||||||
|
productOnWork: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
productOnWork: {
|
||||||
|
every: {
|
||||||
|
productId: { in: productId },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NOT: {
|
||||||
|
OR: [
|
||||||
|
{ id: workId },
|
||||||
|
{
|
||||||
|
productOnWork: {
|
||||||
|
some: {
|
||||||
|
productId: { notIn: productId },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
productOnWork: {
|
||||||
|
none: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (exist) return exist;
|
||||||
|
|
||||||
const record = await prisma.work.update({
|
const record = await prisma.work.update({
|
||||||
data: { ...body, updateBy: req.user.name },
|
include: {
|
||||||
|
productOnWork: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
order: "asc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
where: { id: workId },
|
where: { id: workId },
|
||||||
|
data: {
|
||||||
|
...payload,
|
||||||
|
productOnWork: productId
|
||||||
|
? {
|
||||||
|
deleteMany: {
|
||||||
|
productId: { notIn: productId },
|
||||||
|
},
|
||||||
|
upsert: productId.map((v, i) => ({
|
||||||
|
where: {
|
||||||
|
workId_productId: {
|
||||||
|
workId,
|
||||||
|
productId: v,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: { order: i + 1 },
|
||||||
|
create: {
|
||||||
|
order: i + 1,
|
||||||
|
productId: v,
|
||||||
|
createdBy: req.user.name,
|
||||||
|
updateBy: req.user.name,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
updateBy: req.user.name,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue