Merge branch 'develop' into adiDev
# Conflicts: # src/controllers/SalaryController.ts # src/controllers/SalaryEmployeeController.ts # src/controllers/SalaryPeriodController.ts # src/controllers/SalaryRankController.ts # src/controllers/SalaryRankEmployeeController.ts
This commit is contained in:
commit
667e90ddbd
21 changed files with 6539 additions and 5209 deletions
|
|
@ -9,6 +9,7 @@ import error from "./middlewares/error";
|
|||
import { AppDataSource } from "./database/data-source";
|
||||
import { RegisterRoutes } from "./routes";
|
||||
import { SalaryPeriodController } from "./controllers/SalaryPeriodController";
|
||||
import logMiddleware from "./middlewares/logs";
|
||||
|
||||
async function main() {
|
||||
await AppDataSource.initialize();
|
||||
|
|
@ -23,10 +24,11 @@ async function main() {
|
|||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use("/", express.static("static"));
|
||||
app.use(logMiddleware);
|
||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||
|
||||
RegisterRoutes(app);
|
||||
|
||||
|
||||
app.use(error);
|
||||
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
|
||||
const APP_PORT = +(process.env.APP_PORT || 3000);
|
||||
|
|
@ -35,7 +37,6 @@ async function main() {
|
|||
try {
|
||||
const salaryPeriod = new SalaryPeriodController();
|
||||
await salaryPeriod.CronjobSalaryPeriod();
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error executing function from controller:", error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,4 @@
|
|||
import {
|
||||
Controller,
|
||||
Request,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Path,
|
||||
} from "tsoa";
|
||||
import axios from "axios";
|
||||
import { Controller, Request, Get, Route, Security, Tags } from "tsoa";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
|
||||
@Route("/hello")
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
|
|
@ -14,7 +13,6 @@ import {
|
|||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -23,6 +21,8 @@ import { PosType } from "../entities/PosType";
|
|||
import { PosLevel, CreatePosLevel, UpdatePosLevel } from "../entities/PosLevel";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Not } from "typeorm";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/pos/level")
|
||||
@Tags("PosLevel")
|
||||
|
|
@ -52,7 +52,7 @@ export class PosLevelController extends Controller {
|
|||
async createLevel(
|
||||
@Body()
|
||||
requestBody: CreatePosLevel,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const posLevel = Object.assign(new PosLevel(), requestBody);
|
||||
if (!posLevel) {
|
||||
|
|
@ -64,10 +64,7 @@ export class PosLevelController extends Controller {
|
|||
},
|
||||
});
|
||||
if (!chkPosTypeId) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลประเภทตำแหน่งนี้"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
}
|
||||
|
||||
const chkPosLevelName = await this.posLevelRepository.findOne({
|
||||
|
|
@ -92,11 +89,15 @@ export class PosLevelController extends Controller {
|
|||
}
|
||||
|
||||
// try {
|
||||
const before = null;
|
||||
posLevel.createdUserId = request.user.sub;
|
||||
posLevel.createdFullName = request.user.name;
|
||||
posLevel.lastUpdateUserId = request.user.sub;
|
||||
posLevel.lastUpdateFullName = request.user.name;
|
||||
await this.posLevelRepository.save(posLevel);
|
||||
posLevel.createdAt = new Date();
|
||||
posLevel.lastUpdatedAt = new Date();
|
||||
await this.posLevelRepository.save(posLevel, { data: request });
|
||||
setLogDataDiff(request, { before, after: posLevel });
|
||||
return new HttpSuccess(posLevel);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
@ -118,7 +119,7 @@ export class PosLevelController extends Controller {
|
|||
async editLevel(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdatePosLevel,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const posLevel = await this.posLevelRepository.findOne({ where: { id } });
|
||||
if (!posLevel) {
|
||||
|
|
@ -131,10 +132,7 @@ export class PosLevelController extends Controller {
|
|||
},
|
||||
});
|
||||
if (!chkPosTypeId) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลระดับตำแหน่งนี้"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
|
||||
}
|
||||
|
||||
const chkPosLevelName = await this.posLevelRepository.findOne({
|
||||
|
|
@ -159,10 +157,13 @@ export class PosLevelController extends Controller {
|
|||
}
|
||||
|
||||
// try {
|
||||
const before = structuredClone(posLevel);
|
||||
posLevel.lastUpdateUserId = request.user.sub;
|
||||
posLevel.lastUpdateFullName = request.user.name;
|
||||
posLevel.lastUpdatedAt = new Date();
|
||||
this.posLevelRepository.merge(posLevel, requestBody);
|
||||
await this.posLevelRepository.save(posLevel);
|
||||
await this.posLevelRepository.save(posLevel, { data: Request });
|
||||
setLogDataDiff(request, { before, after: posLevel });
|
||||
return new HttpSuccess(posLevel.id);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
@ -177,13 +178,13 @@ export class PosLevelController extends Controller {
|
|||
* @param {string} id Id ระดับตำแหน่ง
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteLevel(@Path() id: string) {
|
||||
async deleteLevel(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const delPosLevel = await this.posLevelRepository.findOne({ where: { id } });
|
||||
if (!delPosLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
|
||||
}
|
||||
// try {
|
||||
await this.posLevelRepository.remove(delPosLevel);
|
||||
await this.posLevelRepository.remove(delPosLevel, { data: request });
|
||||
return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
|
|
@ -14,7 +13,6 @@ import {
|
|||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -23,6 +21,8 @@ import { PosType, CreatePosType, UpdatePosType } from "../entities/PosType";
|
|||
import { PosLevel } from "../entities/PosLevel";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Not } from "typeorm";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/pos/type")
|
||||
@Tags("PosType")
|
||||
|
|
@ -50,7 +50,7 @@ export class PosTypeController extends Controller {
|
|||
async createType(
|
||||
@Body()
|
||||
requestBody: CreatePosType,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const posType = Object.assign(new PosType(), requestBody);
|
||||
if (!posType) {
|
||||
|
|
@ -68,11 +68,15 @@ export class PosTypeController extends Controller {
|
|||
);
|
||||
}
|
||||
// try {
|
||||
const before = null;
|
||||
posType.createdUserId = request.user.sub;
|
||||
posType.createdFullName = request.user.name;
|
||||
posType.lastUpdateUserId = request.user.sub;
|
||||
posType.lastUpdateFullName = request.user.name;
|
||||
await this.posTypeRepository.save(posType);
|
||||
posType.createdAt = new Date();
|
||||
posType.lastUpdatedAt = new Date();
|
||||
await this.posTypeRepository.save(posType, { data: request });
|
||||
setLogDataDiff(request, { before, after: posType });
|
||||
return new HttpSuccess(posType);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
@ -94,7 +98,7 @@ export class PosTypeController extends Controller {
|
|||
async editType(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdatePosType,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const posType = await this.posTypeRepository.findOne({ where: { id } });
|
||||
if (!posType) {
|
||||
|
|
@ -113,10 +117,13 @@ export class PosTypeController extends Controller {
|
|||
);
|
||||
}
|
||||
// try {
|
||||
const before = structuredClone(posType);
|
||||
posType.lastUpdateUserId = request.user.sub;
|
||||
posType.lastUpdateFullName = request.user.name;
|
||||
posType.lastUpdatedAt = new Date();
|
||||
this.posTypeRepository.merge(posType, requestBody);
|
||||
await this.posTypeRepository.save(posType);
|
||||
await this.posTypeRepository.save(posType, { data: request });
|
||||
setLogDataDiff(request, { before, after: posType });
|
||||
return new HttpSuccess(posType.id);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
@ -131,7 +138,7 @@ export class PosTypeController extends Controller {
|
|||
* @param {string} id Id ตำแหน่ง
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteType(@Path() id: string) {
|
||||
async deleteType(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const delPosType = await this.posTypeRepository.findOne({ where: { id } });
|
||||
if (!delPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
|
|
@ -144,7 +151,7 @@ export class PosTypeController extends Controller {
|
|||
}
|
||||
|
||||
// try {
|
||||
await this.posTypeRepository.remove(delPosType);
|
||||
await this.posTypeRepository.remove(delPosType, { data: request });
|
||||
return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
|
|||
|
|
@ -2,19 +2,14 @@ import {
|
|||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -35,6 +30,9 @@ import { EmployeePosType } from "../entities/EmployeePosType";
|
|||
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
|
||||
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
|
||||
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
@Route("api/v1/salary/report")
|
||||
@Tags("Report")
|
||||
|
|
@ -51,9 +49,7 @@ export class ReportController extends Controller {
|
|||
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
|
||||
private salaryEmployeeRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
|
||||
private poTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private poTypeEmployeeRepository = AppDataSource.getRepository(EmployeePosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel);
|
||||
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
|
||||
private salaryOrgEmployeeRepository = AppDataSource.getRepository(SalaryOrgEmployee);
|
||||
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
|
||||
|
|
@ -100,7 +96,7 @@ export class ReportController extends Controller {
|
|||
},
|
||||
});
|
||||
|
||||
const mapSalaryRank = salaryRank.map((item, index) => ({
|
||||
const mapSalaryRank = salaryRank.map((item) => ({
|
||||
// no: index + 1,
|
||||
// id: item.id,
|
||||
salary: item.salary == null || item.salary == 0 ? "" : item.salary.toLocaleString(),
|
||||
|
|
@ -191,7 +187,7 @@ export class ReportController extends Controller {
|
|||
},
|
||||
});
|
||||
|
||||
const mapSalaryRank = salaryRank.map((item, index) => ({
|
||||
const mapSalaryRank = salaryRank.map((item) => ({
|
||||
step: item.step == null || item.step == 0 ? "" : item.step.toLocaleString(),
|
||||
salaryMonth:
|
||||
item.salaryMonth == null || item.salaryMonth == 0 ? "" : item.salaryMonth.toLocaleString(),
|
||||
|
|
@ -2101,7 +2097,7 @@ export class ReportController extends Controller {
|
|||
});
|
||||
const root = _root?.root == null ? "" : _root.root;
|
||||
// const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root;
|
||||
|
||||
|
||||
const formattedData = salaryProfile.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index + 1)),
|
||||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||||
|
|
@ -2114,8 +2110,10 @@ export class ReportController extends Controller {
|
|||
(item.root == undefined && item.root == null ? "" : item.root),
|
||||
posType: item.posType,
|
||||
posLevel: item.posLevel,
|
||||
posExecutive: item.posExecutive ? item.posExecutive:null,
|
||||
fullPositionName: item.posExecutive ? item.position + " (" + item.posExecutive + ")" : item.position || null,
|
||||
posExecutive: item.posExecutive ? item.posExecutive : null,
|
||||
fullPositionName: item.posExecutive
|
||||
? item.position + " (" + item.posExecutive + ")"
|
||||
: item.position || null,
|
||||
posMasterNo:
|
||||
Extension.ToThaiNumber(item.orgShortName) +
|
||||
Extension.ToThaiNumber(String(item.posMasterNo.toLocaleString())),
|
||||
|
|
@ -4186,8 +4184,8 @@ export class ReportController extends Controller {
|
|||
reportName: "emp2-02",
|
||||
data: {
|
||||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||||
yearOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1))),
|
||||
yearOld2: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-2))),
|
||||
yearOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 1))),
|
||||
yearOld2: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 2))),
|
||||
agency: _root?.root == null ? "" : _root?.root,
|
||||
data: formattedData,
|
||||
},
|
||||
|
|
@ -4694,7 +4692,7 @@ export class ReportController extends Controller {
|
|||
: null,
|
||||
score: profile.result,
|
||||
reason: profile.remark,
|
||||
remark:null,
|
||||
remark: null,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -4766,7 +4764,6 @@ export class ReportController extends Controller {
|
|||
.join("/");
|
||||
const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`;
|
||||
|
||||
|
||||
return {
|
||||
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
||||
fullName: fullName,
|
||||
|
|
@ -5210,7 +5207,7 @@ export class ReportController extends Controller {
|
|||
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
|
||||
|
||||
const formattedData = _salaryPeriod.map((profile, index) => {
|
||||
const fullNameParts = [
|
||||
const fullNameParts = [
|
||||
profile.child4,
|
||||
profile.child3,
|
||||
profile.child2,
|
||||
|
|
@ -5321,7 +5318,7 @@ export class ReportController extends Controller {
|
|||
const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root;
|
||||
|
||||
const formattedData = salaryProfile.map((profile, index) => {
|
||||
const fullNameParts = [
|
||||
const fullNameParts = [
|
||||
profile.child4,
|
||||
profile.child3,
|
||||
profile.child2,
|
||||
|
|
@ -5404,7 +5401,7 @@ export class ReportController extends Controller {
|
|||
const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root;
|
||||
|
||||
const formattedData = _salaryProfileEmp.map((profile, index) => {
|
||||
const fullNameParts = [
|
||||
const fullNameParts = [
|
||||
profile.child4,
|
||||
profile.child3,
|
||||
profile.child2,
|
||||
|
|
@ -5504,7 +5501,7 @@ export class ReportController extends Controller {
|
|||
.filter((part) => part !== undefined && part !== null)
|
||||
.join("/");
|
||||
const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`;
|
||||
|
||||
|
||||
return {
|
||||
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
||||
fullName: fullName,
|
||||
|
|
@ -5895,7 +5892,6 @@ export class ReportController extends Controller {
|
|||
.join("/");
|
||||
const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`;
|
||||
|
||||
|
||||
return {
|
||||
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
||||
fullName: fullName,
|
||||
|
|
@ -6273,7 +6269,7 @@ export class ReportController extends Controller {
|
|||
async SalaryReport33Resume(
|
||||
@Body()
|
||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await Promise.all(
|
||||
body.result.map(async (v) => {
|
||||
|
|
@ -6282,6 +6278,7 @@ export class ReportController extends Controller {
|
|||
id: v.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (salary != null) {
|
||||
await new CallAPI()
|
||||
.PostData(request, "/org/profile/salary", {
|
||||
|
|
@ -6300,9 +6297,14 @@ export class ReportController extends Controller {
|
|||
refCommandNo: v.refCommandNo,
|
||||
templateDoc: v.templateDoc,
|
||||
})
|
||||
.then(async (x) => {
|
||||
.then(async () => {
|
||||
const before = null;
|
||||
salary.status = "DONE";
|
||||
await this.salaryProfileRepository.save(salary);
|
||||
salary.lastUpdateUserId = request.user.sub;
|
||||
salary.lastUpdateFullName = request.user.name;
|
||||
salary.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salary, { data: request });
|
||||
setLogDataDiff(request, { before, after: salary });
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
@ -6321,7 +6323,7 @@ export class ReportController extends Controller {
|
|||
async SalaryReport34Resume(
|
||||
@Body()
|
||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await Promise.all(
|
||||
body.result.map(async (v) => {
|
||||
|
|
@ -6348,9 +6350,14 @@ export class ReportController extends Controller {
|
|||
refCommandNo: v.refCommandNo,
|
||||
templateDoc: v.templateDoc,
|
||||
})
|
||||
.then(async (x) => {
|
||||
.then(async () => {
|
||||
const before = null;
|
||||
salary.status = "DONE";
|
||||
await this.salaryProfileRepository.save(salary);
|
||||
salary.lastUpdateUserId = request.user.sub;
|
||||
salary.lastUpdateFullName = request.user.name;
|
||||
salary.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salary, { data: request });
|
||||
setLogDataDiff(request, { before, after: salary });
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
@ -6369,7 +6376,7 @@ export class ReportController extends Controller {
|
|||
async SalaryReport35Resume(
|
||||
@Body()
|
||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await Promise.all(
|
||||
body.result.map(async (v) => {
|
||||
|
|
@ -6396,9 +6403,14 @@ export class ReportController extends Controller {
|
|||
refCommandNo: v.refCommandNo,
|
||||
templateDoc: v.templateDoc,
|
||||
})
|
||||
.then(async (x) => {
|
||||
.then(async () => {
|
||||
const before = null;
|
||||
salary.status = "DONE";
|
||||
await this.salaryProfileRepository.save(salary);
|
||||
salary.lastUpdateUserId = request.user.sub;
|
||||
salary.lastUpdateFullName = request.user.name;
|
||||
salary.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salary, { data: request });
|
||||
setLogDataDiff(request, { before, after: salary });
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
@ -6417,7 +6429,7 @@ export class ReportController extends Controller {
|
|||
async SalaryReport36Resume(
|
||||
@Body()
|
||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await Promise.all(
|
||||
body.result.map(async (v) => {
|
||||
|
|
@ -6444,9 +6456,14 @@ export class ReportController extends Controller {
|
|||
refCommandNo: v.refCommandNo,
|
||||
templateDoc: v.templateDoc,
|
||||
})
|
||||
.then(async (x) => {
|
||||
.then(async () => {
|
||||
const before = null;
|
||||
salary.status = "DONE";
|
||||
await this.salaryProfileEmployeeRepository.save(salary);
|
||||
salary.lastUpdateUserId = request.user.sub;
|
||||
salary.lastUpdateFullName = request.user.name;
|
||||
salary.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileEmployeeRepository.save(salary, { data: request });
|
||||
setLogDataDiff(request, { before, after: salary });
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
@ -6465,7 +6482,7 @@ export class ReportController extends Controller {
|
|||
async SalaryReport37Resume(
|
||||
@Body()
|
||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await Promise.all(
|
||||
body.result.map(async (v) => {
|
||||
|
|
@ -6492,9 +6509,14 @@ export class ReportController extends Controller {
|
|||
refCommandNo: v.refCommandNo,
|
||||
templateDoc: v.templateDoc,
|
||||
})
|
||||
.then(async (x) => {
|
||||
.then(async () => {
|
||||
const before = null;
|
||||
salary.status = "DONE";
|
||||
await this.salaryProfileEmployeeRepository.save(salary);
|
||||
salary.lastUpdateUserId = request.user.sub;
|
||||
salary.lastUpdateFullName = request.user.name;
|
||||
salary.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileEmployeeRepository.save(salary, { data: request });
|
||||
setLogDataDiff(request, { before, after: salary });
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import { Salarys, CreateSalary, UpdateSalary } from "../entities/Salarys";
|
|||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Brackets, Like, Not } from "typeorm";
|
||||
import { Brackets, Not } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -25,6 +25,7 @@ import { SalaryRanks } from "../entities/SalaryRanks";
|
|||
import { randomUUID } from "crypto";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary")
|
||||
@Tags("Salary")
|
||||
|
|
@ -95,13 +96,17 @@ export class SalaryController extends Controller {
|
|||
if (chk_fields && salarys.isActive) {
|
||||
salarys.isActive = false;
|
||||
}
|
||||
const before = null;
|
||||
salarys.name = salarys.name;
|
||||
salarys.isSpecial = salarys.isSpecial;
|
||||
salarys.createdUserId = request.user.sub;
|
||||
salarys.createdFullName = request.user.name;
|
||||
salarys.lastUpdateUserId = request.user.sub;
|
||||
salarys.lastUpdateFullName = request.user.name;
|
||||
await this.salaryRepository.save(salarys);
|
||||
salarys.createdAt = new Date();
|
||||
salarys.lastUpdatedAt = new Date();
|
||||
await this.salaryRepository.save(salarys, { data: request });
|
||||
setLogDataDiff(request, { before, after: salarys });
|
||||
return new HttpSuccess(salarys.id);
|
||||
}
|
||||
|
||||
|
|
@ -167,12 +172,14 @@ export class SalaryController extends Controller {
|
|||
}
|
||||
|
||||
if (chk_fields.length > 0 && requestBody.isActive) {
|
||||
const before = structuredClone(chk_fields);
|
||||
chk_fields.forEach(async (item: any) => {
|
||||
item.isActive = false;
|
||||
item.lastUpdateUserId = request.user.sub;
|
||||
item.lastUpdateFullName = request.user.name;
|
||||
item.lastUpdatedAt = new Date();
|
||||
await this.salaryRepository.save(chk_fields);
|
||||
await this.salaryRepository.save(chk_fields, { data: request });
|
||||
setLogDataDiff(request, { before, after: request });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -191,11 +198,13 @@ export class SalaryController extends Controller {
|
|||
}
|
||||
const mergeData = Object.assign(new Salarys(), requestBody);
|
||||
|
||||
const before = structuredClone(chk_Salary);
|
||||
chk_Salary.lastUpdateUserId = request.user.sub;
|
||||
chk_Salary.lastUpdateFullName = request.user.name;
|
||||
chk_Salary.lastUpdatedAt = new Date();
|
||||
this.salaryRepository.merge(chk_Salary, mergeData);
|
||||
await this.salaryRepository.save(chk_Salary);
|
||||
await this.salaryRepository.save(chk_Salary, { data: request });
|
||||
setLogDataDiff(request, { before, after: chk_Salary });
|
||||
return new HttpSuccess(id);
|
||||
}
|
||||
|
||||
|
|
@ -224,8 +233,8 @@ export class SalaryController extends Controller {
|
|||
const del_SalaryRank = await this.salaryRankRepository.find({
|
||||
where: { salaryId: chk_Salary.id },
|
||||
});
|
||||
await this.salaryRankRepository.remove(del_SalaryRank);
|
||||
await this.salaryRepository.remove(chk_Salary);
|
||||
await this.salaryRankRepository.remove(del_SalaryRank, { data: request });
|
||||
await this.salaryRepository.remove(chk_Salary, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -247,8 +256,8 @@ export class SalaryController extends Controller {
|
|||
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
||||
detail: "string", //คำอธิบาย
|
||||
})
|
||||
async GetSalaryById(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionGet(req, "SYS_SALARY_CHART_OFFICER");
|
||||
async GetSalaryById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
await new permission().PermissionGet(request, "SYS_SALARY_CHART_OFFICER");
|
||||
const salary = await this.salaryRepository.findOne({
|
||||
relations: ["posType_", "posLevel_"],
|
||||
where: { id: id },
|
||||
|
|
@ -281,12 +290,12 @@ export class SalaryController extends Controller {
|
|||
*/
|
||||
@Get()
|
||||
async listSalary(
|
||||
@Request() req: RequestWithUser,
|
||||
@Request() request: RequestWithUser,
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
await new permission().PermissionList(req, "SYS_SALARY_CHART_OFFICER");
|
||||
await new permission().PermissionList(request, "SYS_SALARY_CHART_OFFICER");
|
||||
const [salary, total] = await AppDataSource.getRepository(Salarys)
|
||||
.createQueryBuilder("salary")
|
||||
.leftJoinAndSelect("salary.posType_", "posType_")
|
||||
|
|
@ -345,14 +354,29 @@ export class SalaryController extends Controller {
|
|||
where: { salaryId: salary?.id },
|
||||
});
|
||||
|
||||
const before = null;
|
||||
const newSalary = { ...salary, id: randomUUID(), isActive: false };
|
||||
|
||||
await this.salaryRepository.save(newSalary);
|
||||
newSalary.createdUserId = request.user.sub;
|
||||
newSalary.createdFullName = request.user.name;
|
||||
newSalary.lastUpdateUserId = request.user.sub;
|
||||
newSalary.lastUpdateFullName = request.user.name;
|
||||
newSalary.createdAt = new Date();
|
||||
newSalary.lastUpdatedAt = new Date();
|
||||
await this.salaryRepository.save(newSalary, { data: request });
|
||||
setLogDataDiff(request, { before, after: newSalary });
|
||||
|
||||
await Promise.all(
|
||||
salaryRank.map(async (v) => {
|
||||
const newSalaryRank = { ...v, id: randomUUID() };
|
||||
await this.salaryRankRepository.save(newSalaryRank);
|
||||
newSalary.createdUserId = request.user.sub;
|
||||
newSalary.createdFullName = request.user.name;
|
||||
newSalary.lastUpdateUserId = request.user.sub;
|
||||
newSalary.lastUpdateFullName = request.user.name;
|
||||
newSalary.createdAt = new Date();
|
||||
newSalary.lastUpdatedAt = new Date();
|
||||
await this.salaryRankRepository.save(newSalaryRank, { data: request });
|
||||
setLogDataDiff(request, { before, after: newSalaryRank });
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,16 +19,16 @@ import {
|
|||
UpdateSalaryEmployee,
|
||||
} from "../entities/SalaryEmployee";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Not, Like, Brackets } from "typeorm";
|
||||
import { Not, Brackets } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
|
||||
import { randomUUID } from "crypto";
|
||||
import { Salarys } from "../entities/Salarys";
|
||||
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/employee")
|
||||
@Tags("SalaryEmployee")
|
||||
|
|
@ -86,11 +86,16 @@ 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);
|
||||
salarys.createdAt = new Date();
|
||||
salarys.lastUpdatedAt = new Date();
|
||||
|
||||
await this.salaryEmployeeRepository.save(salarys, { data: request });
|
||||
setLogDataDiff(request, { before, after: salarys });
|
||||
return new HttpSuccess(salarys.id);
|
||||
}
|
||||
|
||||
|
|
@ -139,22 +144,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);
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +191,7 @@ export class SalaryEmployeeController extends Controller {
|
|||
const chk_SalaryFormulaEmp = await this.salaryFormulaEmployeeRepository.find({
|
||||
where: { salaryEmployeeId: id },
|
||||
});
|
||||
if(chk_SalaryFormulaEmp.length > 0){
|
||||
if (chk_SalaryFormulaEmp.length > 0) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่สามารถลบรายการนี้ได้เนื่องจากมีการใช้งานอยู่",
|
||||
|
|
@ -192,8 +200,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,7 +221,7 @@ export class SalaryEmployeeController extends Controller {
|
|||
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
||||
detail: "string", //คำอธิบาย
|
||||
})
|
||||
async GetSalaryById(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
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 },
|
||||
|
|
@ -273,10 +281,7 @@ export class SalaryEmployeeController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Post("copy")
|
||||
async copySalary(
|
||||
@Body() body: { id: string },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
async copySalary(@Body() body: { id: string }, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionCreate(request, "SYS_WAGE_CHART_EMP");
|
||||
const salary = await this.salaryEmployeeRepository.findOne({
|
||||
relations: ["salaryRankEmployees_"],
|
||||
|
|
@ -292,13 +297,27 @@ export class SalaryEmployeeController extends Controller {
|
|||
});
|
||||
|
||||
const newSalary = { ...salary, id: randomUUID(), isActive: false };
|
||||
|
||||
await this.salaryEmployeeRepository.save(newSalary);
|
||||
const before = null;
|
||||
newSalary.createdUserId = request.user.sub;
|
||||
newSalary.createdFullName = request.user.name;
|
||||
newSalary.lastUpdateUserId = request.user.sub;
|
||||
newSalary.lastUpdateFullName = request.user.name;
|
||||
newSalary.createdAt = new Date();
|
||||
newSalary.lastUpdatedAt = new Date();
|
||||
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);
|
||||
newSalaryRank.createdUserId = request.user.sub;
|
||||
newSalaryRank.createdFullName = request.user.name;
|
||||
newSalaryRank.lastUpdateUserId = request.user.sub;
|
||||
newSalaryRank.lastUpdateFullName = request.user.name;
|
||||
newSalaryRank.createdAt = new Date();
|
||||
newSalaryRank.lastUpdatedAt = new Date();
|
||||
await this.salaryRankEmployeeRepository.save(newSalaryRank, { data: request });
|
||||
setLogDataDiff(request, { before, after: newSalaryRank });
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,12 @@ import {
|
|||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
|
|
@ -19,7 +17,6 @@ import {
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { PosLevel, CreatePosLevel, UpdatePosLevel } from "../entities/PosLevel";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { In, Like, Not } from "typeorm";
|
||||
import {
|
||||
|
|
@ -32,6 +29,7 @@ import { EmployeePosType } from "../entities/EmployeePosType";
|
|||
import { SalaryEmployee } from "../entities/SalaryEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/formula")
|
||||
@Tags("SalaryFormula")
|
||||
|
|
@ -98,12 +96,16 @@ export class SalaryFormulaEmployeeController extends Controller {
|
|||
},
|
||||
});
|
||||
|
||||
const before = null;
|
||||
formula.salaryEmployeeMins = chkSalaryEmployeeMin;
|
||||
formula.createdUserId = request.user.sub;
|
||||
formula.createdFullName = request.user.name;
|
||||
formula.lastUpdateUserId = request.user.sub;
|
||||
formula.lastUpdateFullName = request.user.name;
|
||||
await this.salaryFormulaEmployeeRepository.save(formula);
|
||||
formula.createdAt = new Date();
|
||||
formula.lastUpdatedAt = new Date();
|
||||
await this.salaryFormulaEmployeeRepository.save(formula, { data: request });
|
||||
setLogDataDiff(request, { before, after: formula });
|
||||
return new HttpSuccess(formula);
|
||||
}
|
||||
|
||||
|
|
@ -160,6 +162,7 @@ export class SalaryFormulaEmployeeController extends Controller {
|
|||
id: In(requestBody.salaryEmployeeMinIds),
|
||||
},
|
||||
});
|
||||
const before = structuredClone(formula);
|
||||
formula.position = requestBody.position;
|
||||
formula.salaryMin = requestBody.salaryMin;
|
||||
formula.salary = requestBody.salary;
|
||||
|
|
@ -171,7 +174,9 @@ export class SalaryFormulaEmployeeController extends Controller {
|
|||
formula.salaryEmployeeMins = chkSalaryEmployeeMin;
|
||||
formula.lastUpdateUserId = request.user.sub;
|
||||
formula.lastUpdateFullName = request.user.name;
|
||||
await this.salaryFormulaEmployeeRepository.save(formula);
|
||||
formula.lastUpdatedAt = new Date();
|
||||
await this.salaryFormulaEmployeeRepository.save(formula, { data: request });
|
||||
setLogDataDiff(request, { before, after: formula });
|
||||
return new HttpSuccess(formula.id);
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +192,7 @@ export class SalaryFormulaEmployeeController extends Controller {
|
|||
const delFormula = await this.salaryFormulaEmployeeRepository.findOne({ where: { id } });
|
||||
if (!delFormula) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังค่าจ้างนี้");
|
||||
|
||||
await this.salaryFormulaEmployeeRepository.remove(delFormula);
|
||||
await this.salaryFormulaEmployeeRepository.remove(delFormula, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ import { SalaryRanks } from "../entities/SalaryRanks";
|
|||
import CallAPI from "../interfaces/call-api";
|
||||
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
|
||||
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
|
||||
import { isNullOrUndefined } from "util";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/period")
|
||||
@Tags("Salary")
|
||||
|
|
@ -297,7 +297,7 @@ export class SalaryPeriodController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
|
||||
}
|
||||
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: req });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -328,7 +328,10 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -382,7 +385,10 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -402,8 +408,11 @@ export class SalaryPeriodController extends Controller {
|
|||
* @param {string} amount ฐานเงินเดือน
|
||||
*/
|
||||
@Post("change/amount")
|
||||
async changeAmount(@Body() body: { profileId: string; amount: number }, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionCreate(request, "SYS_SALARY_OFFICER");
|
||||
async changeAmount(
|
||||
@Body() body: { profileId: string; amount: number },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(request, "SYS_SALARY_OFFICER");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
where: { id: body.profileId },
|
||||
|
|
@ -575,8 +584,12 @@ export class SalaryPeriodController extends Controller {
|
|||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||
salaryProfile.lastUpdateFullName = request.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
const before = structuredClone(salaryProfile);
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -607,7 +620,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -661,7 +678,11 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -679,8 +700,11 @@ export class SalaryPeriodController extends Controller {
|
|||
* @param {string} groupId groupId
|
||||
*/
|
||||
@Post("change/group")
|
||||
async changeGroup(@Body() body: { profileId: string; groupId: string } ,@Request() req: RequestWithUser) {
|
||||
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
||||
async changeGroup(
|
||||
@Body() body: { profileId: string; groupId: string },
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
where: { id: body.profileId },
|
||||
|
|
@ -695,9 +719,15 @@ export class SalaryPeriodController extends Controller {
|
|||
if (!salaryOrg) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
|
||||
}
|
||||
const before = null;
|
||||
|
||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = req.user.sub;
|
||||
salaryProfile.lastUpdateFullName = req.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
where: { id: salaryProfile.id },
|
||||
|
|
@ -727,7 +757,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -781,7 +815,11 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -802,7 +840,7 @@ export class SalaryPeriodController extends Controller {
|
|||
@Post("change/type")
|
||||
async changeType(
|
||||
@Body() body: { profileId: string; type: string; isReserve: boolean; remark?: string | null },
|
||||
@Request() req: RequestWithUser
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
|
|
@ -1011,7 +1049,12 @@ export class SalaryPeriodController extends Controller {
|
|||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = req.user.sub;
|
||||
salaryProfile.lastUpdateFullName = req.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
const before = structuredClone(salaryProfile);
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -1042,7 +1085,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -1096,7 +1143,11 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1114,6 +1165,7 @@ export class SalaryPeriodController extends Controller {
|
|||
*/
|
||||
@Put("org/{id}")
|
||||
async GetListsSalaryProfile(
|
||||
@Request() request: RequestWithUser,
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
body: {
|
||||
|
|
@ -1124,6 +1176,7 @@ export class SalaryPeriodController extends Controller {
|
|||
isRetire?: string | null;
|
||||
},
|
||||
) {
|
||||
await new permission().PermissionList(request, "SYS_SALARY_OFFICER");
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
id: id,
|
||||
|
|
@ -1213,6 +1266,7 @@ export class SalaryPeriodController extends Controller {
|
|||
if (!salaryProfile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้");
|
||||
}
|
||||
const before = structuredClone(salaryProfile);
|
||||
salaryProfile.isPunish = body.isPunish;
|
||||
salaryProfile.isSuspension = body.isSuspension;
|
||||
salaryProfile.isAbsent = body.isAbsent;
|
||||
|
|
@ -1220,7 +1274,9 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||
salaryProfile.lastUpdateFullName = request.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfile });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -1438,12 +1494,16 @@ export class SalaryPeriodController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
||||
salaryProfile.createdUserId = request.user.sub;
|
||||
salaryProfile.createdFullName = request.user.name;
|
||||
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||
salaryProfile.lastUpdateFullName = request.user.name;
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.createdAt = new Date();
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -1474,7 +1534,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -1528,7 +1592,11 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1554,8 +1622,14 @@ export class SalaryPeriodController extends Controller {
|
|||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
||||
}
|
||||
const before = structuredClone(salaryPeriod);
|
||||
salaryPeriod.isClose = !salaryPeriod.isClose;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -1591,13 +1665,16 @@ export class SalaryPeriodController extends Controller {
|
|||
"ประเภทผังปี " + Extension.ToThaiYear(salaryPeriod.year) + " ซ้ำ",
|
||||
);
|
||||
}
|
||||
|
||||
const before = null;
|
||||
salaryPeriod.period = salaryPeriod.period.toUpperCase();
|
||||
salaryPeriod.createdUserId = request.user.sub;
|
||||
salaryPeriod.createdFullName = request.user.name;
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.createdAt = new Date();
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
if (salaryPeriod.period == "SPECIAL") {
|
||||
const snapshot = "SNAP1";
|
||||
|
|
@ -1607,8 +1684,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfile = await this.salaryProfileRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
|
|
@ -1616,14 +1693,18 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||
|
||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
|
|
@ -1638,8 +1719,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
|
|
@ -1656,7 +1740,10 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -1702,13 +1789,15 @@ export class SalaryPeriodController extends Controller {
|
|||
"ประเภทผังปี " + (requestBody.effectiveDate.getFullYear() + 543) + " ซ้ำ",
|
||||
);
|
||||
}
|
||||
|
||||
const beforeChk_SalaryPeriod = structuredClone(chk_SalaryPeriod);
|
||||
chk_SalaryPeriod.period = requestBody.period.toUpperCase();
|
||||
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
||||
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
||||
this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody);
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod);
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before: beforeChk_SalaryPeriod, after: chk_SalaryPeriod });
|
||||
|
||||
if (chk_SalaryPeriod.period == "SPECIAL") {
|
||||
const snapshot = "SNAP1";
|
||||
const salaryOrg = await this.salaryOrgRepository.find({
|
||||
|
|
@ -1717,8 +1806,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfile = await this.salaryProfileRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: chk_SalaryPeriod.id, snapshot: snapshot },
|
||||
|
|
@ -1726,18 +1815,25 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||
|
||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||
|
||||
chk_SalaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod);
|
||||
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
||||
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
||||
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before: beforeChk_SalaryPeriod, after: chk_SalaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||
|
||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
|
|
@ -1749,13 +1845,18 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||
|
||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
|
|
@ -1767,7 +1868,10 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -1798,8 +1902,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfile = SalaryOrg.find((x) => x.salaryProfiles.length > 0);
|
||||
if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||
|
||||
await this.salaryOrgRepository.remove(SalaryOrg);
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
||||
await this.salaryOrgRepository.remove(SalaryOrg, { data: request });
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
|
||||
return new HttpSuccess();
|
||||
} else {
|
||||
const SalaryOrg = await this.salaryOrgRepository.findOne({
|
||||
|
|
@ -1807,7 +1911,7 @@ export class SalaryPeriodController extends Controller {
|
|||
});
|
||||
if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -1956,7 +2060,7 @@ export class SalaryPeriodController extends Controller {
|
|||
async SnapshotSalary(
|
||||
@Path() snapshot: string,
|
||||
salaryPeriodId: string,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
snapshot = snapshot.toLocaleUpperCase();
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
|
|
@ -1972,8 +2076,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfile = await this.salaryProfileRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
|
|
@ -1981,8 +2085,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||
let total = 1000;
|
||||
let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/salary/gen", {
|
||||
|
|
@ -2043,13 +2147,20 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||
|
||||
const beforeSalaryPeriod = structuredClone(salaryPeriod);
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryPeriod, after: salaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
delete salaryOrgNew.id;
|
||||
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
|
|
@ -2060,12 +2171,17 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2073,6 +2189,8 @@ export class SalaryPeriodController extends Controller {
|
|||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
|
|
@ -2084,11 +2202,16 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2118,12 +2241,17 @@ export class SalaryPeriodController extends Controller {
|
|||
if (salaryOrgNew != null) {
|
||||
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
|
||||
delete salaryProfileNew.id;
|
||||
|
||||
const beforeSalaryProfileNew = structuredClone(salaryProfileNew);
|
||||
|
||||
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
||||
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
salaryProfileNew.createdAt = new Date();
|
||||
salaryProfileNew.lastUpdatedAt = new Date();
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgOld = await this.salaryOrgRepository.find({
|
||||
|
|
@ -2146,7 +2274,8 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
||||
}
|
||||
await this.salaryProfileRepository.save(salaryProfileNew);
|
||||
await this.salaryProfileRepository.save(salaryProfileNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2164,12 +2293,16 @@ export class SalaryPeriodController extends Controller {
|
|||
if (salaryOrgNew != null) {
|
||||
let salaryProfileNew = Object.assign(new SalaryProfileEmployee(), profile);
|
||||
delete salaryProfileNew.id;
|
||||
const beforeSalaryProfileNew = structuredClone(salaryProfileNew);
|
||||
|
||||
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
||||
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
salaryProfileNew.createdAt = new Date();
|
||||
salaryProfileNew.lastUpdatedAt = new Date();
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgOld = await this.salaryOrgEmployeeRepository.find({
|
||||
|
|
@ -2192,7 +2325,8 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
||||
}
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew);
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2232,6 +2366,7 @@ export class SalaryPeriodController extends Controller {
|
|||
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
|
||||
}
|
||||
|
||||
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -2258,6 +2393,7 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
} else {
|
||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||
|
||||
_salaryOrg.currentAmount = totalProfile;
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||
|
|
@ -2265,12 +2401,21 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before: before_salaryOrg, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||
let totalAmount = 0;
|
||||
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||
|
||||
if (salaryPeriodAPROld != null) {
|
||||
const salaryOrgSnap2Old: any = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -2320,12 +2465,21 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before: before_salaryOrg, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
} else if (salaryPeriod.period == "APR") {
|
||||
await Promise.all(
|
||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -2354,11 +2508,20 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before: before_salaryOrg, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -2387,7 +2550,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before: before_salaryOrg, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -2464,8 +2634,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfile = await this.salaryProfileRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
|
|
@ -2473,8 +2643,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||
|
||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||
let total = 1000;
|
||||
|
|
@ -2534,9 +2704,13 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
}
|
||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||
|
||||
const before = null;
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
|
|
@ -2551,12 +2725,17 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2574,12 +2753,17 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2638,7 +2822,14 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
||||
}
|
||||
await this.salaryProfileRepository.save(salaryProfileNew);
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
salaryProfileNew.createdAt = new Date();
|
||||
salaryProfileNew.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfileNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfileNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2684,7 +2875,14 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
||||
}
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew);
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
salaryProfileNew.createdAt = new Date();
|
||||
salaryProfileNew.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfileNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2757,7 +2955,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
|
|
@ -2812,7 +3017,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
} else if (salaryPeriod.period == "APR") {
|
||||
|
|
@ -2846,7 +3058,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
|
|
@ -2879,7 +3098,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -2893,7 +3119,11 @@ export class SalaryPeriodController extends Controller {
|
|||
* @param {string} rootId Guid, *Id สำนัก
|
||||
*/
|
||||
@Get("officer/approve/{periodId}/{rootId}")
|
||||
async OfficerApprove(@Path() periodId: string, rootId: string) {
|
||||
async OfficerApprove(
|
||||
@Path() periodId: string,
|
||||
rootId: string,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: periodId },
|
||||
relations: ["salaryOrgs"],
|
||||
|
|
@ -2904,8 +3134,13 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITHEAD1";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2919,7 +3154,7 @@ export class SalaryPeriodController extends Controller {
|
|||
* @param {string} rootId Guid, *Id สำนัก
|
||||
*/
|
||||
@Get("head/approve/{periodId}/{rootId}")
|
||||
async HeadApprove(@Path() periodId: string, rootId: string) {
|
||||
async HeadApprove(@Path() periodId: string, rootId: string, @Request() request: RequestWithUser) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: periodId },
|
||||
relations: ["salaryOrgs"],
|
||||
|
|
@ -2931,8 +3166,13 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITOWNER1";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2946,7 +3186,11 @@ export class SalaryPeriodController extends Controller {
|
|||
* @param {string} rootId Guid, *Id สำนัก
|
||||
*/
|
||||
@Get("owner/approve/{periodId}/{rootId}")
|
||||
async OwnerApprove(@Path() periodId: string, rootId: string) {
|
||||
async OwnerApprove(
|
||||
@Path() periodId: string,
|
||||
rootId: string,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: periodId },
|
||||
relations: ["salaryOrgs"],
|
||||
|
|
@ -2958,8 +3202,13 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "REPORT";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2994,9 +3243,14 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITHEAD2";
|
||||
x.ownerRecommend = body.titleRecommend;
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -3031,9 +3285,14 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "REPORT";
|
||||
x.ownerRecommend = body.titleRecommend;
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {
|
|||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { In, Not, MoreThan, Brackets, Like, MoreThanOrEqual } from "typeorm";
|
||||
import { In, Not, MoreThan, Brackets, Like } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -32,6 +32,7 @@ import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
|
|||
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/period-employee")
|
||||
@Tags("SalaryEmployee")
|
||||
|
|
@ -42,7 +43,6 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfileEmployee);
|
||||
private posTypeRepository = AppDataSource.getRepository(EmployeePosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
|
||||
private salaryRepository = AppDataSource.getRepository(SalaryEmployee);
|
||||
private salaryRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
|
||||
private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee);
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
|
||||
}
|
||||
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -289,7 +289,10 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -343,7 +346,10 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -363,7 +369,10 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
* @param {string} amount ฐานเงินเดือน
|
||||
*/
|
||||
@Post("change/amount")
|
||||
async changeAmount(@Body() body: { profileId: string; amount: number }, @Request() req: RequestWithUser) {
|
||||
async changeAmount(
|
||||
@Body() body: { profileId: string; amount: number },
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_WAGE");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -709,7 +718,12 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = req.user.sub;
|
||||
salaryProfile.lastUpdateFullName = req.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
const before = structuredClone(salaryProfile);
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -740,7 +754,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -794,7 +812,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -813,7 +835,10 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
* @param {string} groupId groupId
|
||||
*/
|
||||
@Post("change/group")
|
||||
async changeGroup(@Body() body: { profileId: string; groupId: string }, @Request() req: RequestWithUser) {
|
||||
async changeGroup(
|
||||
@Body() body: { profileId: string; groupId: string },
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_WAGE");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -829,9 +854,13 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
if (!salaryOrg) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = req.user.sub;
|
||||
salaryProfile.lastUpdateFullName = req.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryProfile });
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
where: { id: salaryProfile.id },
|
||||
|
|
@ -861,7 +890,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -915,7 +948,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -936,7 +973,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
@Post("change/type")
|
||||
async changeType(
|
||||
@Body() body: { profileId: string; type: string; isReserve: boolean; remark?: string | null },
|
||||
@Request() req: RequestWithUser
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_WAGE");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
|
|
@ -1320,7 +1357,12 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = req.user.sub;
|
||||
salaryProfile.lastUpdateFullName = req.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
const before = structuredClone(salaryProfile);
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -1351,7 +1393,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -1405,7 +1451,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1423,6 +1473,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
*/
|
||||
@Put("org/{id}")
|
||||
async GetListsSalaryProfile(
|
||||
@Request() request: RequestWithUser,
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
body: {
|
||||
|
|
@ -1433,6 +1484,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
isRetire?: string | null;
|
||||
},
|
||||
) {
|
||||
await new permission().PermissionList(request, "SYS_WAGE");
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
id: id,
|
||||
|
|
@ -1575,6 +1627,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
if (!salaryProfile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้");
|
||||
}
|
||||
const before = structuredClone(salaryProfile);
|
||||
salaryProfile.isPunish = body.isPunish;
|
||||
salaryProfile.isSuspension = body.isSuspension;
|
||||
salaryProfile.isAbsent = body.isAbsent;
|
||||
|
|
@ -1582,7 +1635,9 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||
salaryProfile.lastUpdateFullName = request.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfile });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -1974,12 +2029,16 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
||||
salaryProfile.createdUserId = request.user.sub;
|
||||
salaryProfile.createdFullName = request.user.name;
|
||||
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||
salaryProfile.lastUpdateFullName = request.user.name;
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.createdAt = new Date();
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -2010,7 +2069,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -2064,7 +2127,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2083,15 +2150,20 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
* @param {string} id Guid, *Id รอบเงินเดือน
|
||||
*/
|
||||
@Get("close/{id}")
|
||||
async closeSalaryPeriod_ById(@Path() id: string) {
|
||||
async closeSalaryPeriod_ById(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
||||
}
|
||||
const before = structuredClone(salaryPeriod);
|
||||
salaryPeriod.isClose = !salaryPeriod.isClose;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -2127,13 +2199,16 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
"ประเภทผังปี " + Extension.ToThaiYear(salaryPeriod.year) + " ซ้ำ",
|
||||
);
|
||||
}
|
||||
|
||||
const before = null;
|
||||
salaryPeriod.period = salaryPeriod.period.toUpperCase();
|
||||
salaryPeriod.createdUserId = request.user.sub;
|
||||
salaryPeriod.createdFullName = request.user.name;
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.createdAt = new Date();
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
if (salaryPeriod.period == "SPECIAL") {
|
||||
const snapshot = "SNAP1";
|
||||
|
|
@ -2143,14 +2218,18 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
const salaryProfile = await this.salaryProfileRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||
|
||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
|
|
@ -2164,8 +2243,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -2211,13 +2293,15 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
"ประเภทผังปี " + (requestBody.effectiveDate.getFullYear() + 543) + " ซ้ำ",
|
||||
);
|
||||
}
|
||||
|
||||
const beforechk_SalaryPeriod = structuredClone(chk_SalaryPeriod);
|
||||
chk_SalaryPeriod.period = requestBody.period.toUpperCase();
|
||||
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
||||
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
||||
this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody);
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod);
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before: beforechk_SalaryPeriod, after: chk_SalaryPeriod });
|
||||
|
||||
if (chk_SalaryPeriod.period == "SPECIAL") {
|
||||
const snapshot = "SNAP1";
|
||||
const salaryOrg = await this.salaryOrgRepository.find({
|
||||
|
|
@ -2226,18 +2310,23 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
const salaryProfile = await this.salaryProfileRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||
|
||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||
|
||||
chk_SalaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod);
|
||||
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
||||
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before: beforechk_SalaryPeriod, after: chk_SalaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
const before = structuredClone(salaryOrgNew);
|
||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
|
|
@ -2247,8 +2336,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -2279,8 +2371,8 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
const salaryProfile = SalaryOrg.find((x) => x.salaryProfiles.length > 0);
|
||||
if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||
|
||||
await this.salaryOrgRepository.remove(SalaryOrg);
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
||||
await this.salaryOrgRepository.remove(SalaryOrg, { data: request });
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
|
||||
return new HttpSuccess();
|
||||
} else {
|
||||
const SalaryOrg = await this.salaryOrgRepository.findOne({
|
||||
|
|
@ -2288,7 +2380,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
});
|
||||
if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
||||
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -2397,7 +2489,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
* @param {string} rootId Guid, *Id สำนัก
|
||||
*/
|
||||
@Get("officer/approve/{periodId}/{rootId}")
|
||||
async OfficerApprove(@Path() periodId: string, rootId: string) {
|
||||
async OfficerApprove(
|
||||
@Path() periodId: string,
|
||||
rootId: string,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: periodId },
|
||||
relations: ["salaryOrgEmployees"],
|
||||
|
|
@ -2408,8 +2504,13 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryPeriod.salaryOrgEmployees
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x: any) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITHEAD1";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2423,7 +2524,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
* @param {string} rootId Guid, *Id สำนัก
|
||||
*/
|
||||
@Get("head/approve/{periodId}/{rootId}")
|
||||
async HeadApprove(@Path() periodId: string, rootId: string) {
|
||||
async HeadApprove(@Path() periodId: string, rootId: string, @Request() request: RequestWithUser) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: periodId },
|
||||
relations: ["salaryOrgEmployees"],
|
||||
|
|
@ -2435,8 +2536,13 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryPeriod.salaryOrgEmployees
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x: any) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITOWNER1";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2450,7 +2556,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
* @param {string} rootId Guid, *Id สำนัก
|
||||
*/
|
||||
@Get("owner/approve/{periodId}/{rootId}")
|
||||
async OwnerApprove(@Path() periodId: string, rootId: string) {
|
||||
async OwnerApprove(
|
||||
@Path() periodId: string,
|
||||
rootId: string,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: periodId },
|
||||
relations: ["salaryOrgEmployees"],
|
||||
|
|
@ -2462,8 +2572,13 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryPeriod.salaryOrgEmployees
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x: any) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "REPORT";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2484,7 +2599,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
body: {
|
||||
titleRecommend: string;
|
||||
},
|
||||
@Request() request: RequestWithUser
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_WAGE");
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
|
|
@ -2498,9 +2613,14 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryPeriod.salaryOrgEmployees
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x: any) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITHEAD2";
|
||||
x.ownerRecommend = body.titleRecommend;
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2521,7 +2641,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
body: {
|
||||
titleRecommend: string;
|
||||
},
|
||||
@Request() request: RequestWithUser
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_WAGE");
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
|
|
@ -2535,9 +2655,14 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
salaryPeriod.salaryOrgEmployees
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x: any) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "REPORT";
|
||||
x.ownerRecommend = body.titleRecommend;
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -14,15 +14,17 @@ import {
|
|||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { Brackets, Like } from "typeorm";
|
||||
import { Brackets } from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateSalaryRank, SalaryRanks, UpdateSalaryRank } from "../entities/SalaryRanks";
|
||||
import { Salarys } from "../entities/Salarys";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/rate")
|
||||
@Tags("SalaryRank")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -43,10 +45,11 @@ export class SalaryRanksController extends Controller {
|
|||
*/
|
||||
@Post()
|
||||
async CreateSalaryRank(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body()
|
||||
requestBody: CreateSalaryRank,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
await new permission().PermissionCreate(request, "SYS_SALARY_CHART_OFFICER");
|
||||
try {
|
||||
const checkSalary = await this.salaryRepository.findOne({
|
||||
where: { id: requestBody.salaryId },
|
||||
|
|
@ -54,12 +57,16 @@ export class SalaryRanksController extends Controller {
|
|||
if (!checkSalary) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้");
|
||||
}
|
||||
const before = null;
|
||||
const salaryRank = Object.assign(new SalaryRanks(), requestBody);
|
||||
salaryRank.createdUserId = request.user.sub;
|
||||
salaryRank.createdFullName = request.user.name;
|
||||
salaryRank.lastUpdateUserId = request.user.sub;
|
||||
salaryRank.lastUpdateFullName = request.user.name;
|
||||
await this.salaryRankRepository.save(salaryRank);
|
||||
salaryRank.createdAt = new Date();
|
||||
salaryRank.lastUpdatedAt = new Date();
|
||||
await this.salaryRankRepository.save(salaryRank, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryRank });
|
||||
return new HttpSuccess();
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
|
|
@ -75,19 +82,23 @@ export class SalaryRanksController extends Controller {
|
|||
*/
|
||||
@Put("{id}")
|
||||
async updateSalaryRanks(
|
||||
@Request() request: RequestWithUser,
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdateSalaryRank,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_SALARY_CHART_OFFICER");
|
||||
const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } });
|
||||
if (!salaryRank) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้");
|
||||
}
|
||||
const before = structuredClone(salaryRank);
|
||||
salaryRank.lastUpdateUserId = request.user.sub;
|
||||
salaryRank.lastUpdateFullName = request.user.name;
|
||||
salaryRank.lastUpdatedAt = new Date();
|
||||
this.salaryRankRepository.merge(salaryRank, requestBody);
|
||||
await this.salaryRankRepository.save(salaryRank);
|
||||
await this.salaryRankRepository.save(salaryRank, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryRank });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +110,8 @@ export class SalaryRanksController extends Controller {
|
|||
* @param {string} id Id อัตราเงินเดือน
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteSalaryRanks(@Path() id: string) {
|
||||
async deleteSalaryRanks(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
await new permission().PermissionDelete(request, "SYS_SALARY_CHART_OFFICER");
|
||||
const delSalaryRanks = await this.salaryRankRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
|
|
@ -119,13 +131,14 @@ export class SalaryRanksController extends Controller {
|
|||
*/
|
||||
@Get("{id}")
|
||||
async listSalaryRanks(
|
||||
@Request() request: RequestWithUser,
|
||||
@Path() id: string,
|
||||
@Request() req: RequestWithUser,
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
await new permission().PermissionGet(req, "SYS_SALARY_CHART_OFFICER");
|
||||
await new permission().PermissionGet(request, "SYS_SALARY_CHART_OFFICER");
|
||||
const [salaryRank, total] = await AppDataSource.getRepository(SalaryRanks)
|
||||
.createQueryBuilder("salaryRank")
|
||||
.andWhere(
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import {
|
|||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { Not, Like, Brackets } from "typeorm";
|
||||
import { Not, Brackets } from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -27,6 +27,8 @@ import {
|
|||
import { SalaryEmployee } from "../entities/SalaryEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/rate/employee")
|
||||
@Tags("SalaryRankEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -46,10 +48,11 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
*/
|
||||
@Post()
|
||||
async CreateSalaryRankEmployee(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body()
|
||||
requestBody: CreateSalaryRankEmployee,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
await new permission().PermissionCreate(request, "SYS_WAGE_CHART_EMP");
|
||||
try {
|
||||
const checkSalary = await this.salaryEmployeeRepository.findOne({
|
||||
where: { id: requestBody.salaryEmployeeId },
|
||||
|
|
@ -67,11 +70,15 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเพิ่มได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
|
||||
}
|
||||
const salaryRankEmployee = Object.assign(new SalaryRankEmployee(), requestBody);
|
||||
const before = null;
|
||||
salaryRankEmployee.createdUserId = request.user.sub;
|
||||
salaryRankEmployee.createdFullName = request.user.name;
|
||||
salaryRankEmployee.lastUpdateUserId = request.user.sub;
|
||||
salaryRankEmployee.lastUpdateFullName = request.user.name;
|
||||
await this.salaryRankEmployeeRepository.save(salaryRankEmployee);
|
||||
salaryRankEmployee.createdAt = new Date();
|
||||
salaryRankEmployee.lastUpdatedAt = new Date();
|
||||
await this.salaryRankEmployeeRepository.save(salaryRankEmployee, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryRankEmployee });
|
||||
return new HttpSuccess();
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
|
|
@ -86,11 +93,12 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
*/
|
||||
@Put("{id}")
|
||||
async updateSalaryRankEmployees(
|
||||
@Request() request: RequestWithUser,
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdateSalaryRankEmployee,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_WAGE_CHART_EMP");
|
||||
const salaryRankEmployee = await this.salaryRankEmployeeRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
|
|
@ -107,10 +115,13 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
if (checkStep.length > 0) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถแก้ไขได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
|
||||
}
|
||||
const before = structuredClone(salaryRankEmployee);
|
||||
salaryRankEmployee.lastUpdateUserId = request.user.sub;
|
||||
salaryRankEmployee.lastUpdateFullName = request.user.name;
|
||||
salaryRankEmployee.lastUpdatedAt = new Date();
|
||||
this.salaryRankEmployeeRepository.merge(salaryRankEmployee, requestBody);
|
||||
await this.salaryRankEmployeeRepository.save(salaryRankEmployee);
|
||||
await this.salaryRankEmployeeRepository.save(salaryRankEmployee, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryRankEmployee });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +132,8 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
* @param {string} id Id อัตราเงินเดือน
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteSalaryRankEmployees(@Path() id: string) {
|
||||
async deleteSalaryRankEmployees(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
await new permission().PermissionDelete(request, "SYS_WAGE_CHART_EMP");
|
||||
const delSalaryRankEmployees = await this.salaryRankEmployeeRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,45 @@
|
|||
import "dotenv/config";
|
||||
import "reflect-metadata";
|
||||
import { DataSource } from "typeorm";
|
||||
import { DataSource, LogLevel, LogMessage, QueryRunner } from "typeorm";
|
||||
import { Logger } from "typeorm";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { addLogSequence } from "../interfaces/utils";
|
||||
|
||||
export class MyCustomLogger implements Logger {
|
||||
log(level: "log" | "info" | "warn", message: any, queryRunner?: QueryRunner) {}
|
||||
|
||||
logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner): void {
|
||||
const req = queryRunner?.data as RequestWithUser;
|
||||
if (req?.app?.locals.logData?.sequence) {
|
||||
addLogSequence(req, {
|
||||
action: "database",
|
||||
status: "success",
|
||||
description: "Query Data.",
|
||||
query: [
|
||||
"Query: " + query + (parameters ? " - Parameters:" + JSON.stringify(parameters) : ""),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
// const req = queryRunner?.data as RequestWithUser | undefined;
|
||||
// const logData = req?.app?.locals.logData?.sequence?.at(-1);
|
||||
|
||||
// if (logData && !logData.query) logData.query = [];
|
||||
// if (logData) logData.query.push(
|
||||
// "Query: " + query + (parameters ? (" - Parameters:" + JSON.stringify(parameters)) : '')
|
||||
// );
|
||||
}
|
||||
|
||||
logMigration(message: string, queryRunner?: QueryRunner) {}
|
||||
logQueryError(
|
||||
error: string | Error,
|
||||
query: string,
|
||||
parameters?: any[],
|
||||
queryRunner?: QueryRunner,
|
||||
) {}
|
||||
logQuerySlow(time: number, query: string, parameters?: any[], queryRunner?: QueryRunner) {}
|
||||
logSchemaBuild(message: string, queryRunner?: QueryRunner) {}
|
||||
}
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
type: "mysql",
|
||||
|
|
@ -11,7 +50,7 @@ export const AppDataSource = new DataSource({
|
|||
password: process.env.DB_PASSWORD,
|
||||
connectorPackage: "mysql2",
|
||||
synchronize: false,
|
||||
logging: true,
|
||||
logging: ["query", "error"],
|
||||
entities:
|
||||
process.env.NODE_ENV !== "production"
|
||||
? ["src/entities/**/*.ts"]
|
||||
|
|
@ -21,7 +60,5 @@ export const AppDataSource = new DataSource({
|
|||
? ["src/migration/**/*.ts"]
|
||||
: ["dist/migration/**/*{.ts,.js}"],
|
||||
subscribers: [],
|
||||
logger: new MyCustomLogger(),
|
||||
});
|
||||
// console.log(AppDataSource);
|
||||
|
||||
// export default database;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
Path,
|
||||
} from "tsoa";
|
||||
import axios from "axios";
|
||||
import { addLogSequence } from "./utils";
|
||||
|
||||
class CallAPI {
|
||||
//Get
|
||||
|
|
@ -26,8 +27,28 @@ class CallAPI {
|
|||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "success",
|
||||
description: "connected",
|
||||
request: {
|
||||
method: "GET",
|
||||
url: url,
|
||||
response: JSON.stringify(response.data.result),
|
||||
},
|
||||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "GET",
|
||||
url: url,
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,8 +64,30 @@ class CallAPI {
|
|||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "success",
|
||||
description: "connected",
|
||||
request: {
|
||||
method: "POST",
|
||||
url: url,
|
||||
payload: JSON.stringify(sendData),
|
||||
response: JSON.stringify(response.data.result),
|
||||
},
|
||||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "POST",
|
||||
url: url,
|
||||
payload: JSON.stringify(sendData),
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,3 @@
|
|||
import {
|
||||
Controller,
|
||||
Request,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Path,
|
||||
} from "tsoa";
|
||||
import axios from "axios";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import CallAPI from "./call-api";
|
||||
|
|
@ -26,23 +13,155 @@ class CheckAuth {
|
|||
) {
|
||||
return null;
|
||||
}
|
||||
await new CallAPI()
|
||||
return await new CallAPI()
|
||||
.GetData(req, "/org/permission")
|
||||
.then((x) => {
|
||||
let permission = false;
|
||||
let role = x.roles.find((x: any) => x.authSysId == system);
|
||||
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
|
||||
if (role.attrOwnership == "OWNER") return "OWNER";
|
||||
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate;
|
||||
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete;
|
||||
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet;
|
||||
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList;
|
||||
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate;
|
||||
if (role.attrOwnership == "OWNER") permission = true;
|
||||
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
|
||||
return role.attrPrivilege;
|
||||
})
|
||||
.catch((x) => {
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||
if (x.status != undefined) {
|
||||
throw new HttpError(x.status, x.message);
|
||||
} else {
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||
}
|
||||
});
|
||||
}
|
||||
public async PermissionOrg(req: RequestWithUser, system: string, action: string) {
|
||||
if (
|
||||
req.headers.hasOwnProperty("api_key") &&
|
||||
req.headers["api_key"] &&
|
||||
req.headers["api_key"] == process.env.API_KEY
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return await new CallAPI()
|
||||
.GetData(req, `/org/permission/org/${action}/${system}`)
|
||||
.then(async (x) => {
|
||||
let privilege = x.privilege;
|
||||
let data: any = {
|
||||
root: [null],
|
||||
child1: [null],
|
||||
child2: [null],
|
||||
child3: [null],
|
||||
child4: [null],
|
||||
};
|
||||
let node = 4;
|
||||
if (x.orgChild1Id == null) {
|
||||
node = 0;
|
||||
} else if (x.orgChild2Id == null) {
|
||||
node = 1;
|
||||
} else if (x.orgChild3Id == null) {
|
||||
node = 2;
|
||||
} else if (x.orgChild4Id == null) {
|
||||
node = 3;
|
||||
}
|
||||
if (privilege == "ROOT") {
|
||||
data = {
|
||||
root: [x.orgRootId],
|
||||
child1: null,
|
||||
child2: null,
|
||||
child3: null,
|
||||
child4: null,
|
||||
};
|
||||
} else if (privilege == "CHILD") {
|
||||
data = {
|
||||
root: node >= 0 ? [x.orgRootId] : null,
|
||||
child1: node >= 1 ? [x.orgChild1Id] : null,
|
||||
child2: node >= 2 ? [x.orgChild2Id] : null,
|
||||
child3: node >= 3 ? [x.orgChild3Id] : null,
|
||||
child4: node >= 4 ? [x.orgChild4Id] : null,
|
||||
};
|
||||
} else if (privilege == "NORMAL") {
|
||||
data = {
|
||||
root: [x.orgRootId],
|
||||
child1: [x.orgChild1Id],
|
||||
child2: [x.orgChild2Id],
|
||||
child3: [x.orgChild3Id],
|
||||
child4: [x.orgChild4Id],
|
||||
};
|
||||
} else if (privilege == "SPECIFIC") {
|
||||
} else if (privilege == "OWNER") {
|
||||
data = {
|
||||
root: null,
|
||||
child1: null,
|
||||
child2: null,
|
||||
child3: null,
|
||||
child4: null,
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
})
|
||||
.catch((x) => {
|
||||
if (x.status != undefined) {
|
||||
throw new HttpError(x.status, x.message);
|
||||
} else {
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||
}
|
||||
});
|
||||
}
|
||||
public async PermissionOrgByUser(
|
||||
req: RequestWithUser,
|
||||
system: string,
|
||||
action: string,
|
||||
profileId: string,
|
||||
) {
|
||||
if (
|
||||
req.headers.hasOwnProperty("api_key") &&
|
||||
req.headers["api_key"] &&
|
||||
req.headers["api_key"] == process.env.API_KEY
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return await new CallAPI()
|
||||
.GetData(req, `/org/permission/user/${profileId}`)
|
||||
.then(async (x) => {
|
||||
let org = {
|
||||
root: [null],
|
||||
child1: [null],
|
||||
child2: [null],
|
||||
child3: [null],
|
||||
child4: [null],
|
||||
};
|
||||
if (action.trim().toLocaleUpperCase() == "CREATE")
|
||||
org = await this.PermissionOrgCreate(req, system);
|
||||
if (action.trim().toLocaleUpperCase() == "DELETE")
|
||||
org = await this.PermissionOrgDelete(req, system);
|
||||
if (action.trim().toLocaleUpperCase() == "GET")
|
||||
org = await this.PermissionOrgGet(req, system);
|
||||
if (action.trim().toLocaleUpperCase() == "LIST")
|
||||
org = await this.PermissionOrgList(req, system);
|
||||
if (action.trim().toLocaleUpperCase() == "UPDATE")
|
||||
org = await this.PermissionOrgUpdate(req, system);
|
||||
|
||||
if (org.root != null) if (x.orgRootId != org.root[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||
if (org.child1 != null)
|
||||
if (x.orgChild1Id != org.child1[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||
if (org.child2 != null)
|
||||
if (x.orgChild2Id != org.child2[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||
if (org.child3 != null)
|
||||
if (x.orgChild3Id != org.child3[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||
if (org.child4 != null)
|
||||
if (x.orgChild4Id != org.child4[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||
|
||||
return true;
|
||||
})
|
||||
.catch((x) => {
|
||||
if (x.status != undefined) {
|
||||
throw new HttpError(x.status, x.message);
|
||||
} else {
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||
}
|
||||
});
|
||||
}
|
||||
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||
|
|
@ -60,6 +179,38 @@ class CheckAuth {
|
|||
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
||||
return await this.Permission(req, system, "UPDATE");
|
||||
}
|
||||
|
||||
public async PermissionOrgCreate(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "CREATE");
|
||||
}
|
||||
public async PermissionOrgDelete(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "DELETE");
|
||||
}
|
||||
public async PermissionOrgGet(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "GET");
|
||||
}
|
||||
public async PermissionOrgList(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "LIST");
|
||||
}
|
||||
public async PermissionOrgUpdate(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "UPDATE");
|
||||
}
|
||||
|
||||
public async PermissionOrgUserCreate(req: RequestWithUser, system: string, profileId: string) {
|
||||
return await this.PermissionOrgByUser(req, system, "CREATE", profileId);
|
||||
}
|
||||
public async PermissionOrgUserDelete(req: RequestWithUser, system: string, profileId: string) {
|
||||
return await this.PermissionOrgByUser(req, system, "DELETE", profileId);
|
||||
}
|
||||
public async PermissionOrgUserGet(req: RequestWithUser, system: string, profileId: string) {
|
||||
return await this.PermissionOrgByUser(req, system, "GET", profileId);
|
||||
}
|
||||
public async PermissionOrgUserList(req: RequestWithUser, system: string, profileId: string) {
|
||||
return await this.PermissionOrgByUser(req, system, "LIST", profileId);
|
||||
}
|
||||
public async PermissionOrgUserUpdate(req: RequestWithUser, system: string, profileId: string) {
|
||||
return await this.PermissionOrgByUser(req, system, "UPDATE", profileId);
|
||||
}
|
||||
}
|
||||
|
||||
export default CheckAuth;
|
||||
|
|
|
|||
37
src/interfaces/utils.ts
Normal file
37
src/interfaces/utils.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
export type DataDiff = {
|
||||
before: any;
|
||||
after: any;
|
||||
};
|
||||
|
||||
export type LogSequence = {
|
||||
action: string;
|
||||
status: "success" | "error";
|
||||
description: string;
|
||||
query?: any;
|
||||
request?: {
|
||||
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
||||
url?: string;
|
||||
payload?: string;
|
||||
response?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export function setLogDataDiff(req: RequestWithUser, data: DataDiff) {
|
||||
req.app.locals.logData.dataDiff = {
|
||||
before: JSON.stringify(data.before),
|
||||
after: JSON.stringify(data.after),
|
||||
};
|
||||
}
|
||||
|
||||
export function addLogSequence(req: RequestWithUser, data: LogSequence) {
|
||||
if (!req?.app?.locals?.logData?.sequence) {
|
||||
req.app.locals.logData.sequence = [];
|
||||
}
|
||||
req.app.locals.logData.sequence = req.app.locals.logData.sequence.concat(data);
|
||||
}
|
||||
|
||||
export function editLogSequence(req: RequestWithUser, index: number, data: LogSequence) {
|
||||
req.app.locals.logData.sequence[index] = data;
|
||||
}
|
||||
|
|
@ -3,15 +3,13 @@ import { createDecoder, createVerifier } from "fast-jwt";
|
|||
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import { addLogSequence } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "./user";
|
||||
|
||||
if (!process.env.AUTH_PUBLIC_KEY && !process.env.AUTH_REALM_URL) {
|
||||
throw new Error("Require keycloak AUTH_PUBLIC_KEY or AUTH_REALM_URL.");
|
||||
}
|
||||
if (
|
||||
process.env.AUTH_PUBLIC_KEY &&
|
||||
process.env.AUTH_REALM_URL &&
|
||||
!process.env.AUTH_PREFERRED_MODE
|
||||
) {
|
||||
if (process.env.AUTH_PUBLIC_KEY && process.env.AUTH_REALM_URL && !process.env.AUTH_PREFERRED_MODE) {
|
||||
throw new Error(
|
||||
"AUTH_PREFFERRED must be specified if AUTH_PUBLIC_KEY and AUTH_REALM_URL is provided.",
|
||||
);
|
||||
|
|
@ -26,7 +24,7 @@ const jwtVerify = createVerifier({
|
|||
const jwtDecode = createDecoder();
|
||||
|
||||
export async function expressAuthentication(
|
||||
request: express.Request,
|
||||
request: RequestWithUser,
|
||||
securityName: string,
|
||||
_scopes?: string[],
|
||||
) {
|
||||
|
|
@ -56,6 +54,18 @@ export async function expressAuthentication(
|
|||
if (process.env.AUTH_PUBLIC_KEY) payload = await verifyOffline(token);
|
||||
break;
|
||||
}
|
||||
if (!request.app.locals.logData) {
|
||||
request.app.locals.logData = {};
|
||||
}
|
||||
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Query Data.",
|
||||
// });
|
||||
request.app.locals.logData.userId = payload.sub;
|
||||
request.app.locals.logData.userName = payload.name;
|
||||
request.app.locals.logData.user = payload.preferred_username;
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@ import HttpStatus from "../interfaces/http-status";
|
|||
import { ValidateError } from "tsoa";
|
||||
|
||||
function error(error: Error, _req: Request, res: Response, _next: NextFunction) {
|
||||
const logData = _req.app.locals.logData.sequence?.at(-1);
|
||||
if (logData) {
|
||||
logData.status = "error";
|
||||
logData.description = error.message;
|
||||
}
|
||||
|
||||
if (error instanceof HttpError) {
|
||||
return res.status(error.status).json({
|
||||
status: error.status,
|
||||
|
|
|
|||
74
src/middlewares/logs.ts
Normal file
74
src/middlewares/logs.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import { NextFunction, Request, Response } from "express";
|
||||
import { Client } from "@elastic/elasticsearch";
|
||||
|
||||
if (!process.env.ELASTICSEARCH_INDEX) {
|
||||
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
|
||||
}
|
||||
|
||||
const ELASTICSEARCH_INDEX = process.env.ELASTICSEARCH_INDEX;
|
||||
|
||||
const LOG_LEVEL_MAP: Record<string, number> = {
|
||||
debug: 4,
|
||||
info: 3,
|
||||
warning: 2,
|
||||
error: 1,
|
||||
none: 0,
|
||||
};
|
||||
|
||||
const elasticsearch = new Client({
|
||||
node: `${process.env.ELASTICSEARCH_PROTOCOL}://${process.env.ELASTICSEARCH_HOST}:${process.env.ELASTICSEARCH_PORT}`,
|
||||
});
|
||||
|
||||
async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||
if (!req.url.startsWith("/api/")) return next();
|
||||
|
||||
let data: any;
|
||||
|
||||
const originalJson = res.json;
|
||||
|
||||
res.json = function (v: any) {
|
||||
data = v;
|
||||
return originalJson.call(this, v);
|
||||
};
|
||||
|
||||
const timestamp = new Date().toISOString();
|
||||
const start = performance.now();
|
||||
|
||||
req.app.locals.logData = {};
|
||||
|
||||
res.on("finish", () => {
|
||||
if (!req.url.startsWith("/api/")) return;
|
||||
|
||||
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
|
||||
|
||||
if (level === 1 && res.statusCode < 500) return;
|
||||
if (level === 2 && res.statusCode < 400) return;
|
||||
if (level === 3 && res.statusCode < 200) return;
|
||||
|
||||
const obj = {
|
||||
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
||||
ip: req.ip,
|
||||
systemName: "salary",
|
||||
startTimeStamp: timestamp,
|
||||
endTimeStamp: new Date().toISOString(),
|
||||
processTime: performance.now() - start,
|
||||
host: req.hostname,
|
||||
method: req.method,
|
||||
endpoint: req.url,
|
||||
responseCode: String(res.statusCode === 304 ? 200 : res.statusCode),
|
||||
responseDescription: data?.message,
|
||||
input: (level === 4 && JSON.stringify(req.body, null, 2)) || undefined,
|
||||
output: (level === 4 && JSON.stringify(data, null, 2)) || undefined,
|
||||
...req.app.locals.logData,
|
||||
};
|
||||
|
||||
elasticsearch.index({
|
||||
index: ELASTICSEARCH_INDEX,
|
||||
document: obj,
|
||||
});
|
||||
});
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
export default logMiddleware;
|
||||
Loading…
Add table
Add a link
Reference in a new issue