diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index d3409187..128499ea 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -601,7 +601,7 @@ export async function PayloadSendNoti(commandId: string) { where: { id: commandId, }, - relations: ["commandType"], + relations: ["commandType", "commandRecives"], }); if (!_command || !_command.commandType) return ""; @@ -615,19 +615,18 @@ export async function PayloadSendNoti(commandId: string) { } let attachments = {} if (_command.commandType.isUploadAttachment === true) { - const _payloadAtt = { - name: _command && _command.commandType - ? `เอกสารแนบท้ายคำสั่ง${_command.commandType.name}` - : "", - url: `${process.env.API_URL}/salary/file/ระบบออกคำสั่ง/แนบท้าย/${commandId}/แนบท้าย`, + + const attachmentPayloads = _command.commandRecives.map((recive: any) => ({ + name: `เอกสารแนบท้ายคำสั่ง${_command.commandType.name} (${recive.prefix}${recive.firstName} ${recive.lastName})`, + url: `${process.env.API_URL}/salary/file/ระบบออกคำสั่ง/แนบท้าย/${commandId}/${recive.citizenId}/แนบท้าย`, isReport: true, isTemplate: false, - } + })); + attachments = { - attachments: [_payload, _payloadAtt] + attachments: [_payload, ...attachmentPayloads] }; - } - else { + } else { attachments = { attachments: [_payload] };