no message

This commit is contained in:
kittapath 2025-01-30 14:57:54 +07:00
parent ca9e79d1a4
commit e7e0e010b4

View file

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