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 { RequestWithUser } from "../middlewares/user";
|
||||
import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk";
|
||||
import { DevelopmentOther, UpdateDevelopmentOther } from "../entities/DevelopmentOther";
|
||||
|
||||
@Route("api/v1/development/main")
|
||||
@Tags("Development")
|
||||
|
|
@ -69,6 +70,7 @@ import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentR
|
|||
export class DevelopmentController extends Controller {
|
||||
private developmentRepository = AppDataSource.getRepository(Development);
|
||||
private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk);
|
||||
private developmentOtherRepository = AppDataSource.getRepository(DevelopmentOther);
|
||||
private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress);
|
||||
private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation);
|
||||
private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType);
|
||||
|
|
@ -1332,7 +1334,32 @@ export class DevelopmentController extends Controller {
|
|||
if (!development) {
|
||||
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({
|
||||
where: { id: requestBody.provinceActualId },
|
||||
});
|
||||
|
|
@ -1340,10 +1367,61 @@ export class DevelopmentController extends Controller {
|
|||
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.lastUpdateFullName = request.user.name;
|
||||
await this.developmentRepository.save(development, { data: request });
|
||||
|
||||
await this.developmentOtherRepository.save(development, { data: request });
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
|
||||
|
|
@ -2121,40 +2199,27 @@ export class DevelopmentController extends Controller {
|
|||
@Get("tab5/{id}")
|
||||
async GetDevelopemtTab5ById(@Path() id: string) {
|
||||
const getDevelopment = await this.developmentRepository.findOne({
|
||||
relations: ["developmentOthers"],
|
||||
where: { id: id },
|
||||
relations: ["developmentAddresss"],
|
||||
});
|
||||
if (!getDevelopment) {
|
||||
if (!getDevelopment) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||
}
|
||||
let _getDevelopment = {
|
||||
dateStart: getDevelopment.dateStart,
|
||||
dateEnd: getDevelopment.dateEnd,
|
||||
totalDate: getDevelopment.totalDate,
|
||||
developmentAddresss:
|
||||
getDevelopment.developmentAddresss == null
|
||||
let _getDevelopment = {
|
||||
developmentOthers:
|
||||
getDevelopment.developmentOthers == null
|
||||
? null
|
||||
: getDevelopment.developmentAddresss.sort((a, b) =>
|
||||
(a.address == null ? "" : a.address).localeCompare(
|
||||
b.address == null ? "" : b.address,
|
||||
),
|
||||
: getDevelopment.developmentOthers.sort((a, b) =>
|
||||
(a.id == null ? "" : a.id).localeCompare(b.id == null ? "" : b.id),
|
||||
),
|
||||
budget: getDevelopment.budget,
|
||||
budgetSub: getDevelopment.budgetSub,
|
||||
accept: getDevelopment.accept,
|
||||
receive: getDevelopment.receive,
|
||||
approved: getDevelopment.approved,
|
||||
budgetPay: getDevelopment.budgetPay,
|
||||
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,
|
||||
obstacle: getDevelopment.obstacle,
|
||||
suggestion: getDevelopment.suggestion,
|
||||
isPassAllocate: getDevelopment.isPassAllocate,
|
||||
isNoPass: getDevelopment.isNoPass,
|
||||
isBudget: getDevelopment.isBudget,
|
||||
isOutBudget: getDevelopment.isOutBudget,
|
||||
};
|
||||
|
||||
return new HttpSuccess(_getDevelopment);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -833,12 +833,6 @@ export class UpdateDevelopment5 {
|
|||
@Column()
|
||||
isOutBudget: boolean;
|
||||
//end
|
||||
@Column()
|
||||
topicAcademic: string | null;
|
||||
@Column()
|
||||
addressAcademic: string | null;
|
||||
@Column()
|
||||
provinceActualId: string | null;
|
||||
}
|
||||
|
||||
export class UpdateDevelopment7 {
|
||||
|
|
|
|||
|
|
@ -44,5 +44,5 @@ export class UpdateDevelopmentOther {
|
|||
@Column()
|
||||
addressAcademic: number | null;
|
||||
@Column()
|
||||
provinceActualId: number | null;
|
||||
provinceActualId: string | null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue