This commit is contained in:
Bright 2024-12-27 14:12:27 +07:00
parent 91ba933a65
commit 8e120660a1

View file

@ -623,6 +623,11 @@ export class CommandController extends Controller {
await new permission().PermissionGet(request, "COMMAND"); await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({ const command = await this.commandRepository.findOne({
where: { id }, where: { id },
order: {
commandSends : {
createdAt: "ASC"
}
},
relations: ["commandSends", "commandSends.commandSendCCs"], relations: ["commandSends", "commandSends.commandSendCCs"],
}); });
if (!command) { if (!command) {
@ -637,7 +642,9 @@ export class CommandController extends Controller {
lastName: item.lastName, lastName: item.lastName,
position: item.position, position: item.position,
org: item.org, org: item.org,
sendCC: item.commandSendCCs.map((x) => x.name), sendCC: item.commandSendCCs
.sort((a, b) => a.name.localeCompare(b.name))
.map((x) => x.name),
profileId: item.profileId, profileId: item.profileId,
})); }));
return new HttpSuccess(_command); return new HttpSuccess(_command);
@ -1883,42 +1890,105 @@ export class CommandController extends Controller {
profileId: item.current_holder.id, profileId: item.current_holder.id,
}, },
}); });
if (_commandSend) return; // if (_commandSend) return;
let commandSend = new CommandSend(); if (!_commandSend) {
commandSend.citizenId = item.current_holder.citizenId; let commandSend = new CommandSend();
commandSend.prefix = item.current_holder.prefix; commandSend.citizenId = item.current_holder.citizenId;
commandSend.firstName = item.current_holder.firstName; commandSend.prefix = item.current_holder.prefix;
commandSend.lastName = item.current_holder.lastName; commandSend.firstName = item.current_holder.firstName;
commandSend.position = item.current_holder.position; commandSend.lastName = item.current_holder.lastName;
commandSend.org = item.orgRoot.orgRootName; commandSend.position = item.current_holder.position;
commandSend.profileId = item.current_holder.id; commandSend.org = item.orgRoot.orgRootName;
commandSend.commandId = command.id; commandSend.profileId = item.current_holder.id;
commandSend.createdUserId = request.user.sub; commandSend.commandId = command.id;
commandSend.createdFullName = request.user.name; commandSend.createdUserId = request.user.sub;
commandSend.createdAt = new Date(); commandSend.createdFullName = request.user.name;
commandSend.lastUpdateUserId = request.user.sub; commandSend.createdAt = new Date();
commandSend.lastUpdateFullName = request.user.name; commandSend.lastUpdateUserId = request.user.sub;
commandSend.lastUpdatedAt = new Date(); commandSend.lastUpdateFullName = request.user.name;
await this.commandSendRepository.save(commandSend); commandSend.lastUpdatedAt = new Date();
if (commandSend && commandSend.id) { await this.commandSendRepository.save(commandSend);
let _ccName = new Array("EMAIL", "INBOX"); if (commandSend && commandSend.id) {
let _dataSendCC = new Array(); let _ccName = new Array("EMAIL", "INBOX");
for (let i = 0; i < _ccName.length; i++) { let _dataSendCC = new Array();
_dataSendCC.push({ for (let i = 0; i < _ccName.length; i++) {
commandSendId: commandSend.id, _dataSendCC.push({
name: _ccName[i], commandSendId: commandSend.id,
createdUserId: request.user.sub, name: _ccName[i],
createdFullName: request.user.name, createdUserId: request.user.sub,
createdAt: new Date(), createdFullName: request.user.name,
lastUpdateUserId: request.user.sub, createdAt: new Date(),
lastUpdateFullName: request.user.name, lastUpdateUserId: request.user.sub,
lastUpdatedAt: new Date(), lastUpdateFullName: request.user.name,
}); lastUpdatedAt: new Date(),
});
}
await this.commandSendCCRepository.save(_dataSendCC);
} }
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 && _posMasterDirector.positions.length > 0
? _posMasterDirector.positions[0].positionName
: 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);
}
}
})
)
}
} }
return new HttpSuccess(command.id); return new HttpSuccess(command.id);
} }