รายชื่อผู้ได้รับสำเนาคำสั่ง

This commit is contained in:
kittapath 2024-10-22 16:09:46 +07:00
parent 0ddec18725
commit ecadf565ac
2 changed files with 84 additions and 5 deletions

View file

@ -18,7 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { Command } from "../entities/Command";
import { Brackets, LessThan, MoreThan, Double, In, Between } from "typeorm";
import { Brackets, LessThan, MoreThan, Double, In, Between, IsNull, Not } from "typeorm";
import { CommandType } from "../entities/CommandType";
import { CommandSend } from "../entities/CommandSend";
import { Profile, CreateProfileAllFields } from "../entities/Profile";
@ -1429,6 +1429,53 @@ export class CommandController extends Controller {
);
})
.catch(() => {});
if (requestBody.persons != undefined && requestBody.persons.length > 0) {
const posMaster = await this.posMasterRepository.find({
where: {
current_holderId: In(requestBody.persons.map((x) => x.profileId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
select: ["orgRootId"],
});
const _posMaster = await this.posMasterRepository.find({
where: {
orgRootId: In(posMaster.map((x) => x.orgRootId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot"],
});
await Promise.all(
_posMaster.map(async (item) => {
const _commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
profileId: item.current_holder.id,
},
});
if (_commandSend) return;
let commandSend = new CommandSend();
commandSend.citizenId = item.current_holder.citizenId;
commandSend.prefix = item.current_holder.prefix;
commandSend.firstName = item.current_holder.firstName;
commandSend.lastName = item.current_holder.lastName;
commandSend.position = item.current_holder.position;
commandSend.org = item.orgRoot.orgRootName;
commandSend.profileId = item.current_holder.id;
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);
}),
);
}
return new HttpSuccess(command.id);
}
@ -1487,7 +1534,7 @@ export class CommandController extends Controller {
Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.commandId = item.commandId??_null;
history.commandId = item.commandId ?? _null;
await this.salaryHistoryRepo.save(history, { data: req });
const posMaster = await this.posMasterRepository.findOne({
@ -2040,7 +2087,7 @@ export class CommandController extends Controller {
createdAt: new Date(),
lastUpdatedAt: new Date(),
dateGovernment: new Date(),
isGovernment: item.isGovernment
isGovernment: item.isGovernment,
};
Object.assign(data, meta);
@ -2253,7 +2300,7 @@ export class CommandController extends Controller {
createdAt: new Date(),
lastUpdatedAt: new Date(),
dateGovernment: new Date(),
isGovernment: item.isGovernment
isGovernment: item.isGovernment,
});
await Promise.all([
this.profileRepository.save(_profile),
@ -2507,7 +2554,7 @@ export class CommandController extends Controller {
profileEmployeeId: profile.id,
date: new Date(),
amount: item.amount,
commandId: item.commandId,
commandId: item.commandId,
positionSalaryAmount: item.positionSalaryAmount,
mouthSalaryAmount: item.mouthSalaryAmount,
posNo: profile.posMasterNoTemp,