log
This commit is contained in:
parent
4b34fc20b8
commit
1c9cb7ea78
11 changed files with 741 additions and 122 deletions
|
|
@ -26,6 +26,9 @@ import {
|
|||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
|
||||
import { request } from "axios";
|
||||
|
||||
@Route("api/v1/development/scholarship")
|
||||
@Tags("DevelopmentScholarship")
|
||||
|
|
@ -44,9 +47,14 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
@Post()
|
||||
async CreateDevelopmentScholarship(
|
||||
@Body() requestBody: CreateDevelopmentScholarship,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
if (requestBody.posTypeId != null) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Get Position Type.",
|
||||
// });
|
||||
const checkId = await this.posTypeRepository.findOne({
|
||||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
|
|
@ -55,6 +63,11 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
}
|
||||
}
|
||||
if (requestBody.posLevelId != null) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Get Position Level.",
|
||||
// });
|
||||
const checkId = await this.posLevelRepository.findOne({
|
||||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
|
|
@ -68,7 +81,12 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
development.createdFullName = request.user.name;
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
development.lastUpdateFullName = request.user.name;
|
||||
await this.developmentScholarshipRepository.save(development);
|
||||
addLogSequence(request, {
|
||||
action: "database",
|
||||
status: "success",
|
||||
description: "Store Development Scholarship.",
|
||||
});
|
||||
await this.developmentScholarshipRepository.save(development, { data: request });
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
|
||||
|
|
@ -83,8 +101,13 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
async UpdateDevelopmentScholarship(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdateDevelopmentScholarship,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Get Development Scholarship.",
|
||||
// });
|
||||
const development = await this.developmentScholarshipRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
|
|
@ -92,6 +115,11 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
|
||||
}
|
||||
if (requestBody.posTypeId != null) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Get Position Type.",
|
||||
// });
|
||||
const checkId = await this.posTypeRepository.findOne({
|
||||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
|
|
@ -100,6 +128,11 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
}
|
||||
}
|
||||
if (requestBody.posLevelId != null) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Get Position Level.",
|
||||
// });
|
||||
const checkId = await this.posLevelRepository.findOne({
|
||||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
|
|
@ -107,10 +140,17 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
||||
}
|
||||
}
|
||||
const before = structuredClone(development);
|
||||
Object.assign(development, requestBody);
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
development.lastUpdateFullName = request.user.name;
|
||||
await this.developmentScholarshipRepository.save(development);
|
||||
addLogSequence(request, {
|
||||
action: "database",
|
||||
status: "success",
|
||||
description: "Store DevelopmentScholarship.",
|
||||
});
|
||||
await this.developmentScholarshipRepository.save(development, { data: request });
|
||||
setLogDataDiff(request, { before, after: development });
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
|
||||
|
|
@ -122,15 +162,24 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
* @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async DeleteDevelopmentScholarship(@Path() id: string) {
|
||||
async DeleteDevelopmentScholarship(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Get Development Scholarship",
|
||||
// });
|
||||
const development = await this.developmentScholarshipRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!development) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
|
||||
}
|
||||
|
||||
await this.developmentScholarshipRepository.remove(development);
|
||||
addLogSequence(request, {
|
||||
action: "remove",
|
||||
status: "success",
|
||||
description: "Remove Development Scholarship By ID.",
|
||||
});
|
||||
await this.developmentScholarshipRepository.remove(development, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -422,19 +471,30 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
async UpdateDevelopemtScholarshipUserById(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdateDevelopmentScholarshipUser,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Get Development Scholarship.",
|
||||
// });
|
||||
const getDevelopment = await this.developmentScholarshipRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!getDevelopment) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
|
||||
}
|
||||
const before = structuredClone(getDevelopment);
|
||||
Object.assign(getDevelopment, requestBody);
|
||||
getDevelopment.lastUpdateUserId = request.user.sub;
|
||||
getDevelopment.lastUpdateFullName = request.user.name;
|
||||
await this.developmentScholarshipRepository.save(getDevelopment);
|
||||
|
||||
addLogSequence(request, {
|
||||
action: "database",
|
||||
status: "success",
|
||||
description: "Store DevelopmentScholarship.",
|
||||
});
|
||||
await this.developmentScholarshipRepository.save(getDevelopment, { data: request });
|
||||
setLogDataDiff(request, { before, after: getDevelopment });
|
||||
return new HttpSuccess(getDevelopment.id);
|
||||
}
|
||||
|
||||
|
|
@ -450,8 +510,13 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
async ChangeStatusDevelopemtScholarshipById(
|
||||
@Path() id: string,
|
||||
@Path() status: string,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Get Development Scholarship.",
|
||||
// });
|
||||
const getDevelopment = await this.developmentScholarshipRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
|
|
@ -465,6 +530,11 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
let scholarshipType = "";
|
||||
if (_status == "GRADUATE") {
|
||||
if (getDevelopment.scholarshipType != null) {
|
||||
// addLogSequence(request, {
|
||||
// action: "database",
|
||||
// status: "success",
|
||||
// description: "Change Status Development Scholarship.",
|
||||
// });
|
||||
switch (getDevelopment.scholarshipType.trim().toUpperCase()) {
|
||||
case "DOMESTICE":
|
||||
scholarshipType = "การศึกษาในประเทศ";
|
||||
|
|
@ -509,14 +579,19 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
positionPathId: null,
|
||||
})
|
||||
.then(async (x) => {
|
||||
await this.developmentScholarshipRepository.save(getDevelopment);
|
||||
await this.developmentScholarshipRepository.save(getDevelopment, { data: request });
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("ไม่สามารถบันทึกลงทะเบียนประวัติได้");
|
||||
});
|
||||
} else if (_status == "NOTGRADUATE") {
|
||||
getDevelopment.status = _status;
|
||||
await this.developmentScholarshipRepository.save(getDevelopment);
|
||||
addLogSequence(request, {
|
||||
action: "database",
|
||||
status: "success",
|
||||
description: "Change Status Development Scholarship.",
|
||||
});
|
||||
await this.developmentScholarshipRepository.save(getDevelopment, { data: request });
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue