diff --git a/src/controllers/09-web-hook-controller.ts b/src/controllers/09-web-hook-controller.ts index d55126a..14b7015 100644 --- a/src/controllers/09-web-hook-controller.ts +++ b/src/controllers/09-web-hook-controller.ts @@ -68,37 +68,37 @@ export class WebHookController extends Controller { const userIdLine = payload.events[0]?.source?.userId; const dataNow = dayjs().tz("Asia/Bangkok").startOf("day"); - // const dataUser = await prisma.customerBranch.findFirst({ - // where:{ - // userId:userIdLine - // } - // }) + if (payload?.events[0]?.message) { + const message = payload.events[0].message.text; - const dataEmployee = await prisma.employeePassport.findMany({ - select: { - firstName: true, - firstNameEN: true, - lastName: true, - lastNameEN: true, - employeeId: true, - expireDate: true, - employee: { + if (message === "เมนูหลัก > ข้อความ") { + const dataEmployee = await prisma.employeePassport.findMany({ select: { firstName: true, + firstNameEN: true, lastName: true, - customerBranch: { + lastNameEN: true, + employeeId: true, + expireDate: true, + employee: { select: { firstName: true, - firstNameEN: true, lastName: true, - lastNameEN: true, - customerName: true, - customer: { + customerBranch: { select: { - customerType: true, - registeredBranch: { + firstName: true, + firstNameEN: true, + lastName: true, + lastNameEN: true, + customerName: true, + customer: { select: { - telephoneNo: true, + customerType: true, + registeredBranch: { + select: { + telephoneNo: true, + }, + }, }, }, }, @@ -106,22 +106,28 @@ export class WebHookController extends Controller { }, }, }, - }, - }, - where: { - expireDate: { - lt: dataNow.add(30, "day").toDate(), - }, - }, - orderBy: { - expireDate: "asc", - }, - }); + where: { + employee: { + customerBranch: { + OR: [ + { userId: userIdLine }, + { + customer: { + branch: { some: { userId: userIdLine } }, + }, + }, + ], + }, + }, + expireDate: { + lt: dataNow.add(30, "day").toDate(), + }, + }, + orderBy: { + expireDate: "asc", + }, + }); - if (payload?.events[0]?.message) { - const message = payload.events[0].message.text; - - if (message === "เมนูหลัก > ข้อความ") { const dataUser = userIdLine; const textHead = "JWS ALERT:"; let textData = "";