Migrate add table profileSalaryBackup & เพิ่ม insert รักษาการ และช่วยราชการ #2292
This commit is contained in:
parent
203ec6cb84
commit
5b726e69c8
5 changed files with 406 additions and 21 deletions
|
|
@ -35,7 +35,9 @@ import {
|
|||
CreatePositionSalaryEditHistory,
|
||||
PositionSalaryEditHistory,
|
||||
} from "../entities/PositionSalaryEditHistory";
|
||||
|
||||
import { ProfileSalaryBackup } from "../entities/ProfileSalaryBackup";
|
||||
import { ProfileActposition } from "../entities/ProfileActposition";
|
||||
import { ProfileAssistance } from "../entities/ProfileAssistance";
|
||||
@Route("api/v1/org/profile/salaryTemp")
|
||||
@Tags("ProfileSalaryTemp")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -1328,12 +1330,6 @@ export class ProfileSalaryTempController extends Controller {
|
|||
// const toUpdate = salaryTemps.filter((t) => t.salaryId && t.isEdit && !t.isDelete);
|
||||
const backupTemp = salaryTemps;
|
||||
const toInsert = salaryTemps.filter((t) => !t.isDelete);
|
||||
const dateNow = new Date();
|
||||
const metaUpdate = {
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
lastUpdatedAt: dateNow,
|
||||
};
|
||||
|
||||
// delete profile salary temp
|
||||
await queryRunner.manager.delete(ProfileSalaryTemp, {
|
||||
|
|
@ -1341,6 +1337,23 @@ export class ProfileSalaryTempController extends Controller {
|
|||
});
|
||||
|
||||
// add insert to profile salary backup
|
||||
const profileSalaryBeforeDelete = await queryRunner.manager.find(ProfileSalary, {
|
||||
where: {
|
||||
...(isOfficer
|
||||
? { profileId: body.profileId }
|
||||
: { profileEmployeeId: body.profileId }),
|
||||
},
|
||||
});
|
||||
|
||||
if (profileSalaryBeforeDelete.length > 0) {
|
||||
const backupRows = profileSalaryBeforeDelete.map(({ id, ...salary }) =>
|
||||
queryRunner.manager.create(ProfileSalaryBackup, {
|
||||
...salary,
|
||||
profileSalaryId: id,
|
||||
})
|
||||
);
|
||||
await queryRunner.manager.insert(ProfileSalaryBackup, backupRows);
|
||||
}
|
||||
|
||||
// delete profile salary
|
||||
await queryRunner.manager.delete(ProfileSalary, {
|
||||
|
|
@ -1366,18 +1379,78 @@ export class ProfileSalaryTempController extends Controller {
|
|||
* 5. INSERT (bulk)
|
||||
* ========================= */
|
||||
if (toInsert.length > 0) {
|
||||
const metaCreate = {
|
||||
const dateNow = new Date();
|
||||
const metaCreated = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
createdAt: dateNow,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
lastUpdatedAt: dateNow,
|
||||
};
|
||||
const insertData = toInsert.map(({ id, ...data }) => ({
|
||||
...data,
|
||||
...metaCreate,
|
||||
...metaUpdate,
|
||||
}));
|
||||
|
||||
await queryRunner.manager.insert(ProfileSalary, insertData);
|
||||
const salaryRows = toInsert.filter(
|
||||
x => !["17", "18"].includes(x.commandCode)
|
||||
);
|
||||
// ส่งไปรักษาการ
|
||||
const actPositionRows = toInsert.filter(
|
||||
x => x.commandCode === "17"
|
||||
);
|
||||
// ส่งไปช่วยราชการ
|
||||
const assistanceRows = toInsert.filter(
|
||||
x => x.commandCode === "18"
|
||||
);
|
||||
|
||||
if (salaryRows.length) {
|
||||
await queryRunner.manager.insert(
|
||||
ProfileSalary,
|
||||
salaryRows.map(({ id, ...data }) => ({
|
||||
...data,
|
||||
...metaCreated,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
if (actPositionRows.length) {
|
||||
await queryRunner.manager.insert(
|
||||
ProfileActposition,
|
||||
actPositionRows.map(x => ({
|
||||
profileId: x.profileId,
|
||||
profileEmployeeId: x.profileEmployeeId,
|
||||
dateStart: x.commandDateAffect,
|
||||
dateEnd: x.commandDateAffect,
|
||||
posNo: x.posNo,
|
||||
position: x.positionName,
|
||||
commandId: x.commandId,
|
||||
refCommandNo: x.commandNo,
|
||||
refCommandDate: x.commandDateAffect,
|
||||
status: false,
|
||||
isDeleted: false,
|
||||
...metaCreated,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
if (assistanceRows.length) {
|
||||
await queryRunner.manager.insert(
|
||||
ProfileAssistance,
|
||||
assistanceRows.map(x => ({
|
||||
profileId: x.profileId,
|
||||
profileEmployeeId: x.profileEmployeeId,
|
||||
agency: x.orgRoot,
|
||||
dateStart: x.commandDateAffect,
|
||||
dateEnd: x.commandDateAffect,
|
||||
commandId: x.commandId,
|
||||
commandNo: x.commandNo,
|
||||
commandName: x.commandName,
|
||||
refCommandDate: x.commandDateSign,
|
||||
refId: x.refId,
|
||||
status: "DONE",
|
||||
isUpload: false,
|
||||
...metaCreated,
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// insert profile salary temp new
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue