api ทุน ของ user

This commit is contained in:
Kittapath 2024-04-11 16:32:44 +07:00
parent 37bf71aca5
commit a4eed4f690
8 changed files with 496 additions and 124 deletions

View file

@ -38,9 +38,13 @@ import { PosLevel } from "../entities/PosLevel";
import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition";
import { DevelopmentHistory } from "../entities/DevelopmentHistory"; import { DevelopmentHistory } from "../entities/DevelopmentHistory";
import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; import { DevelopmentProjectType } from "../entities/DevelopmentProjectType";
import { DevelopmentProjectTechnique } from "../entities/DevelopmentProjectTechnique"; import {
import { DevelopmentEvaluation } from "../entities/DevelopmentEvaluation"; CreateDevelopmentEvaluation,
DevelopmentEvaluation,
} from "../entities/DevelopmentEvaluation";
import { DevelopmentAddress } from "../entities/DevelopmentAddress"; import { DevelopmentAddress } from "../entities/DevelopmentAddress";
import { DevelopmentProjectTechniquePlanned } from "../entities/DevelopmentProjectTechniquePlanned";
import { DevelopmentProjectTechniqueActual } from "../entities/DevelopmentProjectTechniqueActual";
@Route("api/v1/development/main") @Route("api/v1/development/main")
@Tags("Development") @Tags("Development")
@ -50,8 +54,11 @@ export class DevelopmentController extends Controller {
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);
private developmentProjectTechniqueRepository = AppDataSource.getRepository( private developmentProjectTechniquePlannedRepository = AppDataSource.getRepository(
DevelopmentProjectTechnique, DevelopmentProjectTechniquePlanned,
);
private developmentProjectTechniqueActualRepository = AppDataSource.getRepository(
DevelopmentProjectTechniqueActual,
); );
private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory);
private actualPeopleRepository = AppDataSource.getRepository(ActualPeople); private actualPeopleRepository = AppDataSource.getRepository(ActualPeople);
@ -162,7 +169,7 @@ export class DevelopmentController extends Controller {
if (!development) { if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
} }
const data = Object.assign(new PlannedGoal(), requestBody); const data = Object.assign(new PlannedGoal(), { ...requestBody, positions: [] });
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;
@ -284,7 +291,7 @@ export class DevelopmentController extends Controller {
@Put("tab2_4_add/{id}") @Put("tab2_4_add/{id}")
async CreateDevelopmenttab2_4( async CreateDevelopmenttab2_4(
@Path() id: string, @Path() id: string,
@Body() requestBody: CreateActualPeople[], @Body() requestBody: CreateActualPeople,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
const development = await this.developmentRepository.findOne({ const development = await this.developmentRepository.findOne({
@ -308,7 +315,7 @@ export class DevelopmentController extends Controller {
* *
* @summary DEV_00 - /tab2-1 # * @summary DEV_00 - /tab2-1 #
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Put("tab2_1_edit/{id}") @Put("tab2_1_edit/{id}")
async UpdateDevelopmenttab2_1( async UpdateDevelopmenttab2_1(
@ -327,9 +334,7 @@ export class DevelopmentController extends Controller {
} }
await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions); await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions);
const _requestBody: any = requestBody; Object.assign(development, { ...requestBody, positions: [] });
delete _requestBody.positions;
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.plannedGoalRepository.save(development); await this.plannedGoalRepository.save(development);
@ -371,7 +376,7 @@ export class DevelopmentController extends Controller {
* *
* @summary DEV_00 - /tab2-2 # * @summary DEV_00 - /tab2-2 #
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Put("tab2_2_edit/{id}") @Put("tab2_2_edit/{id}")
async UpdateDevelopmenttab2_2( async UpdateDevelopmenttab2_2(
@ -397,7 +402,7 @@ export class DevelopmentController extends Controller {
* *
* @summary DEV_00 - /tab2-3 # * @summary DEV_00 - /tab2-3 #
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Put("tab2_3_edit/{id}") @Put("tab2_3_edit/{id}")
async UpdateDevelopmenttab2_3( async UpdateDevelopmenttab2_3(
@ -439,7 +444,7 @@ export class DevelopmentController extends Controller {
* *
* @summary DEV_00 - /tab2-4 # * @summary DEV_00 - /tab2-4 #
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Put("tab2_4_edit/{id}") @Put("tab2_4_edit/{id}")
async UpdateDevelopmenttab2_4( async UpdateDevelopmenttab2_4(
@ -557,19 +562,28 @@ export class DevelopmentController extends Controller {
where: { id }, where: { id },
relations: { relations: {
developmentProjectTypes: true, developmentProjectTypes: true,
developmentProjectTechniques: true, developmentProjectTechniquePlanneds: true,
developmentProjectTechniqueActuals: true,
}, },
}); });
if (!development) { if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
} }
Object.assign(development, requestBody); Object.assign(development, {
...requestBody,
developmentProjectTypes: [],
developmentProjectTechniquePlanneds: [],
developmentProjectTechniqueActuals: [],
});
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); await this.developmentRepository.save(development);
await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes);
await this.developmentProjectTechniqueRepository.remove( await this.developmentProjectTechniquePlannedRepository.remove(
development.developmentProjectTechniques, development.developmentProjectTechniquePlanneds,
);
await this.developmentProjectTechniqueActualRepository.remove(
development.developmentProjectTechniqueActuals,
); );
if (requestBody.developmentProjectTypes != null) { if (requestBody.developmentProjectTypes != null) {
await Promise.all( await Promise.all(
@ -585,17 +599,31 @@ export class DevelopmentController extends Controller {
}), }),
); );
} }
if (requestBody.developmentProjectTechniques != null) { if (requestBody.developmentProjectTechniquePlanneds != null) {
await Promise.all( await Promise.all(
requestBody.developmentProjectTechniques.map(async (x) => { requestBody.developmentProjectTechniquePlanneds.map(async (x) => {
let data = new DevelopmentProjectTechnique(); let data = new DevelopmentProjectTechniquePlanned();
data.name = x; data.name = x;
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.developmentProjectTechniqueRepository.save(data); await this.developmentProjectTechniquePlannedRepository.save(data);
}),
);
}
if (requestBody.developmentProjectTechniqueActuals != null) {
await Promise.all(
requestBody.developmentProjectTechniqueActuals.map(async (x) => {
let data = new DevelopmentProjectTechniquePlanned();
data.name = x;
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.developmentProjectTechniqueActualRepository.save(data);
}), }),
); );
} }
@ -617,9 +645,6 @@ export class DevelopmentController extends Controller {
) { ) {
const development = await this.developmentRepository.findOne({ const development = await this.developmentRepository.findOne({
where: { id }, where: { id },
relations: {
developmentEvaluations: true,
},
}); });
if (!development) { if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
@ -628,18 +653,80 @@ export class DevelopmentController extends Controller {
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); await this.developmentRepository.save(development);
await this.developmentEvaluationRepository.remove(development.developmentEvaluations); return new HttpSuccess(development.id);
await Promise.all( }
requestBody.developmentEvaluations.map(async (x) => {
const data = Object.assign(new DevelopmentEvaluation(), x); /**
data.createdUserId = request.user.sub; * API /tab4-1
data.createdFullName = request.user.name; *
data.lastUpdateUserId = request.user.sub; * @summary DEV_00 - /tab4-1 #
data.lastUpdateFullName = request.user.name; *
data.developmentId = development.id; * @param {string} id Id
await this.developmentEvaluationRepository.save(data); */
}), @Put("tab4_1_add/{id}")
); async CreateDevelopmenttab4_1(
@Path() id: string,
@Body() requestBody: CreateDevelopmentEvaluation,
@Request() request: { user: Record<string, any> },
) {
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
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);
return new HttpSuccess(data.id);
}
/**
* API /tab4-1
*
* @summary DEV_00 - /tab4-1 #
*
* @param {string} id Id
*/
@Delete("tab4_1/{id}")
async DeleteDevelopmenttab4_1(@Path() id: string) {
const development = await this.developmentEvaluationRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน");
}
await this.developmentEvaluationRepository.remove(development);
return new HttpSuccess(development.id);
}
/**
* API /tab4-1
*
* @summary DEV_00 - /tab4-1 #
*
* @param {string} id Id
*/
@Put("tab4_1_edit/{id}")
async UpdateDevelopmenttab4_1(
@Path() id: string,
@Body() requestBody: CreateDevelopmentEvaluation,
@Request() request: { user: Record<string, any> },
) {
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);
return new HttpSuccess(development.id); return new HttpSuccess(development.id);
} }
@ -658,9 +745,7 @@ export class DevelopmentController extends Controller {
) { ) {
const development = await this.developmentRepository.findOne({ const development = await this.developmentRepository.findOne({
where: { id }, where: { id },
relations: { relations: { developmentAddresss: true },
developmentAddresss: true,
},
}); });
if (!development) { if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
@ -673,28 +758,31 @@ export class DevelopmentController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ");
} }
} }
Object.assign(development, requestBody);
Object.assign(development, { ...requestBody, developmentAddresss: [] });
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); await this.developmentRepository.save(development);
await this.developmentAddresssRepository.remove(development.developmentAddresss); await this.developmentAddresssRepository.remove(development.developmentAddresss);
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.find({ 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.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;
await this.developmentAddresssRepository.save(data); await this.developmentAddresssRepository.save(data);
}), }),
); );
return new HttpSuccess(development.id); return new HttpSuccess(development.id);
} }
@ -703,7 +791,6 @@ export class DevelopmentController extends Controller {
* *
* @summary DEV_00 - # * @summary DEV_00 - #
* *
* @param {string} id Id
*/ */
@Get("search") @Get("search")
async ListDevelopemt( async ListDevelopemt(
@ -752,7 +839,7 @@ export class DevelopmentController extends Controller {
* *
* @summary DEV_003 - / #3 * @summary DEV_003 - / #3
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("{id}") @Delete("{id}")
async DeleteDevelopment(@Path() id: string) { async DeleteDevelopment(@Path() id: string) {
@ -764,7 +851,8 @@ export class DevelopmentController extends Controller {
developmentActualGoals: true, developmentActualGoals: true,
developmentPlannedGoals: true, developmentPlannedGoals: true,
developmentProjectTypes: true, developmentProjectTypes: true,
developmentProjectTechniques: true, developmentProjectTechniquePlanneds: true,
developmentProjectTechniqueActuals: true,
developmentEvaluations: true, developmentEvaluations: true,
developmentAddresss: true, developmentAddresss: true,
}, },
@ -787,8 +875,11 @@ export class DevelopmentController extends Controller {
await this.actualGoalRepository.remove(development.developmentActualGoals); await this.actualGoalRepository.remove(development.developmentActualGoals);
await this.plannedGoalRepository.remove(development.developmentPlannedGoals); await this.plannedGoalRepository.remove(development.developmentPlannedGoals);
await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes);
await this.developmentProjectTechniqueRepository.remove( await this.developmentProjectTechniquePlannedRepository.remove(
development.developmentProjectTechniques, development.developmentProjectTechniquePlanneds,
);
await this.developmentProjectTechniqueActualRepository.remove(
development.developmentProjectTechniqueActuals,
); );
await this.developmentEvaluationRepository.remove(development.developmentEvaluations); await this.developmentEvaluationRepository.remove(development.developmentEvaluations);
await this.developmentAddresssRepository.remove(development.developmentAddresss); await this.developmentAddresssRepository.remove(development.developmentAddresss);
@ -915,10 +1006,38 @@ export class DevelopmentController extends Controller {
} }
let _getDevelopment: any = { let _getDevelopment: any = {
id: getDevelopment.id, id: getDevelopment.id,
actualPeoples: getDevelopment.developmentActualPeoples, actualPeoples:
plannedPeoples: getDevelopment.developmentPlannedPeoples, getDevelopment.developmentActualPeoples == null
actualGoals: getDevelopment.developmentActualGoals, ? null
plannedGoals: getDevelopment.developmentPlannedGoals, : getDevelopment.developmentActualPeoples.sort((a, b) =>
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
b.groupTarget == null ? "" : b.groupTarget,
),
),
plannedPeoples:
getDevelopment.developmentPlannedPeoples == null
? null
: getDevelopment.developmentPlannedPeoples.sort((a, b) =>
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
b.groupTarget == null ? "" : b.groupTarget,
),
),
actualGoals:
getDevelopment.developmentActualGoals == null
? null
: getDevelopment.developmentActualGoals.sort((a, b) =>
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
b.groupTarget == null ? "" : b.groupTarget,
),
),
plannedGoals:
getDevelopment.developmentPlannedGoals == null
? null
: getDevelopment.developmentPlannedGoals.sort((a, b) =>
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
b.groupTarget == null ? "" : b.groupTarget,
),
),
}; };
return new HttpSuccess(_getDevelopment); return new HttpSuccess(_getDevelopment);
} }
@ -935,28 +1054,34 @@ export class DevelopmentController extends Controller {
const getDevelopment = await this.developmentRepository.findOne({ const getDevelopment = await this.developmentRepository.findOne({
where: { id: id }, where: { id: id },
relations: [ relations: [
"developmentActualPeoples", "developmentProjectTypes",
"developmentPlannedPeoples", "developmentProjectTechniquePlanneds",
"developmentActualGoals", "developmentProjectTechniqueActuals",
"developmentPlannedGoals",
"developmentPlannedGoals.plannedGoalPositions",
"provinces",
// "provinces.developmentProvinces",
], ],
}); });
if (!getDevelopment) { if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
} }
let _getDevelopment: any = getDevelopment; let _getDevelopment: any = {
_getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; developmentProjectTypes: getDevelopment.developmentProjectTypes.map((x) => x.name).sort(),
_getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; projectModal: getDevelopment.projectModal,
_getDevelopment.actualGoals = getDevelopment.developmentActualGoals; isBackPlanned: getDevelopment.isBackPlanned,
_getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; isHoldPlanned: getDevelopment.isHoldPlanned,
// _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); projectDayBackPlanned: getDevelopment.projectDayBackPlanned,
delete _getDevelopment.developmentActualPeoples; projectDayHoldPlanned: getDevelopment.projectDayHoldPlanned,
delete _getDevelopment.developmentPlannedPeoples; projectNigthHoldPlanned: getDevelopment.projectNigthHoldPlanned,
delete _getDevelopment.developmentActualGoals; developmentProjectTechniquePlanneds: getDevelopment.developmentProjectTechniquePlanneds
delete _getDevelopment.developmentPlannedGoals; .map((x) => x.name)
.sort(),
isBackActual: getDevelopment.isBackActual,
isHoldActual: getDevelopment.isHoldActual,
projectDayBackActual: getDevelopment.projectDayBackActual,
projectDayHoldActual: getDevelopment.projectDayHoldActual,
projectNigthHoldActual: getDevelopment.projectNigthHoldActual,
developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals
.map((x) => x.name)
.sort(),
};
return new HttpSuccess(_getDevelopment); return new HttpSuccess(_getDevelopment);
} }
@ -971,29 +1096,28 @@ export class DevelopmentController extends Controller {
async GetDevelopemtTab4ById(@Path() id: string) { async GetDevelopemtTab4ById(@Path() id: string) {
const getDevelopment = await this.developmentRepository.findOne({ const getDevelopment = await this.developmentRepository.findOne({
where: { id: id }, where: { id: id },
relations: [ relations: ["developmentEvaluations"],
"developmentActualPeoples",
"developmentPlannedPeoples",
"developmentActualGoals",
"developmentPlannedGoals",
"developmentPlannedGoals.plannedGoalPositions",
"provinces",
// "provinces.developmentProvinces",
],
}); });
if (!getDevelopment) { if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
} }
let _getDevelopment: any = getDevelopment; let _getDevelopment = {
_getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; developmentEvaluations:
_getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; getDevelopment.developmentEvaluations == null
_getDevelopment.actualGoals = getDevelopment.developmentActualGoals; ? null
_getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; : getDevelopment.developmentEvaluations.sort((a, b) =>
// _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); (a.indicators == null ? "" : a.indicators).localeCompare(
delete _getDevelopment.developmentActualPeoples; b.indicators == null ? "" : b.indicators,
delete _getDevelopment.developmentPlannedPeoples; ),
delete _getDevelopment.developmentActualGoals; ),
delete _getDevelopment.developmentPlannedGoals; project: getDevelopment.project,
isPassAllocate: getDevelopment.isPassAllocate,
isPassNoAllocate: getDevelopment.isPassNoAllocate,
isNoPass: getDevelopment.isNoPass,
isBudget: getDevelopment.isBudget,
isOutBudget: getDevelopment.isOutBudget,
};
return new HttpSuccess(_getDevelopment); return new HttpSuccess(_getDevelopment);
} }
@ -1008,29 +1132,39 @@ export class DevelopmentController extends Controller {
async GetDevelopemtTab5ById(@Path() id: string) { async GetDevelopemtTab5ById(@Path() id: string) {
const getDevelopment = await this.developmentRepository.findOne({ const getDevelopment = await this.developmentRepository.findOne({
where: { id: id }, where: { id: id },
relations: [ relations: ["developmentAddresss"],
"developmentActualPeoples",
"developmentPlannedPeoples",
"developmentActualGoals",
"developmentPlannedGoals",
"developmentPlannedGoals.plannedGoalPositions",
"provinces",
// "provinces.developmentProvinces",
],
}); });
if (!getDevelopment) { if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
} }
let _getDevelopment: any = getDevelopment; let _getDevelopment = {
_getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; dateStart: getDevelopment.dateStart,
_getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; dateEnd: getDevelopment.dateEnd,
_getDevelopment.actualGoals = getDevelopment.developmentActualGoals; totalDate: getDevelopment.totalDate,
_getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; developmentAddresss:
// _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); getDevelopment.developmentAddresss == null
delete _getDevelopment.developmentActualPeoples; ? null
delete _getDevelopment.developmentPlannedPeoples; : getDevelopment.developmentAddresss.sort((a, b) =>
delete _getDevelopment.developmentActualGoals; (a.address == null ? "" : a.address).localeCompare(
delete _getDevelopment.developmentPlannedGoals; b.address == null ? "" : b.address,
),
),
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,
};
return new HttpSuccess(_getDevelopment); return new HttpSuccess(_getDevelopment);
} }

View file

@ -21,6 +21,7 @@ import {
CreateDevelopmentScholarship, CreateDevelopmentScholarship,
DevelopmentScholarship, DevelopmentScholarship,
UpdateDevelopmentScholarship, UpdateDevelopmentScholarship,
UpdateDevelopmentScholarshipUser,
} from "../entities/DevelopmentScholarship"; } from "../entities/DevelopmentScholarship";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
@ -314,10 +315,91 @@ export class DevelopmentScholarshipController extends Controller {
totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null, totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null,
status: getDevelopment.status ? getDevelopment.status : null, status: getDevelopment.status ? getDevelopment.status : null,
profileId: getDevelopment.profileId ? getDevelopment.profileId : null, profileId: getDevelopment.profileId ? getDevelopment.profileId : null,
planType: getDevelopment.planType ? getDevelopment.planType : null,
isNoUseBudget: getDevelopment.isNoUseBudget ? getDevelopment.isNoUseBudget : null,
}; };
return new HttpSuccess(formattedData); return new HttpSuccess(formattedData);
} }
/**
* API user
*
* @summary DEV_0 - user #
*
* @param {string} profileId profileId
*/
@Get("user/{profileId}")
async GetDevelopemtScholarshipUserById(@Path() profileId: string) {
const getDevelopment = await this.developmentScholarshipRepository.find({
where: { profileId: profileId },
});
const formattedData = getDevelopment.map((item) => ({
id: item.id,
scholarshipYear: item.scholarshipYear,
scholarshipType: item.scholarshipType,
fundType: item.fundType,
}));
return new HttpSuccess(formattedData);
}
/**
* API user
*
* @summary DEV_0 - user #
*
* @param {string} id id
*/
@Get("user/detail/{id}")
async GetDevelopemtScholarshipUserDetailById(@Path() id: string) {
const getDevelopment = await this.developmentScholarshipRepository.findOne({
where: { id: id },
select: [
"id",
"scholarshipYear",
"scholarshipType",
"fundType",
"governmentDate",
"isGraduated",
"graduatedDate",
"isNoGraduated",
"graduatedReason",
],
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
return new HttpSuccess(getDevelopment);
}
/**
* API user
*
* @summary DEV_015 - user #15
*
* @param {string} id
*/
@Put("user/detail/{id}")
async UpdateDevelopemtScholarshipUserById(
@Path() id: string,
@Body() requestBody: UpdateDevelopmentScholarshipUser,
@Request() request: { user: Record<string, any> },
) {
const getDevelopment = await this.developmentScholarshipRepository.findOne({
where: { id: id },
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
Object.assign(getDevelopment, requestBody);
getDevelopment.lastUpdateUserId = request.user.sub;
getDevelopment.lastUpdateFullName = request.user.name;
await this.developmentScholarshipRepository.save(getDevelopment);
return new HttpSuccess(getDevelopment.id);
}
/** /**
* API * API
* *
@ -340,6 +422,8 @@ export class DevelopmentScholarshipController extends Controller {
} }
const _status = status.trim().toUpperCase(); const _status = status.trim().toUpperCase();
getDevelopment.status = _status; getDevelopment.status = _status;
getDevelopment.lastUpdateUserId = request.user.sub;
getDevelopment.lastUpdateFullName = request.user.name;
if (_status == "GRADUATE") { if (_status == "GRADUATE") {
if (getDevelopment.scholarshipType != null) { if (getDevelopment.scholarshipType != null) {
switch (getDevelopment.scholarshipType.trim().toUpperCase()) { switch (getDevelopment.scholarshipType.trim().toUpperCase()) {

View file

@ -7,9 +7,10 @@ import { ActualGoal, CreateActualGoal } from "./ActualGoal";
import { CreatePlannedGoal, PlannedGoal } from "./PlannedGoal"; import { CreatePlannedGoal, PlannedGoal } from "./PlannedGoal";
import { DevelopmentHistory } from "./DevelopmentHistory"; import { DevelopmentHistory } from "./DevelopmentHistory";
import { DevelopmentProjectType } from "./DevelopmentProjectType"; import { DevelopmentProjectType } from "./DevelopmentProjectType";
import { DevelopmentProjectTechnique } from "./DevelopmentProjectTechnique"; import { DevelopmentProjectTechniquePlanned } from "./DevelopmentProjectTechniquePlanned";
import { CreateDevelopmentEvaluation, DevelopmentEvaluation } from "./DevelopmentEvaluation"; import { CreateDevelopmentEvaluation, DevelopmentEvaluation } from "./DevelopmentEvaluation";
import { CreateDevelopmentAddress, DevelopmentAddress } from "./DevelopmentAddress"; import { CreateDevelopmentAddress, DevelopmentAddress } from "./DevelopmentAddress";
import { DevelopmentProjectTechniqueActual } from "./DevelopmentProjectTechniqueActual";
@Entity("development") @Entity("development")
export class Development extends EntityBase { export class Development extends EntityBase {
@ -141,11 +142,18 @@ export class Development extends EntityBase {
projectNigthHoldActual: number; projectNigthHoldActual: number;
@OneToMany( @OneToMany(
() => DevelopmentProjectTechnique, () => DevelopmentProjectTechniquePlanned,
(developmentProjectTechnique: DevelopmentProjectTechnique) => (developmentProjectTechniquePlanned: DevelopmentProjectTechniquePlanned) =>
developmentProjectTechnique.development, developmentProjectTechniquePlanned.development,
) )
developmentProjectTechniques: DevelopmentProjectTechnique[]; developmentProjectTechniquePlanneds: DevelopmentProjectTechniquePlanned[];
@OneToMany(
() => DevelopmentProjectTechniqueActual,
(developmentProjectTechniqueActual: DevelopmentProjectTechniqueActual) =>
developmentProjectTechniqueActual.development,
)
developmentProjectTechniqueActuals: DevelopmentProjectTechniqueActual[];
@Column({ @Column({
nullable: true, nullable: true,
@ -400,6 +408,8 @@ export class UpdateDevelopment3 {
@Column() @Column()
developmentProjectTypes?: string[]; developmentProjectTypes?: string[];
@Column() @Column()
projectModal?: number | null;
@Column()
isBackPlanned?: boolean | null; isBackPlanned?: boolean | null;
@Column() @Column()
isHoldPlanned?: boolean | null; isHoldPlanned?: boolean | null;
@ -410,6 +420,8 @@ export class UpdateDevelopment3 {
@Column() @Column()
projectNigthHoldPlanned?: number | null; projectNigthHoldPlanned?: number | null;
@Column() @Column()
developmentProjectTechniquePlanneds?: string[];
@Column()
isBackActual?: boolean | null; isBackActual?: boolean | null;
@Column() @Column()
isHoldActual?: boolean | null; isHoldActual?: boolean | null;
@ -420,13 +432,11 @@ export class UpdateDevelopment3 {
@Column() @Column()
projectNigthHoldActual?: number | null; projectNigthHoldActual?: number | null;
@Column() @Column()
developmentProjectTechniques?: string[]; developmentProjectTechniqueActuals?: string[];
@Column()
projectModal?: number | null;
} }
export class UpdateDevelopment4 { export class UpdateDevelopment4 {
@Column() // @Column()
developmentEvaluations: CreateDevelopmentEvaluation[]; // developmentEvaluations: CreateDevelopmentEvaluation[];
@Column() @Column()
project: string | null; project: string | null;
@Column() @Column()
@ -479,8 +489,4 @@ export class UpdateDevelopment5 {
addressAcademic: string | null; addressAcademic: string | null;
@Column() @Column()
provinceActualId: string | null; provinceActualId: string | null;
@Column()
dateStudyStart: Date | null;
@Column()
dateStudyEnd: Date | null;
} }

View file

@ -2,8 +2,8 @@ import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { Development } from "./Development"; import { Development } from "./Development";
@Entity("developmentProjectTechnique") @Entity("developmentProjectTechniqueActual")
export class DevelopmentProjectTechnique extends EntityBase { export class DevelopmentProjectTechniqueActual extends EntityBase {
@Column({ @Column({
// TRAINING = การอบรม // TRAINING = การอบรม
// MEETING = การประชุม // MEETING = การประชุม
@ -28,12 +28,12 @@ export class DevelopmentProjectTechnique extends EntityBase {
@ManyToOne( @ManyToOne(
() => Development, () => Development,
(development: Development) => development.developmentProjectTechniques, (development: Development) => development.developmentProjectTechniqueActuals,
) )
@JoinColumn({ name: "developmentId" }) @JoinColumn({ name: "developmentId" })
development: Development; development: Development;
} }
export class CreateDevelopmentProjectTechnique { export class CreateDevelopmentProjectTechniqueActual {
@Column() @Column()
name: number; name: number;
} }

View file

@ -0,0 +1,39 @@
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { Development } from "./Development";
@Entity("developmentProjectTechniquePlanned")
export class DevelopmentProjectTechniquePlanned extends EntityBase {
@Column({
// TRAINING = การอบรม
// MEETING = การประชุม
// SEMINAR = การสัมมนา
// STUDY_TOUR = การศึกษาดูงาน
// ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ
// WORKSHOP = การสัมมนาเชิงปฏิบัติการ
// SPECIAL_LECTURE = การบรรยายพิเศษ
// STUDY_TRAINING = การฝึกศึกษา
nullable: true,
comment: "เทคนิควิธีการที่ใช้ในการพัฒนา",
default: null,
})
name: string;
@Column({
nullable: true,
comment: "โครงการ/หลักสูตรการฝึกอบรม",
default: null,
})
developmentId: string;
@ManyToOne(
() => Development,
(development: Development) => development.developmentProjectTechniquePlanneds,
)
@JoinColumn({ name: "developmentId" })
development: Development;
}
export class CreateDevelopmentProjectTechniquePlanned {
@Column()
name: number;
}

View file

@ -429,6 +429,57 @@ export class DevelopmentScholarship extends EntityBase {
default: null, default: null,
}) })
totalPeriod: string; totalPeriod: string;
@Column({
// ในแผนฯ (INPLAN)
// นอกแผนฯ (OUTPLAN)
nullable: true,
comment: "ในแผนฯ",
length: 40,
default: null,
})
planType: string;
@Column({
comment: "ไม่ใช้งบประมาณ",
default: false,
})
isNoUseBudget: boolean;
@Column({
nullable: true,
type: "datetime",
comment: "กลับเข้ารับราชการตั้งแต่",
default: null,
})
governmentDate: Date;
@Column({
comment: "สำเร็จการศึกษาตามที่หลักสูตรกำหนด",
default: false,
})
isGraduated: boolean;
@Column({
nullable: true,
type: "datetime",
comment: "ตั้งแต่",
default: null,
})
graduatedDate: Date;
@Column({
comment: "เสร็จสิ้นการศึกษาตามที่หลักสูตรกำหนดแล้วแต่ยังไม่สำเร็จการศึกษา",
default: false,
})
isNoGraduated: boolean;
@Column({
nullable: true,
comment: "เนื่องจาก",
default: null,
})
graduatedReason: string;
} }
export class CreateDevelopmentScholarship { export class CreateDevelopmentScholarship {
profileId: string | null; profileId: string | null;
@ -481,6 +532,8 @@ export class CreateDevelopmentScholarship {
studyAbroadStartDate: Date | null; studyAbroadStartDate: Date | null;
studyAbroadEndDate: Date | null; studyAbroadEndDate: Date | null;
totalPeriod: string | null; totalPeriod: string | null;
planType: string | null;
isNoUseBudget: boolean | null;
} }
export class UpdateDevelopmentScholarship { export class UpdateDevelopmentScholarship {
@ -534,4 +587,14 @@ export class UpdateDevelopmentScholarship {
studyAbroadStartDate: Date | null; studyAbroadStartDate: Date | null;
studyAbroadEndDate: Date | null; studyAbroadEndDate: Date | null;
totalPeriod: string | null; totalPeriod: string | null;
planType: string | null;
isNoUseBudget: boolean | null;
}
export class UpdateDevelopmentScholarshipUser {
governmentDate: Date | null;
isGraduated: boolean | null;
graduatedDate: Date | null;
isNoGraduated: boolean | null;
graduatedReason: string | null;
} }

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableStarty11712815316667 implements MigrationInterface {
name = 'AddTableStarty11712815316667'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`developmentProjectTechniquePlanned\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`developmentProjectTechniqueActual\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`developmentProjectTechniquePlanned\` ADD CONSTRAINT \`FK_7166cc94112552ea072a2cc6134\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`developmentProjectTechniqueActual\` ADD CONSTRAINT \`FK_aaaee1c5fb44bef093ed78a0c32\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`developmentProjectTechniqueActual\` DROP FOREIGN KEY \`FK_aaaee1c5fb44bef093ed78a0c32\``);
await queryRunner.query(`ALTER TABLE \`developmentProjectTechniquePlanned\` DROP FOREIGN KEY \`FK_7166cc94112552ea072a2cc6134\``);
await queryRunner.query(`DROP TABLE \`developmentProjectTechniqueActual\``);
await queryRunner.query(`DROP TABLE \`developmentProjectTechniquePlanned\``);
}
}

View file

@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableDevelopmentScholarshipAddPlanType1712824449740 implements MigrationInterface {
name = 'UpdateTableDevelopmentScholarshipAddPlanType1712824449740'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`planType\` varchar(40) NULL COMMENT 'ในแผนฯ'`);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`isNoUseBudget\` tinyint NOT NULL COMMENT 'ไม่ใช้งบประมาณ' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`governmentDate\` datetime NULL COMMENT 'กลับเข้ารับราชการตั้งแต่'`);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`isGraduated\` tinyint NOT NULL COMMENT 'สำเร็จการศึกษาตามที่หลักสูตรกำหนด' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`graduatedDate\` datetime NULL COMMENT 'ตั้งแต่'`);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`isNoGraduated\` tinyint NOT NULL COMMENT 'เสร็จสิ้นการศึกษาตามที่หลักสูตรกำหนดแล้วแต่ยังไม่สำเร็จการศึกษา' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`graduatedReason\` varchar(255) NULL COMMENT 'เนื่องจาก'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`graduatedReason\``);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`isNoGraduated\``);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`graduatedDate\``);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`isGraduated\``);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`governmentDate\``);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`isNoUseBudget\``);
await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`planType\``);
}
}