Tab8 API
This commit is contained in:
parent
6fc0c04a9b
commit
b9cc922edc
2 changed files with 47 additions and 43 deletions
|
|
@ -61,7 +61,7 @@ import { FileInterceptor } from "@nestjs/platform-express";
|
||||||
import * as xlsx from "xlsx";
|
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 } from "../entities/DevelopmentRisk";
|
import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk";
|
||||||
|
|
||||||
@Route("api/v1/development/main")
|
@Route("api/v1/development/main")
|
||||||
@Tags("Development")
|
@Tags("Development")
|
||||||
|
|
@ -1206,27 +1206,27 @@ export class DevelopmentController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//move from tab5
|
//move from tab5
|
||||||
await this.developmentAddresssRepository.remove(development.developmentAddresss, {
|
await this.developmentAddresssRepository.remove(development.developmentAddresss, {
|
||||||
data: request,
|
data: request,
|
||||||
});
|
});
|
||||||
const before = structuredClone(development);
|
const before = structuredClone(development);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
requestBody.developmentAddresss.map(async (x) => {
|
requestBody.developmentAddresss.map(async (x) => {
|
||||||
const data = Object.assign(new DevelopmentAddress(), x);
|
const data = Object.assign(new DevelopmentAddress(), x);
|
||||||
const chkProvince = await this.provinceRepository.findOne({
|
const chkProvince = await this.provinceRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: x.provinceId,
|
id: x.provinceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (chkProvince == null) return;
|
if (chkProvince == null) return;
|
||||||
data.developmentId = development.id;
|
data.developmentId = development.id;
|
||||||
data.createdUserId = request.user.sub;
|
data.createdUserId = request.user.sub;
|
||||||
data.createdFullName = request.user.name;
|
data.createdFullName = request.user.name;
|
||||||
data.lastUpdateUserId = request.user.sub;
|
data.lastUpdateUserId = request.user.sub;
|
||||||
data.lastUpdateFullName = request.user.name;
|
data.lastUpdateFullName = request.user.name;
|
||||||
await this.developmentAddresssRepository.save(data, { data: request });
|
await this.developmentAddresssRepository.save(data, { data: request });
|
||||||
setLogDataDiff(request, { before, after: development });
|
setLogDataDiff(request, { before, after: development });
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
Object.assign(development, { ...requestBody, developmentAddresss: [] });
|
Object.assign(development, { ...requestBody, developmentAddresss: [] });
|
||||||
//End
|
//End
|
||||||
|
|
@ -1387,7 +1387,7 @@ export class DevelopmentController extends Controller {
|
||||||
return new HttpSuccess(development.id);
|
return new HttpSuccess(development.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7
|
||||||
*
|
*
|
||||||
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7 #
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7 #
|
||||||
|
|
@ -1438,8 +1438,7 @@ export class DevelopmentController extends Controller {
|
||||||
return new HttpSuccess(_getDevelopment);
|
return new HttpSuccess(_getDevelopment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
|
||||||
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab8
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab8
|
||||||
*
|
*
|
||||||
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab8 #
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab8 #
|
||||||
|
|
@ -1460,9 +1459,7 @@ export class DevelopmentController extends Controller {
|
||||||
getDevelopment.developmentRisks == null
|
getDevelopment.developmentRisks == null
|
||||||
? null
|
? null
|
||||||
: getDevelopment.developmentRisks.sort((a, b) =>
|
: getDevelopment.developmentRisks.sort((a, b) =>
|
||||||
(a.id == null ? "" : a.id).localeCompare(
|
(a.id == null ? "" : a.id).localeCompare(b.id == null ? "" : b.id),
|
||||||
b.id == null ? "" : b.id,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
expect: getDevelopment.expect,
|
expect: getDevelopment.expect,
|
||||||
};
|
};
|
||||||
|
|
@ -1470,7 +1467,7 @@ export class DevelopmentController extends Controller {
|
||||||
return new HttpSuccess(_getDevelopment);
|
return new HttpSuccess(_getDevelopment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8
|
||||||
*
|
*
|
||||||
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 #
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 #
|
||||||
|
|
@ -1506,7 +1503,7 @@ export class DevelopmentController extends Controller {
|
||||||
@Put("tab8_1_add/{id}")
|
@Put("tab8_1_add/{id}")
|
||||||
async CreateDevelopmenttab8_1(
|
async CreateDevelopmenttab8_1(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() requestBody: UpdateDevelopment8_1,
|
@Body() requestBody: UpdateDevelopmentRisk,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
const development = await this.developmentRepository.findOne({
|
const development = await this.developmentRepository.findOne({
|
||||||
|
|
@ -1516,13 +1513,13 @@ export class DevelopmentController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||||
}
|
}
|
||||||
const before = structuredClone(development);
|
const before = structuredClone(development);
|
||||||
const data = Object.assign(new DevelopmentEvaluation(), requestBody);
|
const data = Object.assign(new DevelopmentRisk(), requestBody);
|
||||||
data.createdUserId = request.user.sub;
|
data.createdUserId = request.user.sub;
|
||||||
data.createdFullName = request.user.name;
|
data.createdFullName = request.user.name;
|
||||||
data.lastUpdateUserId = request.user.sub;
|
data.lastUpdateUserId = request.user.sub;
|
||||||
data.lastUpdateFullName = request.user.name;
|
data.lastUpdateFullName = request.user.name;
|
||||||
data.developmentId = development.id;
|
data.developmentId = development.id;
|
||||||
await this.developmentEvaluationRepository.save(data, { data: request });
|
await this.developmentRiskRepository.save(data, { data: request });
|
||||||
setLogDataDiff(request, { before, after: development });
|
setLogDataDiff(request, { before, after: development });
|
||||||
return new HttpSuccess(data.id);
|
return new HttpSuccess(data.id);
|
||||||
}
|
}
|
||||||
|
|
@ -1536,13 +1533,13 @@ export class DevelopmentController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Delete("tab8_1/{id}")
|
@Delete("tab8_1/{id}")
|
||||||
async DeleteDevelopmenttab8_1(@Path() id: string, @Request() request: RequestWithUser) {
|
async DeleteDevelopmenttab8_1(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
const development = await this.developmentEvaluationRepository.findOne({
|
const development = await this.developmentRiskRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
if (!development) {
|
if (!development) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
|
||||||
}
|
}
|
||||||
await this.developmentEvaluationRepository.remove(development, { data: request });
|
await this.developmentRiskRepository.remove(development, { data: request });
|
||||||
return new HttpSuccess(development.id);
|
return new HttpSuccess(development.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1556,20 +1553,20 @@ export class DevelopmentController extends Controller {
|
||||||
@Put("tab8_1_edit/{id}")
|
@Put("tab8_1_edit/{id}")
|
||||||
async UpdateDevelopmenttab8_1(
|
async UpdateDevelopmenttab8_1(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() requestBody: UpdateDevelopment8_1,
|
@Body() requestBody: UpdateDevelopmentRisk,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
const development = await this.developmentEvaluationRepository.findOne({
|
const development = await this.developmentRiskRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
if (!development) {
|
if (!development) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
|
||||||
}
|
}
|
||||||
Object.assign(development, requestBody);
|
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.developmentEvaluationRepository.save(development, { data: request });
|
await this.developmentRiskRepository.save(development, { data: request });
|
||||||
return new HttpSuccess(development.id);
|
return new HttpSuccess(development.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,16 @@ export class DevelopmentRisk extends EntityBase {
|
||||||
@JoinColumn({ name: "developmentId" })
|
@JoinColumn({ name: "developmentId" })
|
||||||
development: Development;
|
development: Development;
|
||||||
}
|
}
|
||||||
export class CreateDevelopmentRisk {
|
|
||||||
|
export class UpdateDevelopmentRisk {
|
||||||
@Column()
|
@Column()
|
||||||
address: string | null;
|
issues: string | null;
|
||||||
@Column()
|
@Column()
|
||||||
provinceId: string;
|
chance: number | null;
|
||||||
|
@Column()
|
||||||
|
effects: number | null;
|
||||||
|
@Column()
|
||||||
|
riskLevel: string | null;
|
||||||
|
@Column()
|
||||||
|
riskManagement: string | null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue