diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 79a8d2fe..27778027 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1022,6 +1022,7 @@ export class CommandController extends Controller { body: `${command.issue}`, receiverUserIds: profiles, payload: "", //แนบไฟล์ + notiLink: "", //แนบไฟล์ isSendMail: true, isSendInbox: true, isSendNotification: true, diff --git a/src/entities/Command.ts b/src/entities/Command.ts index c33cce38..eda2d20d 100644 --- a/src/entities/Command.ts +++ b/src/entities/Command.ts @@ -5,6 +5,7 @@ import { CommandSend } from "./CommandSend"; import { CommandSalary } from "./CommandSalary"; import { CommandRecive } from "./CommandRecive"; import { ProfileSalary } from "./ProfileSalary"; +import { ProfileSalaryHistory } from "./ProfileSalaryHistory"; @Entity("command") export class Command extends EntityBase { @@ -155,6 +156,9 @@ export class Command extends EntityBase { @OneToMany(() => ProfileSalary, (profileSalary) => profileSalary.command) profileSalarys: ProfileSalary[]; + + @OneToMany(() => ProfileSalaryHistory, (profileSalaryHistory) => profileSalaryHistory.command) + profileSalaryHistorys: ProfileSalaryHistory[]; } export class CreateCommand { diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index f2a56217..9c02c4c7 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -194,6 +194,7 @@ export class CreateProfileSalary { positionType: string | null; positionLevel: string | null; refCommandNo: string | null; + commandId: string | null; // commandType?: string | null; templateDoc: string | null; } diff --git a/src/entities/ProfileSalaryHistory.ts b/src/entities/ProfileSalaryHistory.ts index c0af4fbd..f8f9193d 100644 --- a/src/entities/ProfileSalaryHistory.ts +++ b/src/entities/ProfileSalaryHistory.ts @@ -1,6 +1,7 @@ import { Entity, Column, JoinColumn, ManyToOne, Double } from "typeorm"; import { EntityBase } from "./base/Base"; import { ProfileSalary } from "./ProfileSalary"; +import { Command } from "./Command"; @Entity("profileSalaryHistory") export class ProfileSalaryHistory extends EntityBase { @@ -127,6 +128,18 @@ export class ProfileSalaryHistory extends EntityBase { }) order: number; + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง command", + default: null, + }) + commandId: string; + + @ManyToOne(() => Command, (command) => command.profileSalaryHistorys) + @JoinColumn({ name: "commandId" }) + command: Command; + @ManyToOne(() => ProfileSalary, (profileSalary) => profileSalary.profileSalaryHistories) @JoinColumn({ name: "profileSalaryId" }) histories: ProfileSalary; diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index eb482fd6..7d53079c 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -9,7 +9,8 @@ import { RequestWithUser } from "../middlewares/user"; export let sendToQueue: (payload: any) => void; -export async function init() { //----> (1) Producer +export async function init() { + //----> (1) Producer if (!process.env.AMQ_URL || !process.env.AMQ_QUEUE) return; const { AMQ_URL: url, AMQ_QUEUE: queue } = process.env; //----> (1.2) get url and queue from .env @@ -21,7 +22,8 @@ export async function init() { //----> (1) Producer channel.assertQueue(queue, { durable: true }); //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ) channel.prefetch(1); - sendToQueue = (payload: any, persistent = true) => { //----> (2) sendQueue To RabbitMQ and set persistent (if "true" redo the failed queue when server run again) + sendToQueue = (payload: any, persistent = true) => { + //----> (2) sendQueue To RabbitMQ and set persistent (if "true" redo the failed queue when server run again) channel.sendToQueue(queue, Buffer.from(JSON.stringify(payload)), { persistent, }); @@ -52,7 +54,8 @@ function createConsumer( //----> consumer ); } -async function handler(msg: amqp.ConsumeMessage): Promise { //----> condition before process consumer +async function handler(msg: amqp.ConsumeMessage): Promise { + //----> condition before process consumer const repo = AppDataSource.getRepository(Command); const { data, token, user } = JSON.parse(msg.content.toString()); @@ -82,6 +85,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise { //----> con commandAffectDate: command.commandAffectDate, commandNo: command.commandNo, commandYear: command.commandYear, + commandId: command.id, templateDoc: command.positionDetail, amount: x.amount, positionSalaryAmount: x.positionSalaryAmount,