Merge branch 'develop'
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s
This commit is contained in:
commit
125f708ac6
5 changed files with 205 additions and 2 deletions
|
|
@ -4,7 +4,8 @@ ENV PNPM_HOME="/pnpm"
|
|||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
|
||||
RUN corepack enable
|
||||
RUN apt-get update && apt-get install -y openssl
|
||||
RUN apt-get update && apt-get install -y openssl fontconfig
|
||||
RUN fc-cache -f -v
|
||||
RUN pnpm i -g prisma prisma-kysely
|
||||
|
||||
WORKDIR /app
|
||||
|
|
|
|||
3
prisma/migrations/20250513084929_add/migration.sql
Normal file
3
prisma/migrations/20250513084929_add/migration.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "QuotationWorker" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||
|
|
@ -1410,6 +1410,9 @@ model QuotationWorker {
|
|||
employeeId String
|
||||
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
|
||||
quotationId String
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
}
|
||||
|
||||
model QuotationProductServiceList {
|
||||
|
|
|
|||
|
|
@ -606,7 +606,28 @@ export class TaskActionController extends Controller {
|
|||
return await prisma.$transaction(async (tx) => {
|
||||
const promises = body.map(async (v) => {
|
||||
const record = await tx.task.findFirst({
|
||||
include: { requestWorkStep: true },
|
||||
include: {
|
||||
requestWorkStep: {
|
||||
include: {
|
||||
requestWork: {
|
||||
include: {
|
||||
request: {
|
||||
include: {
|
||||
quotation: true,
|
||||
employee: true,
|
||||
},
|
||||
},
|
||||
productService: {
|
||||
include: {
|
||||
product: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
taskOrder: true,
|
||||
},
|
||||
where: {
|
||||
step: v.step,
|
||||
requestWorkId: v.requestWorkId,
|
||||
|
|
@ -624,6 +645,24 @@ export class TaskActionController extends Controller {
|
|||
data: { userTaskStatus: UserTaskStatus.Restart },
|
||||
});
|
||||
}
|
||||
|
||||
if (v.taskStatus === TaskStatus.Failed) {
|
||||
const taskCode = record.taskOrder.code;
|
||||
const taskName = record.taskOrder.taskName;
|
||||
const productCode = record.requestWorkStep.requestWork.productService.product.code;
|
||||
const productName = record.requestWorkStep.requestWork.productService.product.name;
|
||||
const employeeName = `${record.requestWorkStep.requestWork.request.employee.namePrefix}.${record.requestWorkStep.requestWork.request.employee.firstNameEN} ${record.requestWorkStep.requestWork.request.employee.lastNameEN}`;
|
||||
|
||||
await tx.notification.create({
|
||||
data: {
|
||||
title: "ใบรายการคำขอที่จัดการเกิดปัญหา / Task Failed",
|
||||
detail: `ใบรายการคำขอรหัส ${taskCode}: ${taskName} รหัสสินค้า ${productCode}: ${productName} ของลูกจ้าง ${employeeName} เกิดข้อผิดพลาด`,
|
||||
groupReceiver: { create: { name: "document_checker" } },
|
||||
registeredBranchId: record.taskOrder.registeredBranchId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return await tx.task.update({
|
||||
where: { id: record.id },
|
||||
data: {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import dayjs from "dayjs";
|
|||
import { CronJob } from "cron";
|
||||
|
||||
import prisma from "../db";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
const jobs = [
|
||||
CronJob.from({
|
||||
|
|
@ -38,6 +39,162 @@ const jobs = [
|
|||
.catch((e) => console.error("[ERR]: Update expired quotation status, FAILED.", e));
|
||||
},
|
||||
}),
|
||||
CronJob.from({
|
||||
cronTime: "0 0 0 * * *",
|
||||
runOnInit: true,
|
||||
onTick: async () => {
|
||||
const employeeExpireData = await prisma.employee.findMany({
|
||||
include: {
|
||||
employeePassport: {
|
||||
orderBy: {
|
||||
expireDate: "desc",
|
||||
},
|
||||
take: 1,
|
||||
},
|
||||
customerBranch: {
|
||||
include: {
|
||||
customer: true,
|
||||
},
|
||||
},
|
||||
quotationWorker: {
|
||||
include: {
|
||||
quotation: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
take: 1,
|
||||
},
|
||||
},
|
||||
where: {
|
||||
employeePassport: {
|
||||
some: {
|
||||
expireDate: dayjs().add(90, "day").toDate(),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
employeeExpireData.map(async (record) => {
|
||||
const fullName = `${record.namePrefix}.${record.firstNameEN} ${record.lastNameEN}`;
|
||||
const expireDate = `${dayjs(record.employeePassport[0].expireDate).format("DD/MM")}/${dayjs(record.employeePassport[0].expireDate).year() + 543}`;
|
||||
const textDetail = `ลูกจ้างรหัส / code : ${record.code} ชื่อ : ${fullName} หนังสือเดินทางจะหมดอายุในวันที่ ${expireDate}`;
|
||||
const duplicateText = await prisma.notification.findFirst({
|
||||
where: {
|
||||
detail: textDetail,
|
||||
},
|
||||
});
|
||||
|
||||
const dataNotification: Prisma.NotificationCreateArgs["data"] = {
|
||||
title: "หนังสือเดินทางลูกจ้างหมดอายุ / Employee Passport Expire",
|
||||
detail: textDetail,
|
||||
};
|
||||
|
||||
if (record.quotationWorker && record.quotationWorker.length > 0) {
|
||||
dataNotification.receiverId = record.quotationWorker[0].quotation.updatedByUserId;
|
||||
dataNotification.registeredBranchId =
|
||||
record.quotationWorker[0].quotation.registeredBranchId;
|
||||
} else {
|
||||
(dataNotification.groupReceiver = {
|
||||
create: [{ name: "sale" }, { name: "head_of_sale" }],
|
||||
}),
|
||||
(dataNotification.registeredBranchId =
|
||||
record.customerBranch.customer.registeredBranchId);
|
||||
}
|
||||
|
||||
if (!duplicateText) {
|
||||
await prisma.notification
|
||||
.create({
|
||||
data: dataNotification,
|
||||
})
|
||||
.then(() => console.log("[INFO]: Create notification employee passport expired, OK."))
|
||||
.catch((e) =>
|
||||
console.error("[ERR]: Create notification employee passport expired, FAILED.", e),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
}),
|
||||
CronJob.from({
|
||||
cronTime: "0 0 0 * * *",
|
||||
runOnInit: true,
|
||||
onTick: async () => {
|
||||
const employeeVisaData = await prisma.employee.findMany({
|
||||
include: {
|
||||
employeeVisa: {
|
||||
orderBy: {
|
||||
expireDate: "desc",
|
||||
},
|
||||
take: 1,
|
||||
},
|
||||
customerBranch: {
|
||||
include: {
|
||||
customer: true,
|
||||
},
|
||||
},
|
||||
quotationWorker: {
|
||||
include: {
|
||||
quotation: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
take: 1,
|
||||
},
|
||||
},
|
||||
where: {
|
||||
employeeVisa: {
|
||||
some: {
|
||||
expireDate: dayjs().add(90, "day").toDate(),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
employeeVisaData.map(async (record) => {
|
||||
const fullName = `${record.namePrefix}.${record.firstNameEN} ${record.lastNameEN}`;
|
||||
const expireDate = `${dayjs(record.employeeVisa[0].expireDate).format("DD/MM")}/${dayjs(record.employeeVisa[0].expireDate).year() + 543}`;
|
||||
const textDetail = `ลูกจ้างรหัส / code : ${record.code} ชื่อ : ${fullName} ข้อมูลการตรวจลงตราจะหมดอายุในวันที่ ${expireDate}`;
|
||||
const duplicateText = await prisma.notification.findFirst({
|
||||
where: {
|
||||
detail: textDetail,
|
||||
},
|
||||
});
|
||||
|
||||
const dataNotification: Prisma.NotificationCreateArgs["data"] = {
|
||||
title: "ข้อมูลการตรวจลงตราลูกจ้างหมดอายุ / Employee Visa Expire",
|
||||
detail: textDetail,
|
||||
};
|
||||
|
||||
if (record.quotationWorker && record.quotationWorker.length > 0) {
|
||||
dataNotification.receiverId = record.quotationWorker[0].quotation.updatedByUserId;
|
||||
dataNotification.registeredBranchId =
|
||||
record.quotationWorker[0].quotation.registeredBranchId;
|
||||
} else {
|
||||
(dataNotification.groupReceiver = {
|
||||
create: [{ name: "sale" }, { name: "head_of_sale" }],
|
||||
}),
|
||||
(dataNotification.registeredBranchId =
|
||||
record.customerBranch.customer.registeredBranchId);
|
||||
}
|
||||
|
||||
if (!duplicateText) {
|
||||
await prisma.notification
|
||||
.create({
|
||||
data: dataNotification,
|
||||
})
|
||||
.then(() => console.log("[INFO]: Create notification employee visa expired, OK."))
|
||||
.catch((e) =>
|
||||
console.error("[ERR]: Create notification employee visa expired, FAILED.", e),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
export function initSchedule() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue