log
This commit is contained in:
parent
ce8bb41bda
commit
0f79425d65
17 changed files with 611 additions and 202 deletions
|
|
@ -29,6 +29,7 @@ import { Salarys } from "../entities/Salarys";
|
|||
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/employee")
|
||||
@Tags("SalaryEmployee")
|
||||
|
|
@ -86,11 +87,13 @@ export class SalaryEmployeeController extends Controller {
|
|||
if (chk_3fields && salarys.isActive) {
|
||||
salarys.isActive = false;
|
||||
}
|
||||
const before = null;
|
||||
salarys.createdUserId = request.user.sub;
|
||||
salarys.createdFullName = request.user.name;
|
||||
salarys.lastUpdateUserId = request.user.sub;
|
||||
salarys.lastUpdateFullName = request.user.name;
|
||||
await this.salaryEmployeeRepository.save(salarys);
|
||||
await this.salaryEmployeeRepository.save(salarys, { data: request });
|
||||
setLogDataDiff(request, { before, after: salarys });
|
||||
return new HttpSuccess(salarys.id);
|
||||
}
|
||||
|
||||
|
|
@ -139,22 +142,25 @@ export class SalaryEmployeeController extends Controller {
|
|||
});
|
||||
|
||||
if (chk_3fields.length > 0 && requestBody.isActive) {
|
||||
const beforeChk_3fields = structuredClone(chk_3fields);
|
||||
chk_3fields.forEach(async (item) => {
|
||||
item.isActive = false;
|
||||
item.lastUpdateUserId = request.user.sub;
|
||||
item.lastUpdateFullName = request.user.name;
|
||||
item.lastUpdatedAt = new Date();
|
||||
await this.salaryEmployeeRepository.save(chk_3fields);
|
||||
await this.salaryEmployeeRepository.save(chk_3fields, { data: request });
|
||||
setLogDataDiff(request, { before: beforeChk_3fields, after: chk_3fields });
|
||||
});
|
||||
}
|
||||
|
||||
const mergeData = Object.assign(new SalaryEmployee(), requestBody);
|
||||
|
||||
const before = structuredClone(chk_Salary);
|
||||
chk_Salary.lastUpdateUserId = request.user.sub;
|
||||
chk_Salary.lastUpdateFullName = request.user.name;
|
||||
chk_Salary.lastUpdatedAt = new Date();
|
||||
this.salaryEmployeeRepository.merge(chk_Salary, mergeData);
|
||||
await this.salaryEmployeeRepository.save(chk_Salary);
|
||||
await this.salaryEmployeeRepository.save(chk_Salary, { data: request });
|
||||
setLogDataDiff(request, { before, after: chk_Salary });
|
||||
return new HttpSuccess(id);
|
||||
}
|
||||
|
||||
|
|
@ -192,8 +198,8 @@ export class SalaryEmployeeController extends Controller {
|
|||
const del_SalaryRank = await this.salaryRankEmployeeRepository.find({
|
||||
where: { salaryEmployeeId: chk_Salary.id },
|
||||
});
|
||||
await this.salaryRankEmployeeRepository.remove(del_SalaryRank);
|
||||
await this.salaryEmployeeRepository.remove(chk_Salary);
|
||||
await this.salaryRankEmployeeRepository.remove(del_SalaryRank, { data: request });
|
||||
await this.salaryEmployeeRepository.remove(chk_Salary, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -213,8 +219,7 @@ export class SalaryEmployeeController extends Controller {
|
|||
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
||||
detail: "string", //คำอธิบาย
|
||||
})
|
||||
async GetSalaryById(
|
||||
@Request() request: RequestWithUser,@Path() id: string) {
|
||||
async GetSalaryById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
await new permission().PermissionGet(request, "SYS_WAGE_CHART_EMP");
|
||||
const salary = await this.salaryEmployeeRepository.findOne({
|
||||
where: { id: id },
|
||||
|
|
@ -290,13 +295,15 @@ export class SalaryEmployeeController extends Controller {
|
|||
});
|
||||
|
||||
const newSalary = { ...salary, id: randomUUID(), isActive: false };
|
||||
|
||||
await this.salaryEmployeeRepository.save(newSalary);
|
||||
const before = null;
|
||||
await this.salaryEmployeeRepository.save(newSalary, { data: request });
|
||||
setLogDataDiff(request, { before, after: newSalary });
|
||||
|
||||
await Promise.all(
|
||||
salaryRank.map(async (v) => {
|
||||
const newSalaryRank = { ...v, id: randomUUID() };
|
||||
await this.salaryRankEmployeeRepository.save(newSalaryRank);
|
||||
await this.salaryRankEmployeeRepository.save(newSalaryRank, { data: request });
|
||||
setLogDataDiff(request, { before, after: newSalaryRank });
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue