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
10251
package-lock.json
generated
10251
package-lock.json
generated
File diff suppressed because it is too large
Load diff
90
package.json
90
package.json
|
|
@ -1,45 +1,49 @@
|
||||||
{
|
{
|
||||||
"name": "template",
|
"name": "template",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/app.js",
|
"main": "src/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon",
|
"dev": "nodemon",
|
||||||
"check": "tsc --noEmit",
|
"check": "tsc --noEmit",
|
||||||
"start": "node ./dist/app.js",
|
"start": "node ./dist/app.js",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"build": "tsoa spec-and-routes && tsc",
|
"build": "tsoa spec-and-routes && tsc",
|
||||||
"migration:generate": "typeorm-ts-node-commonjs migration:generate -d src/database/data-source.ts",
|
"migration:generate": "typeorm-ts-node-commonjs migration:generate -d src/database/data-source.ts",
|
||||||
"migration:run": "typeorm-ts-node-commonjs migration:run -d src/database/data-source.ts"
|
"migration:run": "typeorm-ts-node-commonjs migration:run -d src/database/data-source.ts"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cors": "^2.8.17",
|
"@types/cors": "^2.8.17",
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/node": "^20.11.5",
|
"@types/node": "^20.11.5",
|
||||||
"@types/node-cron": "^3.0.11",
|
"@types/node-cron": "^3.0.11",
|
||||||
"@types/swagger-ui-express": "^4.1.6",
|
"@types/swagger-ui-express": "^4.1.6",
|
||||||
"nodemon": "^3.0.3",
|
"nodemon": "^3.0.3",
|
||||||
"prettier": "^3.2.2",
|
"prettier": "^3.2.2",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.3.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tsoa/runtime": "^6.0.0",
|
"@elastic/elasticsearch": "^8.14.0",
|
||||||
"axios": "^1.6.7",
|
"@nestjs/platform-express": "^10.3.7",
|
||||||
"cors": "^2.8.5",
|
"@tsoa/runtime": "^6.0.0",
|
||||||
"dotenv": "^16.3.1",
|
"axios": "^1.6.8",
|
||||||
"express": "^4.18.2",
|
"cors": "^2.8.5",
|
||||||
"fast-jwt": "^3.3.2",
|
"dotenv": "^16.3.1",
|
||||||
"mysql2": "^3.9.1",
|
"express": "^4.18.2",
|
||||||
"node-cron": "^3.0.3",
|
"fast-jwt": "^3.3.2",
|
||||||
"promise.any": "^2.0.6",
|
"multer": "^1.4.5-lts.1",
|
||||||
"reflect-metadata": "^0.2.1",
|
"mysql2": "^3.9.1",
|
||||||
"swagger-ui-express": "^5.0.0",
|
"node-cron": "^3.0.3",
|
||||||
"tsoa": "^6.0.1",
|
"promise.any": "^2.0.6",
|
||||||
"typeorm": "^0.3.19",
|
"reflect-metadata": "^0.2.1",
|
||||||
"typeorm-cli": "^1.0.7"
|
"swagger-ui-express": "^5.0.0",
|
||||||
}
|
"tsoa": "^6.0.1",
|
||||||
|
"typeorm": "^0.3.19",
|
||||||
|
"typeorm-cli": "^1.0.7",
|
||||||
|
"xlsx": "^0.18.5"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ import error from "./middlewares/error";
|
||||||
import { AppDataSource } from "./database/data-source";
|
import { AppDataSource } from "./database/data-source";
|
||||||
import { RegisterRoutes } from "./routes";
|
import { RegisterRoutes } from "./routes";
|
||||||
import { SalaryPeriodController } from "./controllers/SalaryPeriodController";
|
import { SalaryPeriodController } from "./controllers/SalaryPeriodController";
|
||||||
|
import logMiddleware from "./middlewares/logs";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await AppDataSource.initialize();
|
await AppDataSource.initialize();
|
||||||
|
|
@ -23,6 +24,7 @@ async function main() {
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
app.use("/", express.static("static"));
|
app.use("/", express.static("static"));
|
||||||
|
app.use(logMiddleware);
|
||||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||||
|
|
||||||
RegisterRoutes(app);
|
RegisterRoutes(app);
|
||||||
|
|
@ -35,7 +37,6 @@ async function main() {
|
||||||
try {
|
try {
|
||||||
const salaryPeriod = new SalaryPeriodController();
|
const salaryPeriod = new SalaryPeriodController();
|
||||||
await salaryPeriod.CronjobSalaryPeriod();
|
await salaryPeriod.CronjobSalaryPeriod();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error executing function from controller:", error);
|
console.error("Error executing function from controller:", error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,4 @@
|
||||||
import {
|
import { Controller, Request, Get, Route, Security, Tags } from "tsoa";
|
||||||
Controller,
|
|
||||||
Request,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Delete,
|
|
||||||
Patch,
|
|
||||||
Route,
|
|
||||||
Security,
|
|
||||||
Tags,
|
|
||||||
Path,
|
|
||||||
} from "tsoa";
|
|
||||||
import axios from "axios";
|
|
||||||
import CallAPI from "../interfaces/call-api";
|
import CallAPI from "../interfaces/call-api";
|
||||||
|
|
||||||
@Route("/hello")
|
@Route("/hello")
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import {
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Delete,
|
Delete,
|
||||||
Patch,
|
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
|
|
@ -14,7 +13,6 @@ import {
|
||||||
Example,
|
Example,
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -23,6 +21,8 @@ import { PosType } from "../entities/PosType";
|
||||||
import { PosLevel, CreatePosLevel, UpdatePosLevel } from "../entities/PosLevel";
|
import { PosLevel, CreatePosLevel, UpdatePosLevel } from "../entities/PosLevel";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { Not } from "typeorm";
|
import { Not } from "typeorm";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary/pos/level")
|
@Route("api/v1/salary/pos/level")
|
||||||
@Tags("PosLevel")
|
@Tags("PosLevel")
|
||||||
|
|
@ -52,7 +52,7 @@ export class PosLevelController extends Controller {
|
||||||
async createLevel(
|
async createLevel(
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: CreatePosLevel,
|
requestBody: CreatePosLevel,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
const posLevel = Object.assign(new PosLevel(), requestBody);
|
const posLevel = Object.assign(new PosLevel(), requestBody);
|
||||||
if (!posLevel) {
|
if (!posLevel) {
|
||||||
|
|
@ -64,10 +64,7 @@ export class PosLevelController extends Controller {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!chkPosTypeId) {
|
if (!chkPosTypeId) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ไม่พบข้อมูลประเภทตำแหน่งนี้"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const chkPosLevelName = await this.posLevelRepository.findOne({
|
const chkPosLevelName = await this.posLevelRepository.findOne({
|
||||||
|
|
@ -92,11 +89,15 @@ export class PosLevelController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
|
const before = null;
|
||||||
posLevel.createdUserId = request.user.sub;
|
posLevel.createdUserId = request.user.sub;
|
||||||
posLevel.createdFullName = request.user.name;
|
posLevel.createdFullName = request.user.name;
|
||||||
posLevel.lastUpdateUserId = request.user.sub;
|
posLevel.lastUpdateUserId = request.user.sub;
|
||||||
posLevel.lastUpdateFullName = request.user.name;
|
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);
|
return new HttpSuccess(posLevel);
|
||||||
// } catch (error) {
|
// } catch (error) {
|
||||||
// return error;
|
// return error;
|
||||||
|
|
@ -118,7 +119,7 @@ export class PosLevelController extends Controller {
|
||||||
async editLevel(
|
async editLevel(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() requestBody: UpdatePosLevel,
|
@Body() requestBody: UpdatePosLevel,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
const posLevel = await this.posLevelRepository.findOne({ where: { id } });
|
const posLevel = await this.posLevelRepository.findOne({ where: { id } });
|
||||||
if (!posLevel) {
|
if (!posLevel) {
|
||||||
|
|
@ -131,10 +132,7 @@ export class PosLevelController extends Controller {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!chkPosTypeId) {
|
if (!chkPosTypeId) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ไม่พบข้อมูลระดับตำแหน่งนี้"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const chkPosLevelName = await this.posLevelRepository.findOne({
|
const chkPosLevelName = await this.posLevelRepository.findOne({
|
||||||
|
|
@ -159,10 +157,13 @@ export class PosLevelController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
|
const before = structuredClone(posLevel);
|
||||||
posLevel.lastUpdateUserId = request.user.sub;
|
posLevel.lastUpdateUserId = request.user.sub;
|
||||||
posLevel.lastUpdateFullName = request.user.name;
|
posLevel.lastUpdateFullName = request.user.name;
|
||||||
|
posLevel.lastUpdatedAt = new Date();
|
||||||
this.posLevelRepository.merge(posLevel, requestBody);
|
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);
|
return new HttpSuccess(posLevel.id);
|
||||||
// } catch (error) {
|
// } catch (error) {
|
||||||
// return error;
|
// return error;
|
||||||
|
|
@ -177,13 +178,13 @@ export class PosLevelController extends Controller {
|
||||||
* @param {string} id Id ระดับตำแหน่ง
|
* @param {string} id Id ระดับตำแหน่ง
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteLevel(@Path() id: string) {
|
async deleteLevel(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
const delPosLevel = await this.posLevelRepository.findOne({ where: { id } });
|
const delPosLevel = await this.posLevelRepository.findOne({ where: { id } });
|
||||||
if (!delPosLevel) {
|
if (!delPosLevel) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
|
||||||
}
|
}
|
||||||
// try {
|
// try {
|
||||||
await this.posLevelRepository.remove(delPosLevel);
|
await this.posLevelRepository.remove(delPosLevel, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
// } catch (error) {
|
// } catch (error) {
|
||||||
// return error;
|
// return error;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import {
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Delete,
|
Delete,
|
||||||
Patch,
|
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
|
|
@ -14,7 +13,6 @@ import {
|
||||||
Example,
|
Example,
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -23,6 +21,8 @@ import { PosType, CreatePosType, UpdatePosType } from "../entities/PosType";
|
||||||
import { PosLevel } from "../entities/PosLevel";
|
import { PosLevel } from "../entities/PosLevel";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { Not } from "typeorm";
|
import { Not } from "typeorm";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary/pos/type")
|
@Route("api/v1/salary/pos/type")
|
||||||
@Tags("PosType")
|
@Tags("PosType")
|
||||||
|
|
@ -50,7 +50,7 @@ export class PosTypeController extends Controller {
|
||||||
async createType(
|
async createType(
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: CreatePosType,
|
requestBody: CreatePosType,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
const posType = Object.assign(new PosType(), requestBody);
|
const posType = Object.assign(new PosType(), requestBody);
|
||||||
if (!posType) {
|
if (!posType) {
|
||||||
|
|
@ -68,11 +68,15 @@ export class PosTypeController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// try {
|
// try {
|
||||||
|
const before = null;
|
||||||
posType.createdUserId = request.user.sub;
|
posType.createdUserId = request.user.sub;
|
||||||
posType.createdFullName = request.user.name;
|
posType.createdFullName = request.user.name;
|
||||||
posType.lastUpdateUserId = request.user.sub;
|
posType.lastUpdateUserId = request.user.sub;
|
||||||
posType.lastUpdateFullName = request.user.name;
|
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);
|
return new HttpSuccess(posType);
|
||||||
// } catch (error) {
|
// } catch (error) {
|
||||||
// return error;
|
// return error;
|
||||||
|
|
@ -94,7 +98,7 @@ export class PosTypeController extends Controller {
|
||||||
async editType(
|
async editType(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() requestBody: UpdatePosType,
|
@Body() requestBody: UpdatePosType,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
const posType = await this.posTypeRepository.findOne({ where: { id } });
|
const posType = await this.posTypeRepository.findOne({ where: { id } });
|
||||||
if (!posType) {
|
if (!posType) {
|
||||||
|
|
@ -113,10 +117,13 @@ export class PosTypeController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// try {
|
// try {
|
||||||
|
const before = structuredClone(posType);
|
||||||
posType.lastUpdateUserId = request.user.sub;
|
posType.lastUpdateUserId = request.user.sub;
|
||||||
posType.lastUpdateFullName = request.user.name;
|
posType.lastUpdateFullName = request.user.name;
|
||||||
|
posType.lastUpdatedAt = new Date();
|
||||||
this.posTypeRepository.merge(posType, requestBody);
|
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);
|
return new HttpSuccess(posType.id);
|
||||||
// } catch (error) {
|
// } catch (error) {
|
||||||
// return error;
|
// return error;
|
||||||
|
|
@ -131,7 +138,7 @@ export class PosTypeController extends Controller {
|
||||||
* @param {string} id Id ตำแหน่ง
|
* @param {string} id Id ตำแหน่ง
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteType(@Path() id: string) {
|
async deleteType(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
const delPosType = await this.posTypeRepository.findOne({ where: { id } });
|
const delPosType = await this.posTypeRepository.findOne({ where: { id } });
|
||||||
if (!delPosType) {
|
if (!delPosType) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||||
|
|
@ -144,7 +151,7 @@ export class PosTypeController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
await this.posTypeRepository.remove(delPosType);
|
await this.posTypeRepository.remove(delPosType, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
// } catch (error) {
|
// } catch (error) {
|
||||||
// return error;
|
// return error;
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,14 @@ import {
|
||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
|
||||||
Delete,
|
|
||||||
Patch,
|
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -35,6 +30,9 @@ import { EmployeePosType } from "../entities/EmployeePosType";
|
||||||
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
|
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
|
||||||
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
|
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
|
||||||
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
|
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
|
||||||
import CallAPI from "../interfaces/call-api";
|
import CallAPI from "../interfaces/call-api";
|
||||||
@Route("api/v1/salary/report")
|
@Route("api/v1/salary/report")
|
||||||
@Tags("Report")
|
@Tags("Report")
|
||||||
|
|
@ -51,9 +49,7 @@ export class ReportController extends Controller {
|
||||||
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
|
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
|
||||||
private salaryEmployeeRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
|
private salaryEmployeeRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
|
||||||
private poTypeRepository = AppDataSource.getRepository(PosType);
|
private poTypeRepository = AppDataSource.getRepository(PosType);
|
||||||
private poTypeEmployeeRepository = AppDataSource.getRepository(EmployeePosType);
|
|
||||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||||
private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel);
|
|
||||||
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
|
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
|
||||||
private salaryOrgEmployeeRepository = AppDataSource.getRepository(SalaryOrgEmployee);
|
private salaryOrgEmployeeRepository = AppDataSource.getRepository(SalaryOrgEmployee);
|
||||||
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
|
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,
|
// no: index + 1,
|
||||||
// id: item.id,
|
// id: item.id,
|
||||||
salary: item.salary == null || item.salary == 0 ? "" : item.salary.toLocaleString(),
|
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(),
|
step: item.step == null || item.step == 0 ? "" : item.step.toLocaleString(),
|
||||||
salaryMonth:
|
salaryMonth:
|
||||||
item.salaryMonth == null || item.salaryMonth == 0 ? "" : item.salaryMonth.toLocaleString(),
|
item.salaryMonth == null || item.salaryMonth == 0 ? "" : item.salaryMonth.toLocaleString(),
|
||||||
|
|
@ -2114,8 +2110,10 @@ export class ReportController extends Controller {
|
||||||
(item.root == undefined && item.root == null ? "" : item.root),
|
(item.root == undefined && item.root == null ? "" : item.root),
|
||||||
posType: item.posType,
|
posType: item.posType,
|
||||||
posLevel: item.posLevel,
|
posLevel: item.posLevel,
|
||||||
posExecutive: item.posExecutive ? item.posExecutive:null,
|
posExecutive: item.posExecutive ? item.posExecutive : null,
|
||||||
fullPositionName: item.posExecutive ? item.position + " (" + item.posExecutive + ")" : item.position || null,
|
fullPositionName: item.posExecutive
|
||||||
|
? item.position + " (" + item.posExecutive + ")"
|
||||||
|
: item.position || null,
|
||||||
posMasterNo:
|
posMasterNo:
|
||||||
Extension.ToThaiNumber(item.orgShortName) +
|
Extension.ToThaiNumber(item.orgShortName) +
|
||||||
Extension.ToThaiNumber(String(item.posMasterNo.toLocaleString())),
|
Extension.ToThaiNumber(String(item.posMasterNo.toLocaleString())),
|
||||||
|
|
@ -4186,8 +4184,8 @@ export class ReportController extends Controller {
|
||||||
reportName: "emp2-02",
|
reportName: "emp2-02",
|
||||||
data: {
|
data: {
|
||||||
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
|
||||||
yearOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1))),
|
yearOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 1))),
|
||||||
yearOld2: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-2))),
|
yearOld2: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 2))),
|
||||||
agency: _root?.root == null ? "" : _root?.root,
|
agency: _root?.root == null ? "" : _root?.root,
|
||||||
data: formattedData,
|
data: formattedData,
|
||||||
},
|
},
|
||||||
|
|
@ -4694,7 +4692,7 @@ export class ReportController extends Controller {
|
||||||
: null,
|
: null,
|
||||||
score: profile.result,
|
score: profile.result,
|
||||||
reason: profile.remark,
|
reason: profile.remark,
|
||||||
remark:null,
|
remark: null,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -4766,7 +4764,6 @@ export class ReportController extends Controller {
|
||||||
.join("/");
|
.join("/");
|
||||||
const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`;
|
const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`;
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
||||||
fullName: fullName,
|
fullName: fullName,
|
||||||
|
|
@ -5210,7 +5207,7 @@ export class ReportController extends Controller {
|
||||||
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
|
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
|
||||||
|
|
||||||
const formattedData = _salaryPeriod.map((profile, index) => {
|
const formattedData = _salaryPeriod.map((profile, index) => {
|
||||||
const fullNameParts = [
|
const fullNameParts = [
|
||||||
profile.child4,
|
profile.child4,
|
||||||
profile.child3,
|
profile.child3,
|
||||||
profile.child2,
|
profile.child2,
|
||||||
|
|
@ -5321,7 +5318,7 @@ export class ReportController extends Controller {
|
||||||
const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root;
|
const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root;
|
||||||
|
|
||||||
const formattedData = salaryProfile.map((profile, index) => {
|
const formattedData = salaryProfile.map((profile, index) => {
|
||||||
const fullNameParts = [
|
const fullNameParts = [
|
||||||
profile.child4,
|
profile.child4,
|
||||||
profile.child3,
|
profile.child3,
|
||||||
profile.child2,
|
profile.child2,
|
||||||
|
|
@ -5404,7 +5401,7 @@ export class ReportController extends Controller {
|
||||||
const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root;
|
const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root;
|
||||||
|
|
||||||
const formattedData = _salaryProfileEmp.map((profile, index) => {
|
const formattedData = _salaryProfileEmp.map((profile, index) => {
|
||||||
const fullNameParts = [
|
const fullNameParts = [
|
||||||
profile.child4,
|
profile.child4,
|
||||||
profile.child3,
|
profile.child3,
|
||||||
profile.child2,
|
profile.child2,
|
||||||
|
|
@ -5895,7 +5892,6 @@ export class ReportController extends Controller {
|
||||||
.join("/");
|
.join("/");
|
||||||
const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`;
|
const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`;
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
||||||
fullName: fullName,
|
fullName: fullName,
|
||||||
|
|
@ -6273,7 +6269,7 @@ export class ReportController extends Controller {
|
||||||
async SalaryReport33Resume(
|
async SalaryReport33Resume(
|
||||||
@Body()
|
@Body()
|
||||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.result.map(async (v) => {
|
body.result.map(async (v) => {
|
||||||
|
|
@ -6282,6 +6278,7 @@ export class ReportController extends Controller {
|
||||||
id: v.id,
|
id: v.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (salary != null) {
|
if (salary != null) {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostData(request, "/org/profile/salary", {
|
.PostData(request, "/org/profile/salary", {
|
||||||
|
|
@ -6300,9 +6297,14 @@ export class ReportController extends Controller {
|
||||||
refCommandNo: v.refCommandNo,
|
refCommandNo: v.refCommandNo,
|
||||||
templateDoc: v.templateDoc,
|
templateDoc: v.templateDoc,
|
||||||
})
|
})
|
||||||
.then(async (x) => {
|
.then(async () => {
|
||||||
|
const before = null;
|
||||||
salary.status = "DONE";
|
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(
|
async SalaryReport34Resume(
|
||||||
@Body()
|
@Body()
|
||||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.result.map(async (v) => {
|
body.result.map(async (v) => {
|
||||||
|
|
@ -6348,9 +6350,14 @@ export class ReportController extends Controller {
|
||||||
refCommandNo: v.refCommandNo,
|
refCommandNo: v.refCommandNo,
|
||||||
templateDoc: v.templateDoc,
|
templateDoc: v.templateDoc,
|
||||||
})
|
})
|
||||||
.then(async (x) => {
|
.then(async () => {
|
||||||
|
const before = null;
|
||||||
salary.status = "DONE";
|
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(
|
async SalaryReport35Resume(
|
||||||
@Body()
|
@Body()
|
||||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.result.map(async (v) => {
|
body.result.map(async (v) => {
|
||||||
|
|
@ -6396,9 +6403,14 @@ export class ReportController extends Controller {
|
||||||
refCommandNo: v.refCommandNo,
|
refCommandNo: v.refCommandNo,
|
||||||
templateDoc: v.templateDoc,
|
templateDoc: v.templateDoc,
|
||||||
})
|
})
|
||||||
.then(async (x) => {
|
.then(async () => {
|
||||||
|
const before = null;
|
||||||
salary.status = "DONE";
|
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(
|
async SalaryReport36Resume(
|
||||||
@Body()
|
@Body()
|
||||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.result.map(async (v) => {
|
body.result.map(async (v) => {
|
||||||
|
|
@ -6444,9 +6456,14 @@ export class ReportController extends Controller {
|
||||||
refCommandNo: v.refCommandNo,
|
refCommandNo: v.refCommandNo,
|
||||||
templateDoc: v.templateDoc,
|
templateDoc: v.templateDoc,
|
||||||
})
|
})
|
||||||
.then(async (x) => {
|
.then(async () => {
|
||||||
|
const before = null;
|
||||||
salary.status = "DONE";
|
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(
|
async SalaryReport37Resume(
|
||||||
@Body()
|
@Body()
|
||||||
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
body: { result: { id: string; refCommandNo: string; templateDoc: string; personId: string }[] },
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.result.map(async (v) => {
|
body.result.map(async (v) => {
|
||||||
|
|
@ -6492,9 +6509,14 @@ export class ReportController extends Controller {
|
||||||
refCommandNo: v.refCommandNo,
|
refCommandNo: v.refCommandNo,
|
||||||
templateDoc: v.templateDoc,
|
templateDoc: v.templateDoc,
|
||||||
})
|
})
|
||||||
.then(async (x) => {
|
.then(async () => {
|
||||||
|
const before = null;
|
||||||
salary.status = "DONE";
|
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 { PosType } from "../entities/PosType";
|
||||||
import { PosLevel } from "../entities/PosLevel";
|
import { PosLevel } from "../entities/PosLevel";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import { Brackets, Like, Not } from "typeorm";
|
import { Brackets, Not } from "typeorm";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
|
@ -25,6 +25,7 @@ import { SalaryRanks } from "../entities/SalaryRanks";
|
||||||
import { randomUUID } from "crypto";
|
import { randomUUID } from "crypto";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary")
|
@Route("api/v1/salary")
|
||||||
@Tags("Salary")
|
@Tags("Salary")
|
||||||
|
|
@ -95,13 +96,17 @@ export class SalaryController extends Controller {
|
||||||
if (chk_fields && salarys.isActive) {
|
if (chk_fields && salarys.isActive) {
|
||||||
salarys.isActive = false;
|
salarys.isActive = false;
|
||||||
}
|
}
|
||||||
|
const before = null;
|
||||||
salarys.name = salarys.name;
|
salarys.name = salarys.name;
|
||||||
salarys.isSpecial = salarys.isSpecial;
|
salarys.isSpecial = salarys.isSpecial;
|
||||||
salarys.createdUserId = request.user.sub;
|
salarys.createdUserId = request.user.sub;
|
||||||
salarys.createdFullName = request.user.name;
|
salarys.createdFullName = request.user.name;
|
||||||
salarys.lastUpdateUserId = request.user.sub;
|
salarys.lastUpdateUserId = request.user.sub;
|
||||||
salarys.lastUpdateFullName = request.user.name;
|
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);
|
return new HttpSuccess(salarys.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,12 +172,14 @@ export class SalaryController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chk_fields.length > 0 && requestBody.isActive) {
|
if (chk_fields.length > 0 && requestBody.isActive) {
|
||||||
|
const before = structuredClone(chk_fields);
|
||||||
chk_fields.forEach(async (item: any) => {
|
chk_fields.forEach(async (item: any) => {
|
||||||
item.isActive = false;
|
item.isActive = false;
|
||||||
item.lastUpdateUserId = request.user.sub;
|
item.lastUpdateUserId = request.user.sub;
|
||||||
item.lastUpdateFullName = request.user.name;
|
item.lastUpdateFullName = request.user.name;
|
||||||
item.lastUpdatedAt = new Date();
|
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 mergeData = Object.assign(new Salarys(), requestBody);
|
||||||
|
|
||||||
|
const before = structuredClone(chk_Salary);
|
||||||
chk_Salary.lastUpdateUserId = request.user.sub;
|
chk_Salary.lastUpdateUserId = request.user.sub;
|
||||||
chk_Salary.lastUpdateFullName = request.user.name;
|
chk_Salary.lastUpdateFullName = request.user.name;
|
||||||
chk_Salary.lastUpdatedAt = new Date();
|
chk_Salary.lastUpdatedAt = new Date();
|
||||||
this.salaryRepository.merge(chk_Salary, mergeData);
|
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);
|
return new HttpSuccess(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,8 +233,8 @@ export class SalaryController extends Controller {
|
||||||
const del_SalaryRank = await this.salaryRankRepository.find({
|
const del_SalaryRank = await this.salaryRankRepository.find({
|
||||||
where: { salaryId: chk_Salary.id },
|
where: { salaryId: chk_Salary.id },
|
||||||
});
|
});
|
||||||
await this.salaryRankRepository.remove(del_SalaryRank);
|
await this.salaryRankRepository.remove(del_SalaryRank, { data: request });
|
||||||
await this.salaryRepository.remove(chk_Salary);
|
await this.salaryRepository.remove(chk_Salary, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,8 +256,8 @@ export class SalaryController extends Controller {
|
||||||
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
||||||
detail: "string", //คำอธิบาย
|
detail: "string", //คำอธิบาย
|
||||||
})
|
})
|
||||||
async GetSalaryById(@Path() id: string, @Request() req: RequestWithUser) {
|
async GetSalaryById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
await new permission().PermissionGet(req, "SYS_SALARY_CHART_OFFICER");
|
await new permission().PermissionGet(request, "SYS_SALARY_CHART_OFFICER");
|
||||||
const salary = await this.salaryRepository.findOne({
|
const salary = await this.salaryRepository.findOne({
|
||||||
relations: ["posType_", "posLevel_"],
|
relations: ["posType_", "posLevel_"],
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
|
|
@ -281,12 +290,12 @@ export class SalaryController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get()
|
@Get()
|
||||||
async listSalary(
|
async listSalary(
|
||||||
@Request() req: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("keyword") keyword?: string,
|
@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)
|
const [salary, total] = await AppDataSource.getRepository(Salarys)
|
||||||
.createQueryBuilder("salary")
|
.createQueryBuilder("salary")
|
||||||
.leftJoinAndSelect("salary.posType_", "posType_")
|
.leftJoinAndSelect("salary.posType_", "posType_")
|
||||||
|
|
@ -345,14 +354,29 @@ export class SalaryController extends Controller {
|
||||||
where: { salaryId: salary?.id },
|
where: { salaryId: salary?.id },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const before = null;
|
||||||
const newSalary = { ...salary, id: randomUUID(), isActive: false };
|
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(
|
await Promise.all(
|
||||||
salaryRank.map(async (v) => {
|
salaryRank.map(async (v) => {
|
||||||
const newSalaryRank = { ...v, id: randomUUID() };
|
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,
|
UpdateSalaryEmployee,
|
||||||
} from "../entities/SalaryEmployee";
|
} from "../entities/SalaryEmployee";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import { Not, Like, Brackets } from "typeorm";
|
import { Not, Brackets } from "typeorm";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
|
import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
|
||||||
import { randomUUID } from "crypto";
|
import { randomUUID } from "crypto";
|
||||||
import { Salarys } from "../entities/Salarys";
|
|
||||||
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
|
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary/employee")
|
@Route("api/v1/salary/employee")
|
||||||
@Tags("SalaryEmployee")
|
@Tags("SalaryEmployee")
|
||||||
|
|
@ -86,11 +86,16 @@ export class SalaryEmployeeController extends Controller {
|
||||||
if (chk_3fields && salarys.isActive) {
|
if (chk_3fields && salarys.isActive) {
|
||||||
salarys.isActive = false;
|
salarys.isActive = false;
|
||||||
}
|
}
|
||||||
|
const before = null;
|
||||||
salarys.createdUserId = request.user.sub;
|
salarys.createdUserId = request.user.sub;
|
||||||
salarys.createdFullName = request.user.name;
|
salarys.createdFullName = request.user.name;
|
||||||
salarys.lastUpdateUserId = request.user.sub;
|
salarys.lastUpdateUserId = request.user.sub;
|
||||||
salarys.lastUpdateFullName = request.user.name;
|
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);
|
return new HttpSuccess(salarys.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,22 +144,25 @@ export class SalaryEmployeeController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (chk_3fields.length > 0 && requestBody.isActive) {
|
if (chk_3fields.length > 0 && requestBody.isActive) {
|
||||||
|
const beforeChk_3fields = structuredClone(chk_3fields);
|
||||||
chk_3fields.forEach(async (item) => {
|
chk_3fields.forEach(async (item) => {
|
||||||
item.isActive = false;
|
item.isActive = false;
|
||||||
item.lastUpdateUserId = request.user.sub;
|
item.lastUpdateUserId = request.user.sub;
|
||||||
item.lastUpdateFullName = request.user.name;
|
item.lastUpdateFullName = request.user.name;
|
||||||
item.lastUpdatedAt = new Date();
|
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 mergeData = Object.assign(new SalaryEmployee(), requestBody);
|
||||||
|
const before = structuredClone(chk_Salary);
|
||||||
chk_Salary.lastUpdateUserId = request.user.sub;
|
chk_Salary.lastUpdateUserId = request.user.sub;
|
||||||
chk_Salary.lastUpdateFullName = request.user.name;
|
chk_Salary.lastUpdateFullName = request.user.name;
|
||||||
chk_Salary.lastUpdatedAt = new Date();
|
chk_Salary.lastUpdatedAt = new Date();
|
||||||
this.salaryEmployeeRepository.merge(chk_Salary, mergeData);
|
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);
|
return new HttpSuccess(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,7 +191,7 @@ export class SalaryEmployeeController extends Controller {
|
||||||
const chk_SalaryFormulaEmp = await this.salaryFormulaEmployeeRepository.find({
|
const chk_SalaryFormulaEmp = await this.salaryFormulaEmployeeRepository.find({
|
||||||
where: { salaryEmployeeId: id },
|
where: { salaryEmployeeId: id },
|
||||||
});
|
});
|
||||||
if(chk_SalaryFormulaEmp.length > 0){
|
if (chk_SalaryFormulaEmp.length > 0) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatusCode.NOT_FOUND,
|
HttpStatusCode.NOT_FOUND,
|
||||||
"ไม่สามารถลบรายการนี้ได้เนื่องจากมีการใช้งานอยู่",
|
"ไม่สามารถลบรายการนี้ได้เนื่องจากมีการใช้งานอยู่",
|
||||||
|
|
@ -192,8 +200,8 @@ export class SalaryEmployeeController extends Controller {
|
||||||
const del_SalaryRank = await this.salaryRankEmployeeRepository.find({
|
const del_SalaryRank = await this.salaryRankEmployeeRepository.find({
|
||||||
where: { salaryEmployeeId: chk_Salary.id },
|
where: { salaryEmployeeId: chk_Salary.id },
|
||||||
});
|
});
|
||||||
await this.salaryRankEmployeeRepository.remove(del_SalaryRank);
|
await this.salaryRankEmployeeRepository.remove(del_SalaryRank, { data: request });
|
||||||
await this.salaryEmployeeRepository.remove(chk_Salary);
|
await this.salaryEmployeeRepository.remove(chk_Salary, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,7 +221,7 @@ export class SalaryEmployeeController extends Controller {
|
||||||
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
||||||
detail: "string", //คำอธิบาย
|
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");
|
await new permission().PermissionGet(request, "SYS_WAGE_CHART_EMP");
|
||||||
const salary = await this.salaryEmployeeRepository.findOne({
|
const salary = await this.salaryEmployeeRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
|
|
@ -273,10 +281,7 @@ export class SalaryEmployeeController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("copy")
|
@Post("copy")
|
||||||
async copySalary(
|
async copySalary(@Body() body: { id: string }, @Request() request: RequestWithUser) {
|
||||||
@Body() body: { id: string },
|
|
||||||
@Request() request: RequestWithUser,
|
|
||||||
) {
|
|
||||||
await new permission().PermissionCreate(request, "SYS_WAGE_CHART_EMP");
|
await new permission().PermissionCreate(request, "SYS_WAGE_CHART_EMP");
|
||||||
const salary = await this.salaryEmployeeRepository.findOne({
|
const salary = await this.salaryEmployeeRepository.findOne({
|
||||||
relations: ["salaryRankEmployees_"],
|
relations: ["salaryRankEmployees_"],
|
||||||
|
|
@ -292,13 +297,27 @@ export class SalaryEmployeeController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
const newSalary = { ...salary, id: randomUUID(), isActive: false };
|
const newSalary = { ...salary, id: randomUUID(), isActive: false };
|
||||||
|
const before = null;
|
||||||
await this.salaryEmployeeRepository.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.salaryEmployeeRepository.save(newSalary, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: newSalary });
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
salaryRank.map(async (v) => {
|
salaryRank.map(async (v) => {
|
||||||
const newSalaryRank = { ...v, id: randomUUID() };
|
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,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Delete,
|
Delete,
|
||||||
Patch,
|
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
|
|
@ -19,7 +17,6 @@ import {
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { PosLevel, CreatePosLevel, UpdatePosLevel } from "../entities/PosLevel";
|
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { In, Like, Not } from "typeorm";
|
import { In, Like, Not } from "typeorm";
|
||||||
import {
|
import {
|
||||||
|
|
@ -32,6 +29,7 @@ import { EmployeePosType } from "../entities/EmployeePosType";
|
||||||
import { SalaryEmployee } from "../entities/SalaryEmployee";
|
import { SalaryEmployee } from "../entities/SalaryEmployee";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary/formula")
|
@Route("api/v1/salary/formula")
|
||||||
@Tags("SalaryFormula")
|
@Tags("SalaryFormula")
|
||||||
|
|
@ -98,12 +96,16 @@ export class SalaryFormulaEmployeeController extends Controller {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const before = null;
|
||||||
formula.salaryEmployeeMins = chkSalaryEmployeeMin;
|
formula.salaryEmployeeMins = chkSalaryEmployeeMin;
|
||||||
formula.createdUserId = request.user.sub;
|
formula.createdUserId = request.user.sub;
|
||||||
formula.createdFullName = request.user.name;
|
formula.createdFullName = request.user.name;
|
||||||
formula.lastUpdateUserId = request.user.sub;
|
formula.lastUpdateUserId = request.user.sub;
|
||||||
formula.lastUpdateFullName = request.user.name;
|
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);
|
return new HttpSuccess(formula);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,6 +162,7 @@ export class SalaryFormulaEmployeeController extends Controller {
|
||||||
id: In(requestBody.salaryEmployeeMinIds),
|
id: In(requestBody.salaryEmployeeMinIds),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const before = structuredClone(formula);
|
||||||
formula.position = requestBody.position;
|
formula.position = requestBody.position;
|
||||||
formula.salaryMin = requestBody.salaryMin;
|
formula.salaryMin = requestBody.salaryMin;
|
||||||
formula.salary = requestBody.salary;
|
formula.salary = requestBody.salary;
|
||||||
|
|
@ -171,7 +174,9 @@ export class SalaryFormulaEmployeeController extends Controller {
|
||||||
formula.salaryEmployeeMins = chkSalaryEmployeeMin;
|
formula.salaryEmployeeMins = chkSalaryEmployeeMin;
|
||||||
formula.lastUpdateUserId = request.user.sub;
|
formula.lastUpdateUserId = request.user.sub;
|
||||||
formula.lastUpdateFullName = request.user.name;
|
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);
|
return new HttpSuccess(formula.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,7 +192,7 @@ export class SalaryFormulaEmployeeController extends Controller {
|
||||||
const delFormula = await this.salaryFormulaEmployeeRepository.findOne({ where: { id } });
|
const delFormula = await this.salaryFormulaEmployeeRepository.findOne({ where: { id } });
|
||||||
if (!delFormula) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังค่าจ้างนี้");
|
if (!delFormula) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังค่าจ้างนี้");
|
||||||
|
|
||||||
await this.salaryFormulaEmployeeRepository.remove(delFormula);
|
await this.salaryFormulaEmployeeRepository.remove(delFormula, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ import { SalaryRanks } from "../entities/SalaryRanks";
|
||||||
import CallAPI from "../interfaces/call-api";
|
import CallAPI from "../interfaces/call-api";
|
||||||
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
|
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
|
||||||
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
|
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
|
||||||
import { isNullOrUndefined } from "util";
|
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary/period")
|
@Route("api/v1/salary/period")
|
||||||
@Tags("Salary")
|
@Tags("Salary")
|
||||||
|
|
@ -297,7 +297,7 @@ export class SalaryPeriodController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.salaryProfileRepository.remove(salaryProfile);
|
await this.salaryProfileRepository.remove(salaryProfile, { data: req });
|
||||||
|
|
||||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -328,7 +328,10 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -382,7 +385,10 @@ export class SalaryPeriodController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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 ฐานเงินเดือน
|
* @param {string} amount ฐานเงินเดือน
|
||||||
*/
|
*/
|
||||||
@Post("change/amount")
|
@Post("change/amount")
|
||||||
async changeAmount(@Body() body: { profileId: string; amount: number }, @Request() request: RequestWithUser) {
|
async changeAmount(
|
||||||
await new permission().PermissionCreate(request, "SYS_SALARY_OFFICER");
|
@Body() body: { profileId: string; amount: number },
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
|
) {
|
||||||
|
await new permission().PermissionCreate(request, "SYS_SALARY_OFFICER");
|
||||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
where: { id: body.profileId },
|
where: { id: body.profileId },
|
||||||
|
|
@ -575,8 +584,12 @@ export class SalaryPeriodController extends Controller {
|
||||||
} else {
|
} else {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||||
}
|
}
|
||||||
|
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||||
await this.salaryProfileRepository.save(salaryProfile);
|
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({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -607,7 +620,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -661,7 +678,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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
|
* @param {string} groupId groupId
|
||||||
*/
|
*/
|
||||||
@Post("change/group")
|
@Post("change/group")
|
||||||
async changeGroup(@Body() body: { profileId: string; groupId: string } ,@Request() req: RequestWithUser) {
|
async changeGroup(
|
||||||
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
@Body() body: { profileId: string; groupId: string },
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
) {
|
||||||
|
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
||||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
where: { id: body.profileId },
|
where: { id: body.profileId },
|
||||||
|
|
@ -695,9 +719,15 @@ export class SalaryPeriodController extends Controller {
|
||||||
if (!salaryOrg) {
|
if (!salaryOrg) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
|
||||||
}
|
}
|
||||||
|
const before = null;
|
||||||
|
|
||||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
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({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
where: { id: salaryProfile.id },
|
where: { id: salaryProfile.id },
|
||||||
|
|
@ -727,7 +757,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -781,7 +815,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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")
|
@Post("change/type")
|
||||||
async changeType(
|
async changeType(
|
||||||
@Body() body: { profileId: string; type: string; isReserve: boolean; remark?: string | null },
|
@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");
|
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
||||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
|
|
@ -1011,7 +1049,12 @@ export class SalaryPeriodController extends Controller {
|
||||||
} else {
|
} else {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
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({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -1042,7 +1085,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -1096,7 +1143,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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}")
|
@Put("org/{id}")
|
||||||
async GetListsSalaryProfile(
|
async GetListsSalaryProfile(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body()
|
@Body()
|
||||||
body: {
|
body: {
|
||||||
|
|
@ -1124,6 +1176,7 @@ export class SalaryPeriodController extends Controller {
|
||||||
isRetire?: string | null;
|
isRetire?: string | null;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
await new permission().PermissionList(request, "SYS_SALARY_OFFICER");
|
||||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
|
|
@ -1213,6 +1266,7 @@ export class SalaryPeriodController extends Controller {
|
||||||
if (!salaryProfile) {
|
if (!salaryProfile) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้");
|
||||||
}
|
}
|
||||||
|
const before = structuredClone(salaryProfile);
|
||||||
salaryProfile.isPunish = body.isPunish;
|
salaryProfile.isPunish = body.isPunish;
|
||||||
salaryProfile.isSuspension = body.isSuspension;
|
salaryProfile.isSuspension = body.isSuspension;
|
||||||
salaryProfile.isAbsent = body.isAbsent;
|
salaryProfile.isAbsent = body.isAbsent;
|
||||||
|
|
@ -1220,7 +1274,9 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryProfile.lastUpdateUserId = request.user.sub;
|
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||||
salaryProfile.lastUpdateFullName = request.user.name;
|
salaryProfile.lastUpdateFullName = request.user.name;
|
||||||
salaryProfile.lastUpdatedAt = new Date();
|
salaryProfile.lastUpdatedAt = new Date();
|
||||||
await this.salaryProfileRepository.save(salaryProfile);
|
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: salaryProfile });
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1438,12 +1494,16 @@ export class SalaryPeriodController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const before = null;
|
||||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
salaryProfile.salaryOrgId = salaryOrg.id;
|
||||||
salaryProfile.createdUserId = request.user.sub;
|
salaryProfile.createdUserId = request.user.sub;
|
||||||
salaryProfile.createdFullName = request.user.name;
|
salaryProfile.createdFullName = request.user.name;
|
||||||
salaryProfile.lastUpdateUserId = request.user.sub;
|
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||||
salaryProfile.lastUpdateFullName = request.user.name;
|
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({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -1474,7 +1534,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -1528,7 +1592,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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) {
|
if (!salaryPeriod) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
||||||
}
|
}
|
||||||
|
const before = structuredClone(salaryPeriod);
|
||||||
salaryPeriod.isClose = !salaryPeriod.isClose;
|
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();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1591,13 +1665,16 @@ export class SalaryPeriodController extends Controller {
|
||||||
"ประเภทผังปี " + Extension.ToThaiYear(salaryPeriod.year) + " ซ้ำ",
|
"ประเภทผังปี " + Extension.ToThaiYear(salaryPeriod.year) + " ซ้ำ",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const before = null;
|
||||||
salaryPeriod.period = salaryPeriod.period.toUpperCase();
|
salaryPeriod.period = salaryPeriod.period.toUpperCase();
|
||||||
salaryPeriod.createdUserId = request.user.sub;
|
salaryPeriod.createdUserId = request.user.sub;
|
||||||
salaryPeriod.createdFullName = request.user.name;
|
salaryPeriod.createdFullName = request.user.name;
|
||||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
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") {
|
if (salaryPeriod.period == "SPECIAL") {
|
||||||
const snapshot = "SNAP1";
|
const snapshot = "SNAP1";
|
||||||
|
|
@ -1607,8 +1684,8 @@ export class SalaryPeriodController extends Controller {
|
||||||
const salaryProfile = await this.salaryProfileRepository.find({
|
const salaryProfile = await this.salaryProfileRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryOrgRepository.remove(salaryOrg);
|
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||||
await this.salaryProfileRepository.remove(salaryProfile);
|
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||||
|
|
||||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||||
|
|
@ -1616,14 +1693,18 @@ export class SalaryPeriodController extends Controller {
|
||||||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||||
|
|
||||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||||
|
|
||||||
salaryPeriod.revisionId = revisionId;
|
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(
|
await Promise.all(
|
||||||
orgs.map(async (root: any) => {
|
orgs.map(async (root: any) => {
|
||||||
|
|
@ -1638,8 +1719,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrgNew.createdFullName = request.user.name;
|
salaryOrgNew.createdFullName = request.user.name;
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
|
salaryOrgNew.createdAt = new Date();
|
||||||
|
salaryOrgNew.lastUpdatedAt = new Date();
|
||||||
salaryOrgNew.group = "GROUP1";
|
salaryOrgNew.group = "GROUP1";
|
||||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
|
@ -1656,7 +1740,10 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
salaryOrgNew.group = "GROUP1";
|
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) + " ซ้ำ",
|
"ประเภทผังปี " + (requestBody.effectiveDate.getFullYear() + 543) + " ซ้ำ",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const beforeChk_SalaryPeriod = structuredClone(chk_SalaryPeriod);
|
||||||
chk_SalaryPeriod.period = requestBody.period.toUpperCase();
|
chk_SalaryPeriod.period = requestBody.period.toUpperCase();
|
||||||
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
||||||
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
||||||
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
||||||
this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody);
|
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") {
|
if (chk_SalaryPeriod.period == "SPECIAL") {
|
||||||
const snapshot = "SNAP1";
|
const snapshot = "SNAP1";
|
||||||
const salaryOrg = await this.salaryOrgRepository.find({
|
const salaryOrg = await this.salaryOrgRepository.find({
|
||||||
|
|
@ -1717,8 +1806,8 @@ export class SalaryPeriodController extends Controller {
|
||||||
const salaryProfile = await this.salaryProfileRepository.find({
|
const salaryProfile = await this.salaryProfileRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryOrgRepository.remove(salaryOrg);
|
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||||
await this.salaryProfileRepository.remove(salaryProfile);
|
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||||
|
|
||||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||||
where: { salaryPeriodId: chk_SalaryPeriod.id, snapshot: snapshot },
|
where: { salaryPeriodId: chk_SalaryPeriod.id, snapshot: snapshot },
|
||||||
|
|
@ -1726,18 +1815,25 @@ export class SalaryPeriodController extends Controller {
|
||||||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||||
|
|
||||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||||
|
|
||||||
chk_SalaryPeriod.revisionId = revisionId;
|
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(
|
await Promise.all(
|
||||||
orgs.map(async (root: any) => {
|
orgs.map(async (root: any) => {
|
||||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||||
|
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||||
|
|
||||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||||
salaryOrgNew.status = "PENDING";
|
salaryOrgNew.status = "PENDING";
|
||||||
salaryOrgNew.rootId = root.rootId;
|
salaryOrgNew.rootId = root.rootId;
|
||||||
|
|
@ -1749,13 +1845,18 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
salaryOrgNew.group = "GROUP1";
|
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(
|
await Promise.all(
|
||||||
orgs.map(async (root: any) => {
|
orgs.map(async (root: any) => {
|
||||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||||
|
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||||
|
|
||||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||||
salaryOrgNew.status = "PENDING";
|
salaryOrgNew.status = "PENDING";
|
||||||
salaryOrgNew.rootId = root.rootId;
|
salaryOrgNew.rootId = root.rootId;
|
||||||
|
|
@ -1767,7 +1868,10 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
salaryOrgNew.group = "GROUP1";
|
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);
|
const salaryProfile = SalaryOrg.find((x) => x.salaryProfiles.length > 0);
|
||||||
if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||||
|
|
||||||
await this.salaryOrgRepository.remove(SalaryOrg);
|
await this.salaryOrgRepository.remove(SalaryOrg, { data: request });
|
||||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
} else {
|
} else {
|
||||||
const SalaryOrg = await this.salaryOrgRepository.findOne({
|
const SalaryOrg = await this.salaryOrgRepository.findOne({
|
||||||
|
|
@ -1807,7 +1911,7 @@ export class SalaryPeriodController extends Controller {
|
||||||
});
|
});
|
||||||
if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||||
|
|
||||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1956,7 +2060,7 @@ export class SalaryPeriodController extends Controller {
|
||||||
async SnapshotSalary(
|
async SnapshotSalary(
|
||||||
@Path() snapshot: string,
|
@Path() snapshot: string,
|
||||||
salaryPeriodId: string,
|
salaryPeriodId: string,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
snapshot = snapshot.toLocaleUpperCase();
|
snapshot = snapshot.toLocaleUpperCase();
|
||||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
|
|
@ -1972,8 +2076,8 @@ export class SalaryPeriodController extends Controller {
|
||||||
const salaryProfile = await this.salaryProfileRepository.find({
|
const salaryProfile = await this.salaryProfileRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryProfileRepository.remove(salaryProfile);
|
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||||
await this.salaryOrgRepository.remove(salaryOrg);
|
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||||
|
|
||||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||||
|
|
@ -1981,8 +2085,8 @@ export class SalaryPeriodController extends Controller {
|
||||||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||||
let total = 1000;
|
let total = 1000;
|
||||||
let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/salary/gen", {
|
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");
|
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||||
|
|
||||||
|
const beforeSalaryPeriod = structuredClone(salaryPeriod);
|
||||||
salaryPeriod.revisionId = revisionId;
|
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(
|
await Promise.all(
|
||||||
orgs.map(async (root: any) => {
|
orgs.map(async (root: any) => {
|
||||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||||
delete salaryOrgNew.id;
|
delete salaryOrgNew.id;
|
||||||
|
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||||
|
|
||||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||||
salaryOrgNew.status = "PENDING";
|
salaryOrgNew.status = "PENDING";
|
||||||
salaryOrgNew.rootId = root.rootId;
|
salaryOrgNew.rootId = root.rootId;
|
||||||
|
|
@ -2060,12 +2171,17 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrgNew.createdFullName = request.user.name;
|
salaryOrgNew.createdFullName = request.user.name;
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
|
salaryOrgNew.createdAt = new Date();
|
||||||
|
salaryOrgNew.lastUpdatedAt = new Date();
|
||||||
salaryOrgNew.group = "GROUP1";
|
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") {
|
if (salaryPeriod.period != "SPECIAL") {
|
||||||
delete salaryOrgNew.id;
|
delete salaryOrgNew.id;
|
||||||
salaryOrgNew.group = "GROUP2";
|
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(
|
await Promise.all(
|
||||||
orgs.map(async (root: any) => {
|
orgs.map(async (root: any) => {
|
||||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||||
|
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||||
|
|
||||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||||
salaryOrgNew.status = "PENDING";
|
salaryOrgNew.status = "PENDING";
|
||||||
salaryOrgNew.rootId = root.rootId;
|
salaryOrgNew.rootId = root.rootId;
|
||||||
|
|
@ -2084,11 +2202,16 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
salaryOrgNew.group = "GROUP1";
|
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") {
|
if (salaryPeriod.period != "SPECIAL") {
|
||||||
delete salaryOrgNew.id;
|
delete salaryOrgNew.id;
|
||||||
salaryOrgNew.group = "GROUP2";
|
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) {
|
if (salaryOrgNew != null) {
|
||||||
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
|
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
|
||||||
delete salaryProfileNew.id;
|
delete salaryProfileNew.id;
|
||||||
|
|
||||||
|
const beforeSalaryProfileNew = structuredClone(salaryProfileNew);
|
||||||
|
|
||||||
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
||||||
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
||||||
salaryProfileNew.createdUserId = request.user.sub;
|
salaryProfileNew.createdUserId = request.user.sub;
|
||||||
salaryProfileNew.createdFullName = request.user.name;
|
salaryProfileNew.createdFullName = request.user.name;
|
||||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||||
|
salaryProfileNew.createdAt = new Date();
|
||||||
|
salaryProfileNew.lastUpdatedAt = new Date();
|
||||||
|
|
||||||
if (snapshot == "SNAP2") {
|
if (snapshot == "SNAP2") {
|
||||||
const salaryOrgOld = await this.salaryOrgRepository.find({
|
const salaryOrgOld = await this.salaryOrgRepository.find({
|
||||||
|
|
@ -2146,7 +2274,8 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
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) {
|
if (salaryOrgNew != null) {
|
||||||
let salaryProfileNew = Object.assign(new SalaryProfileEmployee(), profile);
|
let salaryProfileNew = Object.assign(new SalaryProfileEmployee(), profile);
|
||||||
delete salaryProfileNew.id;
|
delete salaryProfileNew.id;
|
||||||
|
const beforeSalaryProfileNew = structuredClone(salaryProfileNew);
|
||||||
|
|
||||||
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
||||||
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
||||||
salaryProfileNew.createdUserId = request.user.sub;
|
salaryProfileNew.createdUserId = request.user.sub;
|
||||||
salaryProfileNew.createdFullName = request.user.name;
|
salaryProfileNew.createdFullName = request.user.name;
|
||||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||||
|
salaryProfileNew.createdAt = new Date();
|
||||||
|
salaryProfileNew.lastUpdatedAt = new Date();
|
||||||
|
|
||||||
if (snapshot == "SNAP2") {
|
if (snapshot == "SNAP2") {
|
||||||
const salaryOrgOld = await this.salaryOrgEmployeeRepository.find({
|
const salaryOrgOld = await this.salaryOrgEmployeeRepository.find({
|
||||||
|
|
@ -2192,7 +2325,8 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
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");
|
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||||
if (snapshot == "SNAP2") {
|
if (snapshot == "SNAP2") {
|
||||||
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -2258,6 +2393,7 @@ export class SalaryPeriodController extends Controller {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||||
|
|
||||||
_salaryOrg.currentAmount = totalProfile;
|
_salaryOrg.currentAmount = totalProfile;
|
||||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||||
|
|
@ -2265,12 +2401,21 @@ export class SalaryPeriodController extends Controller {
|
||||||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
_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(
|
await Promise.all(
|
||||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||||
let totalAmount = 0;
|
let totalAmount = 0;
|
||||||
|
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||||
|
|
||||||
if (salaryPeriodAPROld != null) {
|
if (salaryPeriodAPROld != null) {
|
||||||
const salaryOrgSnap2Old: any = await this.salaryOrgEmployeeRepository.findOne({
|
const salaryOrgSnap2Old: any = await this.salaryOrgEmployeeRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -2320,12 +2465,21 @@ export class SalaryPeriodController extends Controller {
|
||||||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
_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") {
|
} else if (salaryPeriod.period == "APR") {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||||
|
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||||
|
|
||||||
if (snapshot == "SNAP2") {
|
if (snapshot == "SNAP2") {
|
||||||
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -2354,11 +2508,20 @@ export class SalaryPeriodController extends Controller {
|
||||||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
_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(
|
await Promise.all(
|
||||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||||
|
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||||
|
|
||||||
if (snapshot == "SNAP2") {
|
if (snapshot == "SNAP2") {
|
||||||
const salaryOrgSnap1 = await this.salaryOrgEmployeeRepository.findOne({
|
const salaryOrgSnap1 = await this.salaryOrgEmployeeRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -2387,7 +2550,14 @@ export class SalaryPeriodController extends Controller {
|
||||||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
_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({
|
const salaryProfile = await this.salaryProfileRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryOrgRepository.remove(salaryOrg);
|
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||||
await this.salaryProfileRepository.remove(salaryProfile);
|
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||||
|
|
||||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||||
|
|
@ -2473,8 +2643,8 @@ export class SalaryPeriodController extends Controller {
|
||||||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||||
|
|
||||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||||
let total = 1000;
|
let total = 1000;
|
||||||
|
|
@ -2534,9 +2704,13 @@ export class SalaryPeriodController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||||
|
const before = null;
|
||||||
salaryPeriod.revisionId = revisionId;
|
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(
|
await Promise.all(
|
||||||
orgs.map(async (root: any) => {
|
orgs.map(async (root: any) => {
|
||||||
|
|
@ -2551,12 +2725,17 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryOrgNew.createdFullName = request.user.name;
|
salaryOrgNew.createdFullName = request.user.name;
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
|
salaryOrgNew.createdAt = new Date();
|
||||||
|
salaryOrgNew.lastUpdatedAt = new Date();
|
||||||
salaryOrgNew.group = "GROUP1";
|
salaryOrgNew.group = "GROUP1";
|
||||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||||
|
|
||||||
if (salaryPeriod.period != "SPECIAL") {
|
if (salaryPeriod.period != "SPECIAL") {
|
||||||
delete salaryOrgNew.id;
|
delete salaryOrgNew.id;
|
||||||
salaryOrgNew.group = "GROUP2";
|
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.createdFullName = request.user.name;
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
|
salaryOrgNew.createdAt = new Date();
|
||||||
|
salaryOrgNew.lastUpdatedAt = new Date();
|
||||||
salaryOrgNew.group = "GROUP1";
|
salaryOrgNew.group = "GROUP1";
|
||||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||||
|
|
||||||
if (salaryPeriod.period != "SPECIAL") {
|
if (salaryPeriod.period != "SPECIAL") {
|
||||||
delete salaryOrgNew.id;
|
delete salaryOrgNew.id;
|
||||||
salaryOrgNew.group = "GROUP2";
|
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.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
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.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
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;
|
_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(
|
await Promise.all(
|
||||||
|
|
@ -2812,7 +3017,14 @@ export class SalaryPeriodController extends Controller {
|
||||||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
_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") {
|
} else if (salaryPeriod.period == "APR") {
|
||||||
|
|
@ -2846,7 +3058,14 @@ export class SalaryPeriodController extends Controller {
|
||||||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
_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(
|
await Promise.all(
|
||||||
|
|
@ -2879,7 +3098,14 @@ export class SalaryPeriodController extends Controller {
|
||||||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
_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 สำนัก
|
* @param {string} rootId Guid, *Id สำนัก
|
||||||
*/
|
*/
|
||||||
@Get("officer/approve/{periodId}/{rootId}")
|
@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({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
where: { id: periodId },
|
where: { id: periodId },
|
||||||
relations: ["salaryOrgs"],
|
relations: ["salaryOrgs"],
|
||||||
|
|
@ -2904,8 +3134,13 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryPeriod.salaryOrgs
|
salaryPeriod.salaryOrgs
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x) => {
|
.map(async (x) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "WAITHEAD1";
|
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();
|
return new HttpSuccess();
|
||||||
|
|
@ -2919,7 +3154,7 @@ export class SalaryPeriodController extends Controller {
|
||||||
* @param {string} rootId Guid, *Id สำนัก
|
* @param {string} rootId Guid, *Id สำนัก
|
||||||
*/
|
*/
|
||||||
@Get("head/approve/{periodId}/{rootId}")
|
@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({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
where: { id: periodId },
|
where: { id: periodId },
|
||||||
relations: ["salaryOrgs"],
|
relations: ["salaryOrgs"],
|
||||||
|
|
@ -2931,8 +3166,13 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryPeriod.salaryOrgs
|
salaryPeriod.salaryOrgs
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x) => {
|
.map(async (x) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "WAITOWNER1";
|
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();
|
return new HttpSuccess();
|
||||||
|
|
@ -2946,7 +3186,11 @@ export class SalaryPeriodController extends Controller {
|
||||||
* @param {string} rootId Guid, *Id สำนัก
|
* @param {string} rootId Guid, *Id สำนัก
|
||||||
*/
|
*/
|
||||||
@Get("owner/approve/{periodId}/{rootId}")
|
@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({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
where: { id: periodId },
|
where: { id: periodId },
|
||||||
relations: ["salaryOrgs"],
|
relations: ["salaryOrgs"],
|
||||||
|
|
@ -2958,8 +3202,13 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryPeriod.salaryOrgs
|
salaryPeriod.salaryOrgs
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x) => {
|
.map(async (x) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "REPORT";
|
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();
|
return new HttpSuccess();
|
||||||
|
|
@ -2994,9 +3243,14 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryPeriod.salaryOrgs
|
salaryPeriod.salaryOrgs
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x) => {
|
.map(async (x) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "WAITHEAD2";
|
x.status = "WAITHEAD2";
|
||||||
x.ownerRecommend = body.titleRecommend;
|
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();
|
return new HttpSuccess();
|
||||||
|
|
@ -3031,9 +3285,14 @@ export class SalaryPeriodController extends Controller {
|
||||||
salaryPeriod.salaryOrgs
|
salaryPeriod.salaryOrgs
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x) => {
|
.map(async (x) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "REPORT";
|
x.status = "REPORT";
|
||||||
x.ownerRecommend = body.titleRecommend;
|
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();
|
return new HttpSuccess();
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import {
|
||||||
Query,
|
Query,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
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 HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
|
@ -32,6 +32,7 @@ import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
|
||||||
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
|
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary/period-employee")
|
@Route("api/v1/salary/period-employee")
|
||||||
@Tags("SalaryEmployee")
|
@Tags("SalaryEmployee")
|
||||||
|
|
@ -42,7 +43,6 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfileEmployee);
|
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfileEmployee);
|
||||||
private posTypeRepository = AppDataSource.getRepository(EmployeePosType);
|
private posTypeRepository = AppDataSource.getRepository(EmployeePosType);
|
||||||
private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
|
private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
|
||||||
private salaryRepository = AppDataSource.getRepository(SalaryEmployee);
|
|
||||||
private salaryRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
|
private salaryRankRepository = AppDataSource.getRepository(SalaryRankEmployee);
|
||||||
private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee);
|
private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee);
|
||||||
|
|
||||||
|
|
@ -258,7 +258,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.salaryProfileRepository.remove(salaryProfile);
|
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||||
|
|
||||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -289,7 +289,10 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -343,7 +346,10 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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 ฐานเงินเดือน
|
* @param {string} amount ฐานเงินเดือน
|
||||||
*/
|
*/
|
||||||
@Post("change/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");
|
await new permission().PermissionCreate(req, "SYS_WAGE");
|
||||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -709,7 +718,12 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
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({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -740,7 +754,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -794,7 +812,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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
|
* @param {string} groupId groupId
|
||||||
*/
|
*/
|
||||||
@Post("change/group")
|
@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");
|
await new permission().PermissionCreate(req, "SYS_WAGE");
|
||||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -829,9 +854,13 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
if (!salaryOrg) {
|
if (!salaryOrg) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
|
||||||
}
|
}
|
||||||
|
const before = null;
|
||||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
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({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
where: { id: salaryProfile.id },
|
where: { id: salaryProfile.id },
|
||||||
|
|
@ -861,7 +890,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -915,7 +948,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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")
|
@Post("change/type")
|
||||||
async changeType(
|
async changeType(
|
||||||
@Body() body: { profileId: string; type: string; isReserve: boolean; remark?: string | null },
|
@Body() body: { profileId: string; type: string; isReserve: boolean; remark?: string | null },
|
||||||
@Request() req: RequestWithUser
|
@Request() req: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionCreate(req, "SYS_WAGE");
|
await new permission().PermissionCreate(req, "SYS_WAGE");
|
||||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
|
|
@ -1320,7 +1357,12 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
} else {
|
} else {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
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({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -1351,7 +1393,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -1405,7 +1451,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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}")
|
@Put("org/{id}")
|
||||||
async GetListsSalaryProfile(
|
async GetListsSalaryProfile(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body()
|
@Body()
|
||||||
body: {
|
body: {
|
||||||
|
|
@ -1433,6 +1484,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
isRetire?: string | null;
|
isRetire?: string | null;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
await new permission().PermissionList(request, "SYS_WAGE");
|
||||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
|
|
@ -1575,6 +1627,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
if (!salaryProfile) {
|
if (!salaryProfile) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้");
|
||||||
}
|
}
|
||||||
|
const before = structuredClone(salaryProfile);
|
||||||
salaryProfile.isPunish = body.isPunish;
|
salaryProfile.isPunish = body.isPunish;
|
||||||
salaryProfile.isSuspension = body.isSuspension;
|
salaryProfile.isSuspension = body.isSuspension;
|
||||||
salaryProfile.isAbsent = body.isAbsent;
|
salaryProfile.isAbsent = body.isAbsent;
|
||||||
|
|
@ -1582,7 +1635,9 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryProfile.lastUpdateUserId = request.user.sub;
|
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||||
salaryProfile.lastUpdateFullName = request.user.name;
|
salaryProfile.lastUpdateFullName = request.user.name;
|
||||||
salaryProfile.lastUpdatedAt = new Date();
|
salaryProfile.lastUpdatedAt = new Date();
|
||||||
await this.salaryProfileRepository.save(salaryProfile);
|
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: salaryProfile });
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1974,12 +2029,16 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const before = null;
|
||||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
salaryProfile.salaryOrgId = salaryOrg.id;
|
||||||
salaryProfile.createdUserId = request.user.sub;
|
salaryProfile.createdUserId = request.user.sub;
|
||||||
salaryProfile.createdFullName = request.user.name;
|
salaryProfile.createdFullName = request.user.name;
|
||||||
salaryProfile.lastUpdateUserId = request.user.sub;
|
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||||
salaryProfile.lastUpdateFullName = request.user.name;
|
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({
|
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
|
@ -2010,7 +2069,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryOrg.quantityUsed = amountFullType;
|
salaryOrg.quantityUsed = amountFullType;
|
||||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||||
salaryOrg.remainQuota = calRemainQuota;
|
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") {
|
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||||
|
|
@ -2064,7 +2127,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
? 0
|
? 0
|
||||||
: sumAmountUse.totalAmount;
|
: sumAmountUse.totalAmount;
|
||||||
salaryOrg.remainingAmount = calRemainAmount;
|
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 รอบเงินเดือน
|
* @param {string} id Guid, *Id รอบเงินเดือน
|
||||||
*/
|
*/
|
||||||
@Get("close/{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({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!salaryPeriod) {
|
if (!salaryPeriod) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
||||||
}
|
}
|
||||||
|
const before = structuredClone(salaryPeriod);
|
||||||
salaryPeriod.isClose = !salaryPeriod.isClose;
|
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();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2127,13 +2199,16 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
"ประเภทผังปี " + Extension.ToThaiYear(salaryPeriod.year) + " ซ้ำ",
|
"ประเภทผังปี " + Extension.ToThaiYear(salaryPeriod.year) + " ซ้ำ",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const before = null;
|
||||||
salaryPeriod.period = salaryPeriod.period.toUpperCase();
|
salaryPeriod.period = salaryPeriod.period.toUpperCase();
|
||||||
salaryPeriod.createdUserId = request.user.sub;
|
salaryPeriod.createdUserId = request.user.sub;
|
||||||
salaryPeriod.createdFullName = request.user.name;
|
salaryPeriod.createdFullName = request.user.name;
|
||||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
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") {
|
if (salaryPeriod.period == "SPECIAL") {
|
||||||
const snapshot = "SNAP1";
|
const snapshot = "SNAP1";
|
||||||
|
|
@ -2143,14 +2218,18 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
const salaryProfile = await this.salaryProfileRepository.find({
|
const salaryProfile = await this.salaryProfileRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryOrgRepository.remove(salaryOrg);
|
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||||
await this.salaryProfileRepository.remove(salaryProfile);
|
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||||
|
|
||||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||||
|
|
||||||
salaryPeriod.revisionId = revisionId;
|
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(
|
await Promise.all(
|
||||||
orgs.map(async (rootId: string) => {
|
orgs.map(async (rootId: string) => {
|
||||||
|
|
@ -2164,8 +2243,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryOrgNew.createdFullName = request.user.name;
|
salaryOrgNew.createdFullName = request.user.name;
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
|
salaryOrgNew.createdAt = new Date();
|
||||||
|
salaryOrgNew.lastUpdatedAt = new Date();
|
||||||
salaryOrgNew.group = "GROUP1";
|
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) + " ซ้ำ",
|
"ประเภทผังปี " + (requestBody.effectiveDate.getFullYear() + 543) + " ซ้ำ",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const beforechk_SalaryPeriod = structuredClone(chk_SalaryPeriod);
|
||||||
chk_SalaryPeriod.period = requestBody.period.toUpperCase();
|
chk_SalaryPeriod.period = requestBody.period.toUpperCase();
|
||||||
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
||||||
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
||||||
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
||||||
this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody);
|
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") {
|
if (chk_SalaryPeriod.period == "SPECIAL") {
|
||||||
const snapshot = "SNAP1";
|
const snapshot = "SNAP1";
|
||||||
const salaryOrg = await this.salaryOrgRepository.find({
|
const salaryOrg = await this.salaryOrgRepository.find({
|
||||||
|
|
@ -2226,18 +2310,23 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
const salaryProfile = await this.salaryProfileRepository.find({
|
const salaryProfile = await this.salaryProfileRepository.find({
|
||||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||||
});
|
});
|
||||||
await this.salaryOrgRepository.remove(salaryOrg);
|
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||||
await this.salaryProfileRepository.remove(salaryProfile);
|
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||||
|
|
||||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||||
|
|
||||||
chk_SalaryPeriod.revisionId = revisionId;
|
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(
|
await Promise.all(
|
||||||
orgs.map(async (rootId: string) => {
|
orgs.map(async (rootId: string) => {
|
||||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||||
|
const before = structuredClone(salaryOrgNew);
|
||||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||||
salaryOrgNew.status = "PENDING";
|
salaryOrgNew.status = "PENDING";
|
||||||
salaryOrgNew.rootId = rootId;
|
salaryOrgNew.rootId = rootId;
|
||||||
|
|
@ -2247,8 +2336,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryOrgNew.createdFullName = request.user.name;
|
salaryOrgNew.createdFullName = request.user.name;
|
||||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||||
|
salaryOrgNew.createdAt = new Date();
|
||||||
|
salaryOrgNew.lastUpdatedAt = new Date();
|
||||||
salaryOrgNew.group = "GROUP1";
|
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);
|
const salaryProfile = SalaryOrg.find((x) => x.salaryProfiles.length > 0);
|
||||||
if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||||
|
|
||||||
await this.salaryOrgRepository.remove(SalaryOrg);
|
await this.salaryOrgRepository.remove(SalaryOrg, { data: request });
|
||||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
} else {
|
} else {
|
||||||
const SalaryOrg = await this.salaryOrgRepository.findOne({
|
const SalaryOrg = await this.salaryOrgRepository.findOne({
|
||||||
|
|
@ -2288,7 +2380,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
});
|
});
|
||||||
if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
|
||||||
|
|
||||||
await this.salaryPeriodRepository.remove(SalaryPeriod);
|
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2397,7 +2489,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
* @param {string} rootId Guid, *Id สำนัก
|
* @param {string} rootId Guid, *Id สำนัก
|
||||||
*/
|
*/
|
||||||
@Get("officer/approve/{periodId}/{rootId}")
|
@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({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
where: { id: periodId },
|
where: { id: periodId },
|
||||||
relations: ["salaryOrgEmployees"],
|
relations: ["salaryOrgEmployees"],
|
||||||
|
|
@ -2408,8 +2504,13 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryPeriod.salaryOrgEmployees
|
salaryPeriod.salaryOrgEmployees
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x: any) => {
|
.map(async (x: any) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "WAITHEAD1";
|
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();
|
return new HttpSuccess();
|
||||||
|
|
@ -2423,7 +2524,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
* @param {string} rootId Guid, *Id สำนัก
|
* @param {string} rootId Guid, *Id สำนัก
|
||||||
*/
|
*/
|
||||||
@Get("head/approve/{periodId}/{rootId}")
|
@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({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
where: { id: periodId },
|
where: { id: periodId },
|
||||||
relations: ["salaryOrgEmployees"],
|
relations: ["salaryOrgEmployees"],
|
||||||
|
|
@ -2435,8 +2536,13 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryPeriod.salaryOrgEmployees
|
salaryPeriod.salaryOrgEmployees
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x: any) => {
|
.map(async (x: any) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "WAITOWNER1";
|
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();
|
return new HttpSuccess();
|
||||||
|
|
@ -2450,7 +2556,11 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
* @param {string} rootId Guid, *Id สำนัก
|
* @param {string} rootId Guid, *Id สำนัก
|
||||||
*/
|
*/
|
||||||
@Get("owner/approve/{periodId}/{rootId}")
|
@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({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
where: { id: periodId },
|
where: { id: periodId },
|
||||||
relations: ["salaryOrgEmployees"],
|
relations: ["salaryOrgEmployees"],
|
||||||
|
|
@ -2462,8 +2572,13 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryPeriod.salaryOrgEmployees
|
salaryPeriod.salaryOrgEmployees
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x: any) => {
|
.map(async (x: any) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "REPORT";
|
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();
|
return new HttpSuccess();
|
||||||
|
|
@ -2484,7 +2599,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
body: {
|
body: {
|
||||||
titleRecommend: string;
|
titleRecommend: string;
|
||||||
},
|
},
|
||||||
@Request() request: RequestWithUser
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_WAGE");
|
await new permission().PermissionUpdate(request, "SYS_WAGE");
|
||||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
|
|
@ -2498,9 +2613,14 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryPeriod.salaryOrgEmployees
|
salaryPeriod.salaryOrgEmployees
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x: any) => {
|
.map(async (x: any) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "WAITHEAD2";
|
x.status = "WAITHEAD2";
|
||||||
x.ownerRecommend = body.titleRecommend;
|
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();
|
return new HttpSuccess();
|
||||||
|
|
@ -2521,7 +2641,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
body: {
|
body: {
|
||||||
titleRecommend: string;
|
titleRecommend: string;
|
||||||
},
|
},
|
||||||
@Request() request: RequestWithUser
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_WAGE");
|
await new permission().PermissionUpdate(request, "SYS_WAGE");
|
||||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||||
|
|
@ -2535,9 +2655,14 @@ export class SalaryPeriodEmployeeController extends Controller {
|
||||||
salaryPeriod.salaryOrgEmployees
|
salaryPeriod.salaryOrgEmployees
|
||||||
.filter((x) => x.rootId == rootId)
|
.filter((x) => x.rootId == rootId)
|
||||||
.map(async (x: any) => {
|
.map(async (x: any) => {
|
||||||
|
const before = structuredClone(x);
|
||||||
x.status = "REPORT";
|
x.status = "REPORT";
|
||||||
x.ownerRecommend = body.titleRecommend;
|
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();
|
return new HttpSuccess();
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,17 @@ import {
|
||||||
Get,
|
Get,
|
||||||
Query,
|
Query,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { Brackets, Like } from "typeorm";
|
import { Brackets } from "typeorm";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { CreateSalaryRank, SalaryRanks, UpdateSalaryRank } from "../entities/SalaryRanks";
|
import { CreateSalaryRank, SalaryRanks, UpdateSalaryRank } from "../entities/SalaryRanks";
|
||||||
import { Salarys } from "../entities/Salarys";
|
import { Salarys } from "../entities/Salarys";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary/rate")
|
@Route("api/v1/salary/rate")
|
||||||
@Tags("SalaryRank")
|
@Tags("SalaryRank")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -43,10 +45,11 @@ export class SalaryRanksController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post()
|
@Post()
|
||||||
async CreateSalaryRank(
|
async CreateSalaryRank(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: CreateSalaryRank,
|
requestBody: CreateSalaryRank,
|
||||||
@Request() request: { user: Record<string, any> },
|
|
||||||
) {
|
) {
|
||||||
|
await new permission().PermissionCreate(request, "SYS_SALARY_CHART_OFFICER");
|
||||||
try {
|
try {
|
||||||
const checkSalary = await this.salaryRepository.findOne({
|
const checkSalary = await this.salaryRepository.findOne({
|
||||||
where: { id: requestBody.salaryId },
|
where: { id: requestBody.salaryId },
|
||||||
|
|
@ -54,12 +57,16 @@ export class SalaryRanksController extends Controller {
|
||||||
if (!checkSalary) {
|
if (!checkSalary) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้");
|
||||||
}
|
}
|
||||||
|
const before = null;
|
||||||
const salaryRank = Object.assign(new SalaryRanks(), requestBody);
|
const salaryRank = Object.assign(new SalaryRanks(), requestBody);
|
||||||
salaryRank.createdUserId = request.user.sub;
|
salaryRank.createdUserId = request.user.sub;
|
||||||
salaryRank.createdFullName = request.user.name;
|
salaryRank.createdFullName = request.user.name;
|
||||||
salaryRank.lastUpdateUserId = request.user.sub;
|
salaryRank.lastUpdateUserId = request.user.sub;
|
||||||
salaryRank.lastUpdateFullName = request.user.name;
|
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();
|
return new HttpSuccess();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|
@ -75,19 +82,23 @@ export class SalaryRanksController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Put("{id}")
|
@Put("{id}")
|
||||||
async updateSalaryRanks(
|
async updateSalaryRanks(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: UpdateSalaryRank,
|
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 } });
|
const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } });
|
||||||
if (!salaryRank) {
|
if (!salaryRank) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้");
|
||||||
}
|
}
|
||||||
|
const before = structuredClone(salaryRank);
|
||||||
salaryRank.lastUpdateUserId = request.user.sub;
|
salaryRank.lastUpdateUserId = request.user.sub;
|
||||||
salaryRank.lastUpdateFullName = request.user.name;
|
salaryRank.lastUpdateFullName = request.user.name;
|
||||||
|
salaryRank.lastUpdatedAt = new Date();
|
||||||
this.salaryRankRepository.merge(salaryRank, requestBody);
|
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();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +110,8 @@ export class SalaryRanksController extends Controller {
|
||||||
* @param {string} id Id อัตราเงินเดือน
|
* @param {string} id Id อัตราเงินเดือน
|
||||||
*/
|
*/
|
||||||
@Delete("{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({
|
const delSalaryRanks = await this.salaryRankRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
|
|
@ -119,13 +131,14 @@ export class SalaryRanksController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async listSalaryRanks(
|
async listSalaryRanks(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("keyword") keyword?: string,
|
@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)
|
const [salaryRank, total] = await AppDataSource.getRepository(SalaryRanks)
|
||||||
.createQueryBuilder("salaryRank")
|
.createQueryBuilder("salaryRank")
|
||||||
.andWhere(
|
.andWhere(
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import {
|
||||||
Get,
|
Get,
|
||||||
Query,
|
Query,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { Not, Like, Brackets } from "typeorm";
|
import { Not, Brackets } from "typeorm";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
|
@ -27,6 +27,8 @@ import {
|
||||||
import { SalaryEmployee } from "../entities/SalaryEmployee";
|
import { SalaryEmployee } from "../entities/SalaryEmployee";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
@Route("api/v1/salary/rate/employee")
|
@Route("api/v1/salary/rate/employee")
|
||||||
@Tags("SalaryRankEmployee")
|
@Tags("SalaryRankEmployee")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -46,10 +48,11 @@ export class SalaryRankEmployeeController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post()
|
@Post()
|
||||||
async CreateSalaryRankEmployee(
|
async CreateSalaryRankEmployee(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: CreateSalaryRankEmployee,
|
requestBody: CreateSalaryRankEmployee,
|
||||||
@Request() request: { user: Record<string, any> },
|
|
||||||
) {
|
) {
|
||||||
|
await new permission().PermissionCreate(request, "SYS_WAGE_CHART_EMP");
|
||||||
try {
|
try {
|
||||||
const checkSalary = await this.salaryEmployeeRepository.findOne({
|
const checkSalary = await this.salaryEmployeeRepository.findOne({
|
||||||
where: { id: requestBody.salaryEmployeeId },
|
where: { id: requestBody.salaryEmployeeId },
|
||||||
|
|
@ -67,11 +70,15 @@ export class SalaryRankEmployeeController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเพิ่มได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเพิ่มได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
|
||||||
}
|
}
|
||||||
const salaryRankEmployee = Object.assign(new SalaryRankEmployee(), requestBody);
|
const salaryRankEmployee = Object.assign(new SalaryRankEmployee(), requestBody);
|
||||||
|
const before = null;
|
||||||
salaryRankEmployee.createdUserId = request.user.sub;
|
salaryRankEmployee.createdUserId = request.user.sub;
|
||||||
salaryRankEmployee.createdFullName = request.user.name;
|
salaryRankEmployee.createdFullName = request.user.name;
|
||||||
salaryRankEmployee.lastUpdateUserId = request.user.sub;
|
salaryRankEmployee.lastUpdateUserId = request.user.sub;
|
||||||
salaryRankEmployee.lastUpdateFullName = request.user.name;
|
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();
|
return new HttpSuccess();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|
@ -86,11 +93,12 @@ export class SalaryRankEmployeeController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Put("{id}")
|
@Put("{id}")
|
||||||
async updateSalaryRankEmployees(
|
async updateSalaryRankEmployees(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: UpdateSalaryRankEmployee,
|
requestBody: UpdateSalaryRankEmployee,
|
||||||
@Request() request: { user: Record<string, any> },
|
|
||||||
) {
|
) {
|
||||||
|
await new permission().PermissionUpdate(request, "SYS_WAGE_CHART_EMP");
|
||||||
const salaryRankEmployee = await this.salaryRankEmployeeRepository.findOne({
|
const salaryRankEmployee = await this.salaryRankEmployeeRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -107,10 +115,13 @@ export class SalaryRankEmployeeController extends Controller {
|
||||||
if (checkStep.length > 0) {
|
if (checkStep.length > 0) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถแก้ไขได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถแก้ไขได้ เนื่องจากลำดับขั้นนี้ซ้ำ");
|
||||||
}
|
}
|
||||||
|
const before = structuredClone(salaryRankEmployee);
|
||||||
salaryRankEmployee.lastUpdateUserId = request.user.sub;
|
salaryRankEmployee.lastUpdateUserId = request.user.sub;
|
||||||
salaryRankEmployee.lastUpdateFullName = request.user.name;
|
salaryRankEmployee.lastUpdateFullName = request.user.name;
|
||||||
|
salaryRankEmployee.lastUpdatedAt = new Date();
|
||||||
this.salaryRankEmployeeRepository.merge(salaryRankEmployee, requestBody);
|
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();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +132,8 @@ export class SalaryRankEmployeeController extends Controller {
|
||||||
* @param {string} id Id อัตราเงินเดือน
|
* @param {string} id Id อัตราเงินเดือน
|
||||||
*/
|
*/
|
||||||
@Delete("{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({
|
const delSalaryRankEmployees = await this.salaryRankEmployeeRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,45 @@
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
import "reflect-metadata";
|
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({
|
export const AppDataSource = new DataSource({
|
||||||
type: "mysql",
|
type: "mysql",
|
||||||
|
|
@ -11,7 +50,7 @@ export const AppDataSource = new DataSource({
|
||||||
password: process.env.DB_PASSWORD,
|
password: process.env.DB_PASSWORD,
|
||||||
connectorPackage: "mysql2",
|
connectorPackage: "mysql2",
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
logging: true,
|
logging: ["query", "error"],
|
||||||
entities:
|
entities:
|
||||||
process.env.NODE_ENV !== "production"
|
process.env.NODE_ENV !== "production"
|
||||||
? ["src/entities/**/*.ts"]
|
? ["src/entities/**/*.ts"]
|
||||||
|
|
@ -21,7 +60,5 @@ export const AppDataSource = new DataSource({
|
||||||
? ["src/migration/**/*.ts"]
|
? ["src/migration/**/*.ts"]
|
||||||
: ["dist/migration/**/*{.ts,.js}"],
|
: ["dist/migration/**/*{.ts,.js}"],
|
||||||
subscribers: [],
|
subscribers: [],
|
||||||
|
logger: new MyCustomLogger(),
|
||||||
});
|
});
|
||||||
// console.log(AppDataSource);
|
|
||||||
|
|
||||||
// export default database;
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {
|
||||||
Path,
|
Path,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { addLogSequence } from "./utils";
|
||||||
|
|
||||||
class CallAPI {
|
class CallAPI {
|
||||||
//Get
|
//Get
|
||||||
|
|
@ -26,8 +27,28 @@ class CallAPI {
|
||||||
api_key: process.env.API_KEY,
|
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;
|
return response.data.result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
addLogSequence(request, {
|
||||||
|
action: "request",
|
||||||
|
status: "error",
|
||||||
|
description: "unconnected",
|
||||||
|
request: {
|
||||||
|
method: "GET",
|
||||||
|
url: url,
|
||||||
|
response: JSON.stringify(error),
|
||||||
|
},
|
||||||
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,8 +64,30 @@ class CallAPI {
|
||||||
api_key: process.env.API_KEY,
|
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;
|
return response.data.result;
|
||||||
} catch (error) {
|
} 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;
|
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 axios from "axios";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import CallAPI from "./call-api";
|
import CallAPI from "./call-api";
|
||||||
|
|
@ -26,23 +13,155 @@ class CheckAuth {
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
await new CallAPI()
|
return await new CallAPI()
|
||||||
.GetData(req, "/org/permission")
|
.GetData(req, "/org/permission")
|
||||||
.then((x) => {
|
.then((x) => {
|
||||||
let permission = false;
|
let permission = false;
|
||||||
let role = x.roles.find((x: any) => x.authSysId == system);
|
let role = x.roles.find((x: any) => x.authSysId == system);
|
||||||
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
|
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
|
||||||
|
if (role.attrOwnership == "OWNER") return "OWNER";
|
||||||
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate;
|
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate;
|
||||||
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete;
|
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete;
|
||||||
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet;
|
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet;
|
||||||
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList;
|
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList;
|
||||||
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate;
|
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate;
|
||||||
if (role.attrOwnership == "OWNER") permission = true;
|
|
||||||
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
|
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
|
||||||
return role.attrPrivilege;
|
return role.attrPrivilege;
|
||||||
})
|
})
|
||||||
.catch((x) => {
|
.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) {
|
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||||
|
|
@ -60,6 +179,38 @@ class CheckAuth {
|
||||||
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
||||||
return await this.Permission(req, system, "UPDATE");
|
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;
|
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 HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
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) {
|
if (!process.env.AUTH_PUBLIC_KEY && !process.env.AUTH_REALM_URL) {
|
||||||
throw new Error("Require keycloak AUTH_PUBLIC_KEY or AUTH_REALM_URL.");
|
throw new Error("Require keycloak AUTH_PUBLIC_KEY or AUTH_REALM_URL.");
|
||||||
}
|
}
|
||||||
if (
|
if (process.env.AUTH_PUBLIC_KEY && process.env.AUTH_REALM_URL && !process.env.AUTH_PREFERRED_MODE) {
|
||||||
process.env.AUTH_PUBLIC_KEY &&
|
|
||||||
process.env.AUTH_REALM_URL &&
|
|
||||||
!process.env.AUTH_PREFERRED_MODE
|
|
||||||
) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"AUTH_PREFFERRED must be specified if AUTH_PUBLIC_KEY and AUTH_REALM_URL is provided.",
|
"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();
|
const jwtDecode = createDecoder();
|
||||||
|
|
||||||
export async function expressAuthentication(
|
export async function expressAuthentication(
|
||||||
request: express.Request,
|
request: RequestWithUser,
|
||||||
securityName: string,
|
securityName: string,
|
||||||
_scopes?: string[],
|
_scopes?: string[],
|
||||||
) {
|
) {
|
||||||
|
|
@ -56,6 +54,18 @@ export async function expressAuthentication(
|
||||||
if (process.env.AUTH_PUBLIC_KEY) payload = await verifyOffline(token);
|
if (process.env.AUTH_PUBLIC_KEY) payload = await verifyOffline(token);
|
||||||
break;
|
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;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,12 @@ import HttpStatus from "../interfaces/http-status";
|
||||||
import { ValidateError } from "tsoa";
|
import { ValidateError } from "tsoa";
|
||||||
|
|
||||||
function error(error: Error, _req: Request, res: Response, _next: NextFunction) {
|
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) {
|
if (error instanceof HttpError) {
|
||||||
return res.status(error.status).json({
|
return res.status(error.status).json({
|
||||||
status: error.status,
|
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