add notification expireDate passport, visa
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 6s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 6s
This commit is contained in:
parent
0affb5337f
commit
897ef335b4
4 changed files with 149 additions and 1 deletions
|
|
@ -38,6 +38,120 @@ 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
employeePassport: {
|
||||
some: {
|
||||
expireDate: dayjs().add(90, "day").toDate(),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await 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,
|
||||
},
|
||||
});
|
||||
|
||||
if (!duplicateText) {
|
||||
await prisma.notification
|
||||
.create({
|
||||
data: {
|
||||
title: "หนังสือเดินทางลูกจ้างหมดอายุ / Employee Passport Expire",
|
||||
detail: textDetail,
|
||||
groupReceiver: {
|
||||
create: [{ name: "sale" }, { name: "head_of_sale" }],
|
||||
},
|
||||
registeredBranchId: record.customerBranch.customer.registeredBranchId,
|
||||
},
|
||||
})
|
||||
.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,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
employeeVisa: {
|
||||
some: {
|
||||
expireDate: dayjs().add(90, "day").toDate(),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await 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,
|
||||
},
|
||||
});
|
||||
|
||||
if (!duplicateText) {
|
||||
await prisma.notification
|
||||
.create({
|
||||
data: {
|
||||
title: "ข้อมูลการตรวจลงตราลูกจ้างหมดอายุ / Employee Visa Expire",
|
||||
detail: textDetail,
|
||||
groupReceiver: {
|
||||
create: [{ name: "sale" }, { name: "head_of_sale" }],
|
||||
},
|
||||
registeredBranchId: record.customerBranch.customer.registeredBranchId,
|
||||
},
|
||||
})
|
||||
.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