api ทุน ของ user
This commit is contained in:
parent
37bf71aca5
commit
a4eed4f690
8 changed files with 496 additions and 124 deletions
|
|
@ -21,6 +21,7 @@ import {
|
|||
CreateDevelopmentScholarship,
|
||||
DevelopmentScholarship,
|
||||
UpdateDevelopmentScholarship,
|
||||
UpdateDevelopmentScholarshipUser,
|
||||
} from "../entities/DevelopmentScholarship";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
|
|
@ -314,10 +315,91 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null,
|
||||
status: getDevelopment.status ? getDevelopment.status : null,
|
||||
profileId: getDevelopment.profileId ? getDevelopment.profileId : null,
|
||||
planType: getDevelopment.planType ? getDevelopment.planType : null,
|
||||
isNoUseBudget: getDevelopment.isNoUseBudget ? getDevelopment.isNoUseBudget : null,
|
||||
};
|
||||
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 เปลี่ยนสถานะ
|
||||
*
|
||||
|
|
@ -340,6 +422,8 @@ export class DevelopmentScholarshipController extends Controller {
|
|||
}
|
||||
const _status = status.trim().toUpperCase();
|
||||
getDevelopment.status = _status;
|
||||
getDevelopment.lastUpdateUserId = request.user.sub;
|
||||
getDevelopment.lastUpdateFullName = request.user.name;
|
||||
if (_status == "GRADUATE") {
|
||||
if (getDevelopment.scholarshipType != null) {
|
||||
switch (getDevelopment.scholarshipType.trim().toUpperCase()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue