This commit is contained in:
AdisakKanthawilang 2024-07-25 17:06:42 +07:00
parent 4b34fc20b8
commit 1c9cb7ea78
11 changed files with 741 additions and 122 deletions

View file

@ -25,6 +25,8 @@ import {
} from "../entities/DevelopmentHistory";
import { EmployeePosType } from "../entities/EmployeePosType";
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { RequestWithUser } from "../middlewares/user";
import { addLogSequence } from "../interfaces/utils";
@Route("api/v1/development/history/employee")
@Tags("DevelopmentEmployeeHistory")
@ -72,7 +74,7 @@ export class DevelopmentEmployeeHistoryController extends Controller {
@Post()
async CreateDevelopmentHistory(
@Body() requestBody: CreateDevelopmentHistory,
@Request() request: { user: Record<string, any> },
@Request() request: RequestWithUser,
) {
const type = "EMPLOYEE";
const chk_name = await this.developmentHistoryRepository.find({
@ -119,7 +121,12 @@ export class DevelopmentEmployeeHistoryController extends Controller {
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
await this.developmentHistoryRepository.save(development);
addLogSequence(request, {
action: "database",
status: "success",
description: "Store DevelopmentHistory.",
});
await this.developmentHistoryRepository.save(development, { data: request });
return new HttpSuccess(development.id);
}
@ -134,7 +141,7 @@ export class DevelopmentEmployeeHistoryController extends Controller {
async UpdateDevelopmentHistory(
@Path() id: string,
@Body() requestBody: UpdateDevelopmentHistory,
@Request() request: { user: Record<string, any> },
@Request() request: RequestWithUser,
) {
const type = "EMPLOYEE";
const development = await this.developmentHistoryRepository.findOne({
@ -184,7 +191,12 @@ export class DevelopmentEmployeeHistoryController extends Controller {
development.posLevelId = null;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
await this.developmentHistoryRepository.save(development);
addLogSequence(request, {
action: "database",
status: "success",
description: "Store DevelopmentHistory.",
});
await this.developmentHistoryRepository.save(development, { data: request });
return new HttpSuccess(development.id);
}
@ -196,7 +208,7 @@ export class DevelopmentEmployeeHistoryController extends Controller {
* @param {string} id Id
*/
@Delete("{id}")
async DeleteDevelopmentHistory(@Path() id: string) {
async DeleteDevelopmentHistory(@Path() id: string,@Request () request: RequestWithUser) {
const type = "EMPLOYEE";
const development = await this.developmentHistoryRepository.findOne({
where: { id: id, type: type },
@ -204,8 +216,12 @@ export class DevelopmentEmployeeHistoryController extends Controller {
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
}
await this.developmentHistoryRepository.remove(development);
addLogSequence(request, {
action: "remove",
status: "success",
description: "Remove DevelopmentHistory.",
});
await this.developmentHistoryRepository.remove(development, { data: request });
return new HttpSuccess();
}