api อัพเดทเงินเดือน
This commit is contained in:
parent
5ac8da1057
commit
7e87cec833
2 changed files with 84 additions and 0 deletions
|
|
@ -131,6 +131,46 @@ export class ProfileSalaryController extends Controller {
|
||||||
history.profileSalaryId = data.id;
|
history.profileSalaryId = data.id;
|
||||||
await this.salaryHistoryRepo.save(history, { data: req });
|
await this.salaryHistoryRepo.save(history, { data: req });
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("update")
|
||||||
|
public async updateSalary(@Request() req: RequestWithUser, @Body() body: CreateProfileSalary) {
|
||||||
|
if (!body.profileId) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||||
|
|
||||||
|
const dest_item = await this.salaryRepo.findOne({
|
||||||
|
where: { profileId: body.profileId },
|
||||||
|
order: { order: "DESC" },
|
||||||
|
});
|
||||||
|
const before = null;
|
||||||
|
const data = new ProfileSalary();
|
||||||
|
|
||||||
|
const meta = {
|
||||||
|
order: dest_item == null ? 1 : dest_item.order + 1,
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(data, { ...body, ...meta });
|
||||||
|
const history = new ProfileSalaryHistory();
|
||||||
|
Object.assign(history, { ...data, id: undefined });
|
||||||
|
await this.salaryRepo.save(data, { data: req });
|
||||||
|
setLogDataDiff(req, { before, after: data });
|
||||||
|
history.profileSalaryId = data.id;
|
||||||
|
await this.salaryHistoryRepo.save(history, { data: req });
|
||||||
|
|
||||||
let null_:any = null;
|
let null_:any = null;
|
||||||
profile.amount = body.amount ?? null_;
|
profile.amount = body.amount ?? null_;
|
||||||
profile.positionSalaryAmount = body.positionSalaryAmount ?? null_;
|
profile.positionSalaryAmount = body.positionSalaryAmount ?? null_;
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,50 @@ export class ProfileSalaryEmployeeController extends Controller {
|
||||||
history.profileSalaryId = data.id;
|
history.profileSalaryId = data.id;
|
||||||
await this.salaryHistoryRepo.save(history, { data: req });
|
await this.salaryHistoryRepo.save(history, { data: req });
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("update")
|
||||||
|
public async updateSalaryEmployee(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: CreateProfileSalaryEmployee,
|
||||||
|
) {
|
||||||
|
if (!body.profileEmployeeId) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||||
|
|
||||||
|
const dest_item = await this.salaryRepo.findOne({
|
||||||
|
where: { profileEmployeeId: body.profileEmployeeId },
|
||||||
|
order: { order: "DESC" },
|
||||||
|
});
|
||||||
|
const before = null;
|
||||||
|
const data = new ProfileSalary();
|
||||||
|
|
||||||
|
const meta = {
|
||||||
|
order: dest_item == null ? 1 : dest_item.order + 1,
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(data, { ...body, ...meta });
|
||||||
|
const history = new ProfileSalaryHistory();
|
||||||
|
Object.assign(history, { ...data, id: undefined });
|
||||||
|
|
||||||
|
await this.salaryRepo.save(data, { data: req });
|
||||||
|
setLogDataDiff(req, { before, after: data });
|
||||||
|
history.profileSalaryId = data.id;
|
||||||
|
await this.salaryHistoryRepo.save(history, { data: req });
|
||||||
|
|
||||||
let null_:any = null;
|
let null_:any = null;
|
||||||
profile.amount = body.amount ?? null_;
|
profile.amount = body.amount ?? null_;
|
||||||
profile.positionSalaryAmount = body.positionSalaryAmount ?? null_;
|
profile.positionSalaryAmount = body.positionSalaryAmount ?? null_;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue