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

@ -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()) {