This commit is contained in:
AdisakKanthawilang 2024-08-07 17:34:44 +07:00
parent 8a36a6c977
commit 6fc0c04a9b
4 changed files with 202 additions and 6 deletions

View file

@ -27,6 +27,7 @@ import {
UpdateDevelopment5,
UpdateDevelopment7,
UpdateDevelopment8,
UpdateDevelopment8_1,
} from "../entities/Development";
import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople";
import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople";
@ -60,12 +61,14 @@ import { FileInterceptor } from "@nestjs/platform-express";
import * as xlsx from "xlsx";
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
import { DevelopmentRisk } from "../entities/DevelopmentRisk";
@Route("api/v1/development/main")
@Tags("Development")
@Security("bearerAuth")
export class DevelopmentController extends Controller {
private developmentRepository = AppDataSource.getRepository(Development);
private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk);
private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress);
private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation);
private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType);
@ -1410,10 +1413,11 @@ export class DevelopmentController extends Controller {
await this.developmentRepository.save(development, { data: request });
return new HttpSuccess(development.id);
}
/**
* API / tab6
* API / tab7
*
* @summary DEV_00 - /tab6 #
* @summary DEV_00 - /tab7 #
*
* @param {string} id Id
*/
@ -1434,6 +1438,38 @@ export class DevelopmentController extends Controller {
return new HttpSuccess(_getDevelopment);
}
/**
* API / tab8
*
* @summary DEV_00 - /tab8 #
*
* @param {string} id Id
*/
@Get("tab8/{id}")
async GetDevelopemtTab8ById(@Path() id: string) {
const getDevelopment = await this.developmentRepository.findOne({
relations: ["developmentRisks"],
where: { id: id },
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
let _getDevelopment = {
developmentRisks:
getDevelopment.developmentRisks == null
? null
: getDevelopment.developmentRisks.sort((a, b) =>
(a.id == null ? "" : a.id).localeCompare(
b.id == null ? "" : b.id,
),
),
expect: getDevelopment.expect,
};
return new HttpSuccess(_getDevelopment);
}
/**
* API / tab8
*
@ -1460,6 +1496,82 @@ export class DevelopmentController extends Controller {
await this.developmentRepository.save(development, { data: request });
return new HttpSuccess(development.id);
}
/**
* API /tab8-1
*
* @summary DEV_00 - /tab8-1 #
*
* @param {string} id Id
*/
@Put("tab8_1_add/{id}")
async CreateDevelopmenttab8_1(
@Path() id: string,
@Body() requestBody: UpdateDevelopment8_1,
@Request() request: RequestWithUser,
) {
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
const before = structuredClone(development);
const data = Object.assign(new DevelopmentEvaluation(), requestBody);
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.developmentId = development.id;
await this.developmentEvaluationRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: development });
return new HttpSuccess(data.id);
}
/**
* API /tab8-1
*
* @summary DEV_00 - /tab8-1 #
*
* @param {string} id Id
*/
@Delete("tab8_1/{id}")
async DeleteDevelopmenttab8_1(@Path() id: string, @Request() request: RequestWithUser) {
const development = await this.developmentEvaluationRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน");
}
await this.developmentEvaluationRepository.remove(development, { data: request });
return new HttpSuccess(development.id);
}
/**
* API /tab8-1
*
* @summary DEV_00 - /tab8-1 #
*
* @param {string} id Id
*/
@Put("tab8_1_edit/{id}")
async UpdateDevelopmenttab8_1(
@Path() id: string,
@Body() requestBody: UpdateDevelopment8_1,
@Request() request: RequestWithUser,
) {
const development = await this.developmentEvaluationRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
await this.developmentEvaluationRepository.save(development, { data: request });
return new HttpSuccess(development.id);
}
/**
* API