api tab5
This commit is contained in:
parent
15a730d4a9
commit
b8575cd3a0
3 changed files with 96 additions and 37 deletions
|
|
@ -62,6 +62,7 @@ import * as xlsx from "xlsx";
|
||||||
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
|
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk";
|
import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk";
|
||||||
|
import { DevelopmentOther, UpdateDevelopmentOther } from "../entities/DevelopmentOther";
|
||||||
|
|
||||||
@Route("api/v1/development/main")
|
@Route("api/v1/development/main")
|
||||||
@Tags("Development")
|
@Tags("Development")
|
||||||
|
|
@ -69,6 +70,7 @@ import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentR
|
||||||
export class DevelopmentController extends Controller {
|
export class DevelopmentController extends Controller {
|
||||||
private developmentRepository = AppDataSource.getRepository(Development);
|
private developmentRepository = AppDataSource.getRepository(Development);
|
||||||
private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk);
|
private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk);
|
||||||
|
private developmentOtherRepository = AppDataSource.getRepository(DevelopmentOther);
|
||||||
private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress);
|
private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress);
|
||||||
private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation);
|
private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation);
|
||||||
private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType);
|
private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType);
|
||||||
|
|
@ -1332,7 +1334,32 @@ export class DevelopmentController extends Controller {
|
||||||
if (!development) {
|
if (!development) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||||
}
|
}
|
||||||
if (requestBody.provinceActualId != null) {
|
Object.assign(development, { ...requestBody, developmentAddresss: [] });
|
||||||
|
development.lastUpdateUserId = request.user.sub;
|
||||||
|
development.lastUpdateFullName = request.user.name;
|
||||||
|
await this.developmentRepository.save(development, { data: request });
|
||||||
|
return new HttpSuccess(development.id);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab5-1
|
||||||
|
*
|
||||||
|
* @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab5-1 #
|
||||||
|
*
|
||||||
|
* @param {string} id Id โครงการ
|
||||||
|
*/
|
||||||
|
@Put("tab5_1_add/{id}")
|
||||||
|
async CreateDevelopmenttab5_1(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body() requestBody: UpdateDevelopmentOther,
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
|
) {
|
||||||
|
const development = await this.developmentRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
if (!development) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||||
|
}
|
||||||
|
if (requestBody.provinceActualId != null) {
|
||||||
const checkId = await this.provinceRepository.findOne({
|
const checkId = await this.provinceRepository.findOne({
|
||||||
where: { id: requestBody.provinceActualId },
|
where: { id: requestBody.provinceActualId },
|
||||||
});
|
});
|
||||||
|
|
@ -1340,10 +1367,61 @@ export class DevelopmentController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object.assign(development, { ...requestBody, developmentAddresss: [] });
|
const before = structuredClone(development);
|
||||||
|
const data = Object.assign(new DevelopmentOther(), 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.developmentOtherRepository.save(data, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: development });
|
||||||
|
return new HttpSuccess(data.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบโครงการ/หลักสูตรการฝึกอบรมtab5-1
|
||||||
|
*
|
||||||
|
* @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab5-1 #
|
||||||
|
*
|
||||||
|
* @param {string} id Id รายการ
|
||||||
|
*/
|
||||||
|
@Delete("tab5_1/{id}")
|
||||||
|
async DeleteDevelopmenttab5_1(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
|
const development = await this.developmentOtherRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
if (!development) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
|
||||||
|
}
|
||||||
|
await this.developmentOtherRepository.remove(development, { data: request });
|
||||||
|
return new HttpSuccess(development.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab5-1
|
||||||
|
*
|
||||||
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab5-1 #
|
||||||
|
*
|
||||||
|
* @param {string} id Id รายการ
|
||||||
|
*/
|
||||||
|
@Put("tab5_1_edit/{id}")
|
||||||
|
async UpdateDevelopmenttab5_1(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body() requestBody: UpdateDevelopmentOther,
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
|
) {
|
||||||
|
const development = await this.developmentOtherRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
if (!development) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
|
||||||
|
}
|
||||||
|
Object.assign(development, requestBody);
|
||||||
development.lastUpdateUserId = request.user.sub;
|
development.lastUpdateUserId = request.user.sub;
|
||||||
development.lastUpdateFullName = request.user.name;
|
development.lastUpdateFullName = request.user.name;
|
||||||
await this.developmentRepository.save(development, { data: request });
|
|
||||||
|
await this.developmentOtherRepository.save(development, { data: request });
|
||||||
return new HttpSuccess(development.id);
|
return new HttpSuccess(development.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2121,40 +2199,27 @@ export class DevelopmentController extends Controller {
|
||||||
@Get("tab5/{id}")
|
@Get("tab5/{id}")
|
||||||
async GetDevelopemtTab5ById(@Path() id: string) {
|
async GetDevelopemtTab5ById(@Path() id: string) {
|
||||||
const getDevelopment = await this.developmentRepository.findOne({
|
const getDevelopment = await this.developmentRepository.findOne({
|
||||||
|
relations: ["developmentOthers"],
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
relations: ["developmentAddresss"],
|
|
||||||
});
|
});
|
||||||
if (!getDevelopment) {
|
if (!getDevelopment) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||||
}
|
}
|
||||||
let _getDevelopment = {
|
let _getDevelopment = {
|
||||||
dateStart: getDevelopment.dateStart,
|
developmentOthers:
|
||||||
dateEnd: getDevelopment.dateEnd,
|
getDevelopment.developmentOthers == null
|
||||||
totalDate: getDevelopment.totalDate,
|
|
||||||
developmentAddresss:
|
|
||||||
getDevelopment.developmentAddresss == null
|
|
||||||
? null
|
? null
|
||||||
: getDevelopment.developmentAddresss.sort((a, b) =>
|
: getDevelopment.developmentOthers.sort((a, b) =>
|
||||||
(a.address == null ? "" : a.address).localeCompare(
|
(a.id == null ? "" : a.id).localeCompare(b.id == null ? "" : b.id),
|
||||||
b.address == null ? "" : b.address,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
budget: getDevelopment.budget,
|
obstacle: getDevelopment.obstacle,
|
||||||
budgetSub: getDevelopment.budgetSub,
|
suggestion: getDevelopment.suggestion,
|
||||||
accept: getDevelopment.accept,
|
isPassAllocate: getDevelopment.isPassAllocate,
|
||||||
receive: getDevelopment.receive,
|
isNoPass: getDevelopment.isNoPass,
|
||||||
approved: getDevelopment.approved,
|
isBudget: getDevelopment.isBudget,
|
||||||
budgetPay: getDevelopment.budgetPay,
|
isOutBudget: getDevelopment.isOutBudget,
|
||||||
issues: getDevelopment.issues,
|
|
||||||
chance: getDevelopment.chance,
|
|
||||||
effects: getDevelopment.effects,
|
|
||||||
riskLevel: getDevelopment.riskLevel,
|
|
||||||
riskManagement: getDevelopment.riskManagement,
|
|
||||||
expect: getDevelopment.expect,
|
|
||||||
topicAcademic: getDevelopment.topicAcademic,
|
|
||||||
addressAcademic: getDevelopment.addressAcademic,
|
|
||||||
provinceActualId: getDevelopment.provinceActualId,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return new HttpSuccess(_getDevelopment);
|
return new HttpSuccess(_getDevelopment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -833,12 +833,6 @@ export class UpdateDevelopment5 {
|
||||||
@Column()
|
@Column()
|
||||||
isOutBudget: boolean;
|
isOutBudget: boolean;
|
||||||
//end
|
//end
|
||||||
@Column()
|
|
||||||
topicAcademic: string | null;
|
|
||||||
@Column()
|
|
||||||
addressAcademic: string | null;
|
|
||||||
@Column()
|
|
||||||
provinceActualId: string | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateDevelopment7 {
|
export class UpdateDevelopment7 {
|
||||||
|
|
|
||||||
|
|
@ -44,5 +44,5 @@ export class UpdateDevelopmentOther {
|
||||||
@Column()
|
@Column()
|
||||||
addressAcademic: number | null;
|
addressAcademic: number | null;
|
||||||
@Column()
|
@Column()
|
||||||
provinceActualId: number | null;
|
provinceActualId: string | null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue