diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index a020da83..caa8328e 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -2142,253 +2142,252 @@ export class CommandController extends Controller { }), ); } - - if (["C-PM-10"].includes(commandCode)) { - await Promise.all( - requestBody.persons.map(async (item: any) => { - const _posMasterDirector = await this.posMasterRepository.findOne({ - where: { - orgRootId: item.rootId, - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - current_holderId: item.profileId, - }, - relations: ["current_holder", "orgRoot", "positions"], - }); - const _commandSend = await this.commandSendRepository.findOne({ - where: { - commandId: command.id, - profileId: item.profileId ?? _null, - }, - }); - if (!_commandSend) { - let commandSend = new CommandSend(); - commandSend.citizenId = item.citizenId; - commandSend.prefix = item.prefix; - commandSend.firstName = item.firstName; - commandSend.lastName = item.lastName; - commandSend.position = _posMasterDirector?.current_holder.position ?? _null; - commandSend.org = - _posMasterDirector && _posMasterDirector.orgRoot - ? _posMasterDirector.orgRoot.orgRootName - : _null; - commandSend.profileId = item.profileId; - commandSend.commandId = command.id; - commandSend.createdUserId = request.user.sub; - commandSend.createdFullName = request.user.name; - commandSend.createdAt = new Date(); - commandSend.lastUpdateUserId = request.user.sub; - commandSend.lastUpdateFullName = request.user.name; - commandSend.lastUpdatedAt = new Date(); - await this.commandSendRepository.save(commandSend); - if (commandSend && commandSend.id) { - let _ccName = new Array("EMAIL", "INBOX"); - let _dataSendCC = new Array(); - for (let i = 0; i < _ccName.length; i++) { - _dataSendCC.push({ - commandSendId: commandSend.id, - name: _ccName[i], - createdUserId: request.user.sub, - createdFullName: request.user.name, - createdAt: new Date(), - lastUpdateUserId: request.user.sub, - lastUpdateFullName: request.user.name, - lastUpdatedAt: new Date(), - }); - } - await this.commandSendCCRepository.save(_dataSendCC); + } + if (["C-PM-10"].includes(commandCode)) { + await Promise.all( + requestBody.persons.map(async (item: any) => { + const _posMasterDirector = await this.posMasterRepository.findOne({ + where: { + orgRootId: item.rootId, + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + current_holderId: item.profileId, + }, + relations: ["current_holder", "orgRoot", "positions"], + }); + const _commandSend = await this.commandSendRepository.findOne({ + where: { + commandId: command.id, + profileId: item.profileId ?? _null, + }, + }); + if (!_commandSend) { + let commandSend = new CommandSend(); + commandSend.citizenId = item.citizenId; + commandSend.prefix = item.prefix; + commandSend.firstName = item.firstName; + commandSend.lastName = item.lastName; + commandSend.position = _posMasterDirector?.current_holder.position ?? _null; + commandSend.org = + _posMasterDirector && _posMasterDirector.orgRoot + ? _posMasterDirector.orgRoot.orgRootName + : _null; + commandSend.profileId = item.profileId; + commandSend.commandId = command.id; + commandSend.createdUserId = request.user.sub; + commandSend.createdFullName = request.user.name; + commandSend.createdAt = new Date(); + commandSend.lastUpdateUserId = request.user.sub; + commandSend.lastUpdateFullName = request.user.name; + commandSend.lastUpdatedAt = new Date(); + await this.commandSendRepository.save(commandSend); + if (commandSend && commandSend.id) { + let _ccName = new Array("EMAIL", "INBOX"); + let _dataSendCC = new Array(); + for (let i = 0; i < _ccName.length; i++) { + _dataSendCC.push({ + commandSendId: commandSend.id, + name: _ccName[i], + createdUserId: request.user.sub, + createdFullName: request.user.name, + createdAt: new Date(), + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + }); } + await this.commandSendCCRepository.save(_dataSendCC); } - }), - ); - } + } + }), + ); + } - if ( - [ - "C-PM-01", - "C-PM-02", - "C-PM-03", - "C-PM-04", - "C-PM-05", - "C-PM-07", - "C-PM-08", - "C-PM-09", - "C-PM-13", - "C-PM-14", - "C-PM-15", - "C-PM-16", - "C-PM-21", - "C-PM-22", - "C-PM-24", - "C-PM-39", - ].includes(commandCode) - ) { - const _posMasterCommission = await this.posMasterRepository.findOne({ - where: { - orgRoot: { - isCommission: true, - }, - isDirector: true, - orgChild1: IsNull(), - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - current_holderId: Not(IsNull()), + if ( + [ + "C-PM-01", + "C-PM-02", + "C-PM-03", + "C-PM-04", + "C-PM-05", + "C-PM-07", + "C-PM-08", + "C-PM-09", + "C-PM-13", + "C-PM-14", + "C-PM-15", + "C-PM-16", + "C-PM-21", + "C-PM-22", + "C-PM-24", + "C-PM-39", + ].includes(commandCode) + ) { + const _posMasterCommission = await this.posMasterRepository.findOne({ + where: { + orgRoot: { + isCommission: true, }, - relations: ["current_holder", "orgRoot", "positions"], - }); - let _commandSend = await this.commandSendRepository.findOne({ - where: { - commandId: command.id, - profileId: _posMasterCommission?.current_holder.id ?? _null, - }, - }); - if (!_commandSend && _posMasterCommission != null) { - let commandSend = new CommandSend(); - commandSend.citizenId = _posMasterCommission?.current_holder.citizenId ?? _null; - commandSend.prefix = _posMasterCommission?.current_holder.prefix ?? _null; - commandSend.firstName = _posMasterCommission?.current_holder.firstName ?? _null; - commandSend.lastName = _posMasterCommission?.current_holder.lastName ?? _null; - commandSend.position = _posMasterCommission?.current_holder.position ?? _null; - commandSend.org = - _posMasterCommission && _posMasterCommission.orgRoot - ? _posMasterCommission.orgRoot.orgRootName - : _null; - commandSend.profileId = _posMasterCommission?.current_holderId ?? _null; - commandSend.commandId = command.id; - commandSend.createdUserId = request.user.sub; - commandSend.createdFullName = request.user.name; - commandSend.createdAt = new Date(); - commandSend.lastUpdateUserId = request.user.sub; - commandSend.lastUpdateFullName = request.user.name; - commandSend.lastUpdatedAt = new Date(); - await this.commandSendRepository.save(commandSend); - if (commandSend && commandSend.id) { - let _ccName = new Array("EMAIL", "INBOX"); - let _dataSendCC = new Array(); - for (let i = 0; i < _ccName.length; i++) { - _dataSendCC.push({ - commandSendId: commandSend.id, - name: _ccName[i], - createdUserId: request.user.sub, - createdFullName: request.user.name, - createdAt: new Date(), - lastUpdateUserId: request.user.sub, - lastUpdateFullName: request.user.name, - lastUpdatedAt: new Date(), - }); - } - await this.commandSendCCRepository.save(_dataSendCC); + isDirector: true, + orgChild1: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgRoot", "positions"], + }); + let _commandSend = await this.commandSendRepository.findOne({ + where: { + commandId: command.id, + profileId: _posMasterCommission?.current_holder.id ?? _null, + }, + }); + if (!_commandSend && _posMasterCommission != null) { + let commandSend = new CommandSend(); + commandSend.citizenId = _posMasterCommission?.current_holder.citizenId ?? _null; + commandSend.prefix = _posMasterCommission?.current_holder.prefix ?? _null; + commandSend.firstName = _posMasterCommission?.current_holder.firstName ?? _null; + commandSend.lastName = _posMasterCommission?.current_holder.lastName ?? _null; + commandSend.position = _posMasterCommission?.current_holder.position ?? _null; + commandSend.org = + _posMasterCommission && _posMasterCommission.orgRoot + ? _posMasterCommission.orgRoot.orgRootName + : _null; + commandSend.profileId = _posMasterCommission?.current_holderId ?? _null; + commandSend.commandId = command.id; + commandSend.createdUserId = request.user.sub; + commandSend.createdFullName = request.user.name; + commandSend.createdAt = new Date(); + commandSend.lastUpdateUserId = request.user.sub; + commandSend.lastUpdateFullName = request.user.name; + commandSend.lastUpdatedAt = new Date(); + await this.commandSendRepository.save(commandSend); + if (commandSend && commandSend.id) { + let _ccName = new Array("EMAIL", "INBOX"); + let _dataSendCC = new Array(); + for (let i = 0; i < _ccName.length; i++) { + _dataSendCC.push({ + commandSendId: commandSend.id, + name: _ccName[i], + createdUserId: request.user.sub, + createdFullName: request.user.name, + createdAt: new Date(), + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + }); } + await this.commandSendCCRepository.save(_dataSendCC); } - const _posMasterInformation = await this.posMasterRepository.findOne({ - where: { - orgChild1: { - isInformation: true, - }, - isDirector: true, - orgChild2: IsNull(), - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - current_holderId: Not(IsNull()), + } + const _posMasterInformation = await this.posMasterRepository.findOne({ + where: { + orgChild1: { + isInformation: true, }, - relations: ["current_holder", "orgRoot", "positions"], - }); - _commandSend = await this.commandSendRepository.findOne({ - where: { - commandId: command.id, - profileId: _posMasterInformation?.current_holder.id ?? _null, - }, - }); - if (!_commandSend && _posMasterInformation != null) { - let commandSend = new CommandSend(); - commandSend.citizenId = _posMasterInformation?.current_holder.citizenId ?? _null; - commandSend.prefix = _posMasterInformation?.current_holder.prefix ?? _null; - commandSend.firstName = _posMasterInformation?.current_holder.firstName ?? _null; - commandSend.lastName = _posMasterInformation?.current_holder.lastName ?? _null; - commandSend.position = _posMasterInformation?.current_holder.position ?? _null; - commandSend.org = - _posMasterInformation && _posMasterInformation.orgRoot - ? _posMasterInformation.orgRoot.orgRootName - : _null; - commandSend.profileId = _posMasterInformation?.current_holderId ?? _null; - commandSend.commandId = command.id; - commandSend.createdUserId = request.user.sub; - commandSend.createdFullName = request.user.name; - commandSend.createdAt = new Date(); - commandSend.lastUpdateUserId = request.user.sub; - commandSend.lastUpdateFullName = request.user.name; - commandSend.lastUpdatedAt = new Date(); - await this.commandSendRepository.save(commandSend); - if (commandSend && commandSend.id) { - let _ccName = new Array("EMAIL", "INBOX"); - let _dataSendCC = new Array(); - for (let i = 0; i < _ccName.length; i++) { - _dataSendCC.push({ - commandSendId: commandSend.id, - name: _ccName[i], - createdUserId: request.user.sub, - createdFullName: request.user.name, - createdAt: new Date(), - lastUpdateUserId: request.user.sub, - lastUpdateFullName: request.user.name, - lastUpdatedAt: new Date(), - }); - } - await this.commandSendCCRepository.save(_dataSendCC); + isDirector: true, + orgChild2: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgRoot", "positions"], + }); + _commandSend = await this.commandSendRepository.findOne({ + where: { + commandId: command.id, + profileId: _posMasterInformation?.current_holder.id ?? _null, + }, + }); + if (!_commandSend && _posMasterInformation != null) { + let commandSend = new CommandSend(); + commandSend.citizenId = _posMasterInformation?.current_holder.citizenId ?? _null; + commandSend.prefix = _posMasterInformation?.current_holder.prefix ?? _null; + commandSend.firstName = _posMasterInformation?.current_holder.firstName ?? _null; + commandSend.lastName = _posMasterInformation?.current_holder.lastName ?? _null; + commandSend.position = _posMasterInformation?.current_holder.position ?? _null; + commandSend.org = + _posMasterInformation && _posMasterInformation.orgRoot + ? _posMasterInformation.orgRoot.orgRootName + : _null; + commandSend.profileId = _posMasterInformation?.current_holderId ?? _null; + commandSend.commandId = command.id; + commandSend.createdUserId = request.user.sub; + commandSend.createdFullName = request.user.name; + commandSend.createdAt = new Date(); + commandSend.lastUpdateUserId = request.user.sub; + commandSend.lastUpdateFullName = request.user.name; + commandSend.lastUpdatedAt = new Date(); + await this.commandSendRepository.save(commandSend); + if (commandSend && commandSend.id) { + let _ccName = new Array("EMAIL", "INBOX"); + let _dataSendCC = new Array(); + for (let i = 0; i < _ccName.length; i++) { + _dataSendCC.push({ + commandSendId: commandSend.id, + name: _ccName[i], + createdUserId: request.user.sub, + createdFullName: request.user.name, + createdAt: new Date(), + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + }); } + await this.commandSendCCRepository.save(_dataSendCC); } - const _posMasterOfficer = await this.posMasterRepository.findOne({ - where: { - orgChild1: { - isOfficer: true, - }, - isDirector: true, - orgChild2: IsNull(), - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - current_holderId: Not(IsNull()), + } + const _posMasterOfficer = await this.posMasterRepository.findOne({ + where: { + orgChild1: { + isOfficer: true, }, - relations: ["current_holder", "orgRoot", "positions"], - }); - _commandSend = await this.commandSendRepository.findOne({ - where: { - commandId: command.id, - profileId: _posMasterOfficer?.current_holder.id ?? _null, - }, - }); - if (!_commandSend && _posMasterOfficer != null) { - let commandSend = new CommandSend(); - commandSend.citizenId = _posMasterOfficer?.current_holder.citizenId ?? _null; - commandSend.prefix = _posMasterOfficer?.current_holder.prefix ?? _null; - commandSend.firstName = _posMasterOfficer?.current_holder.firstName ?? _null; - commandSend.lastName = _posMasterOfficer?.current_holder.lastName ?? _null; - commandSend.position = _posMasterOfficer?.current_holder.position ?? _null; - commandSend.org = - _posMasterOfficer && _posMasterOfficer.orgRoot - ? _posMasterOfficer.orgRoot.orgRootName - : _null; - commandSend.profileId = _posMasterOfficer?.current_holderId ?? _null; - commandSend.commandId = command.id; - commandSend.createdUserId = request.user.sub; - commandSend.createdFullName = request.user.name; - commandSend.createdAt = new Date(); - commandSend.lastUpdateUserId = request.user.sub; - commandSend.lastUpdateFullName = request.user.name; - commandSend.lastUpdatedAt = new Date(); - await this.commandSendRepository.save(commandSend); - if (commandSend && commandSend.id) { - let _ccName = new Array("EMAIL", "INBOX"); - let _dataSendCC = new Array(); - for (let i = 0; i < _ccName.length; i++) { - _dataSendCC.push({ - commandSendId: commandSend.id, - name: _ccName[i], - createdUserId: request.user.sub, - createdFullName: request.user.name, - createdAt: new Date(), - lastUpdateUserId: request.user.sub, - lastUpdateFullName: request.user.name, - lastUpdatedAt: new Date(), - }); - } - await this.commandSendCCRepository.save(_dataSendCC); + isDirector: true, + orgChild2: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgRoot", "positions"], + }); + _commandSend = await this.commandSendRepository.findOne({ + where: { + commandId: command.id, + profileId: _posMasterOfficer?.current_holder.id ?? _null, + }, + }); + if (!_commandSend && _posMasterOfficer != null) { + let commandSend = new CommandSend(); + commandSend.citizenId = _posMasterOfficer?.current_holder.citizenId ?? _null; + commandSend.prefix = _posMasterOfficer?.current_holder.prefix ?? _null; + commandSend.firstName = _posMasterOfficer?.current_holder.firstName ?? _null; + commandSend.lastName = _posMasterOfficer?.current_holder.lastName ?? _null; + commandSend.position = _posMasterOfficer?.current_holder.position ?? _null; + commandSend.org = + _posMasterOfficer && _posMasterOfficer.orgRoot + ? _posMasterOfficer.orgRoot.orgRootName + : _null; + commandSend.profileId = _posMasterOfficer?.current_holderId ?? _null; + commandSend.commandId = command.id; + commandSend.createdUserId = request.user.sub; + commandSend.createdFullName = request.user.name; + commandSend.createdAt = new Date(); + commandSend.lastUpdateUserId = request.user.sub; + commandSend.lastUpdateFullName = request.user.name; + commandSend.lastUpdatedAt = new Date(); + await this.commandSendRepository.save(commandSend); + if (commandSend && commandSend.id) { + let _ccName = new Array("EMAIL", "INBOX"); + let _dataSendCC = new Array(); + for (let i = 0; i < _ccName.length; i++) { + _dataSendCC.push({ + commandSendId: commandSend.id, + name: _ccName[i], + createdUserId: request.user.sub, + createdFullName: request.user.name, + createdAt: new Date(), + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + }); } + await this.commandSendCCRepository.save(_dataSendCC); } } }