add path admin(detail scholarship)

This commit is contained in:
AdisakKanthawilang 2024-08-30 14:17:29 +07:00
parent 3abd92e15f
commit d13da7269c

View file

@ -52,11 +52,6 @@ export class DevelopmentScholarshipController extends Controller {
) {
await new permission().PermissionCreate(request, "SYS_DEV_SCHOLARSHIP");
if (requestBody.posTypeId != null) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Position Type.",
// });
const checkId = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
@ -65,11 +60,6 @@ export class DevelopmentScholarshipController extends Controller {
}
}
if (requestBody.posLevelId != null) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Position Level.",
// });
const checkId = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
@ -83,11 +73,6 @@ export class DevelopmentScholarshipController extends Controller {
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store Development Scholarship.",
// });
await this.developmentScholarshipRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
return new HttpSuccess(development.id);
@ -106,11 +91,6 @@ export class DevelopmentScholarshipController extends Controller {
@Body() requestBody: UpdateDevelopmentScholarship,
@Request() request: RequestWithUser,
) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development Scholarship.",
// });
await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP");
const development = await this.developmentScholarshipRepository.findOne({
where: { id: id },
@ -119,11 +99,6 @@ export class DevelopmentScholarshipController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
if (requestBody.posTypeId != null) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Position Type.",
// });
const checkId = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
@ -132,11 +107,6 @@ export class DevelopmentScholarshipController extends Controller {
}
}
if (requestBody.posLevelId != null) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Position Level.",
// });
const checkId = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
@ -148,11 +118,6 @@ export class DevelopmentScholarshipController extends Controller {
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentScholarship.",
// });
await this.developmentScholarshipRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
return new HttpSuccess(development.id);
@ -167,11 +132,6 @@ export class DevelopmentScholarshipController extends Controller {
*/
@Delete("{id}")
async DeleteDevelopmentScholarship(@Path() id: string, @Request() request: RequestWithUser) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development Scholarship",
// });
await new permission().PermissionDelete(request, "SYS_DEV_SCHOLARSHIP");
const development = await this.developmentScholarshipRepository.findOne({
where: { id: id },
@ -179,11 +139,7 @@ export class DevelopmentScholarshipController extends Controller {
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove Development Scholarship By ID.",
// });
await this.developmentScholarshipRepository.remove(development, { data: request });
return new HttpSuccess();
}
@ -295,6 +251,121 @@ export class DevelopmentScholarshipController extends Controller {
*/
@Get("{id}")
async GetDevelopemtScholarshipById(@Request() request: RequestWithUser, @Path() id: string) {
// await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP");//USER
const getDevelopment = await this.developmentScholarshipRepository.findOne({
relations: ["posLevel", "posType", "posLevelguarantor", "posTypeguarantor"],
where: { id: id },
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
const formattedData = {
rootId: getDevelopment.rootId ? getDevelopment.rootId : null,
root: getDevelopment.root ? getDevelopment.root : null,
org: getDevelopment.org ? getDevelopment.org : null,
orgRootShortName: getDevelopment.orgRootShortName ? getDevelopment.orgRootShortName : null,
orgRevisionId: getDevelopment.orgRevisionId ? getDevelopment.orgRevisionId : null,
rank: getDevelopment.rank ? getDevelopment.rank : null,
prefix: getDevelopment.prefix ? getDevelopment.prefix : null,
firstName: getDevelopment.firstName ? getDevelopment.firstName : null,
lastName: getDevelopment.lastName ? getDevelopment.lastName : null,
citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null,
position: getDevelopment.position ? getDevelopment.position : null,
posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null,
posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null,
posLevelName: getDevelopment.posLevel?.posLevelName
? getDevelopment.posLevel?.posLevelName
: null,
posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null,
posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null,
guarantorRootId: getDevelopment.guarantorRootId ? getDevelopment.guarantorRootId : null,
guarantorRoot: getDevelopment.guarantorRoot ? getDevelopment.guarantorRoot : null,
guarantorOrg: getDevelopment.guarantorOrg ? getDevelopment.guarantorOrg : null,
guarantorOrgRootShortName: getDevelopment.guarantorOrgRootShortName
? getDevelopment.guarantorOrgRootShortName
: null,
guarantorOrgRevisionId: getDevelopment.guarantorOrgRevisionId
? getDevelopment.guarantorOrgRevisionId
: null,
guarantorRank: getDevelopment.guarantorRank ? getDevelopment.guarantorRank : null,
guarantorPrefix: getDevelopment.guarantorPrefix ? getDevelopment.guarantorPrefix : null,
guarantorFirstName: getDevelopment.guarantorFirstName
? getDevelopment.guarantorFirstName
: null,
guarantorLastName: getDevelopment.guarantorLastName ? getDevelopment.guarantorLastName : null,
guarantorCitizenId: getDevelopment.guarantorCitizenId
? getDevelopment.guarantorCitizenId
: null,
guarantorPosition: getDevelopment.guarantorPosition ? getDevelopment.guarantorPosition : null,
guarantorPosExecutive: getDevelopment.guarantorPosExecutive
? getDevelopment.guarantorPosExecutive
: null,
posLevelguarantorId: getDevelopment.posLevelguarantorId
? getDevelopment.posLevelguarantorId
: null,
posLevelguarantorName: getDevelopment.posLevelguarantor?.posLevelName
? getDevelopment.posLevelguarantor?.posLevelName
: null,
posTypeguarantorId: getDevelopment.posTypeguarantorId
? getDevelopment.posTypeguarantorId
: null,
posTypeguarantorName: getDevelopment.posTypeguarantor?.posTypeName
? getDevelopment.posTypeguarantor?.posTypeName
: null,
scholarshipYear: getDevelopment.scholarshipYear ? getDevelopment.scholarshipYear : null,
budgetSource: getDevelopment.budgetSource ? getDevelopment.budgetSource : null,
budgetApprove: getDevelopment.budgetApprove ? getDevelopment.budgetApprove : null,
bookNo: getDevelopment.bookNo ? getDevelopment.bookNo : null,
bookNoDate: getDevelopment.bookNoDate ? getDevelopment.bookNoDate : null,
bookApproveDate: getDevelopment.bookApproveDate ? getDevelopment.bookApproveDate : null,
useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : false,
changeDetail: getDevelopment.changeDetail ? getDevelopment.changeDetail : null,
scholarshipType: getDevelopment.scholarshipType ? getDevelopment.scholarshipType : null,
fundType: getDevelopment.fundType ? getDevelopment.fundType : null,
contractNo: getDevelopment.contractNo ? getDevelopment.contractNo : null,
contractDate: getDevelopment.contractDate ? getDevelopment.contractDate : null,
reportBackNo: getDevelopment.reportBackNo ? getDevelopment.reportBackNo : null,
reportBackNoDate: getDevelopment.reportBackNoDate ? getDevelopment.reportBackNoDate : null,
reportBackDate: getDevelopment.reportBackDate ? getDevelopment.reportBackDate : null,
degreeLevel: getDevelopment.degreeLevel ? getDevelopment.degreeLevel : null,
course: getDevelopment.course ? getDevelopment.course : null,
field: getDevelopment.field ? getDevelopment.field : null,
faculty: getDevelopment.faculty ? getDevelopment.faculty : null,
educationalInstitution: getDevelopment.educationalInstitution
? getDevelopment.educationalInstitution
: null,
startDate: getDevelopment.startDate ? getDevelopment.startDate : null,
endDate: getDevelopment.endDate ? getDevelopment.endDate : null,
studyPlace: getDevelopment.studyPlace ? getDevelopment.studyPlace : null,
studyTopic: getDevelopment.studyTopic ? getDevelopment.studyTopic : null,
studyStartDate: getDevelopment.studyStartDate ? getDevelopment.studyStartDate : null,
studyEndDate: getDevelopment.studyEndDate ? getDevelopment.studyEndDate : null,
studyCountry: getDevelopment.studyCountry ? getDevelopment.studyCountry : null,
studyAbroadTopic: getDevelopment.studyAbroadTopic ? getDevelopment.studyAbroadTopic : null,
studyAbroadStartDate: getDevelopment.studyAbroadStartDate
? getDevelopment.studyAbroadStartDate
: null,
studyAbroadEndDate: getDevelopment.studyAbroadEndDate
? getDevelopment.studyAbroadEndDate
: null,
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 / ADMIN
*
* @summary DEV_015 - / #15 ADMIN
*
* @param {string} id Id ADMIN
*/
@Get("admin/{id}")
async GetDevelopemtScholarshipAdminById(@Request() request: RequestWithUser, @Path() id: string) {
await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP");
const getDevelopment = await this.developmentScholarshipRepository.findOne({
relations: ["posLevel", "posType", "posLevelguarantor", "posTypeguarantor"],
@ -481,12 +552,7 @@ export class DevelopmentScholarshipController extends Controller {
@Body() requestBody: UpdateDevelopmentScholarshipUser,
@Request() request: RequestWithUser,
) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development Scholarship.",
// });
await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP");
// await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP");
const getDevelopment = await this.developmentScholarshipRepository.findOne({
where: { id: id },
});
@ -497,11 +563,6 @@ export class DevelopmentScholarshipController extends Controller {
Object.assign(getDevelopment, requestBody);
getDevelopment.lastUpdateUserId = request.user.sub;
getDevelopment.lastUpdateFullName = request.user.name;
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentScholarship.",
// });
await this.developmentScholarshipRepository.save(getDevelopment, { data: request });
setLogDataDiff(request, { before, after: getDevelopment });
return new HttpSuccess(getDevelopment.id);
@ -521,11 +582,6 @@ export class DevelopmentScholarshipController extends Controller {
@Path() status: string,
@Request() request: RequestWithUser,
) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development Scholarship.",
// });
const getDevelopment = await this.developmentScholarshipRepository.findOne({
where: { id: id },
});
@ -539,11 +595,6 @@ export class DevelopmentScholarshipController extends Controller {
let scholarshipType = "";
if (_status == "GRADUATE") {
if (getDevelopment.scholarshipType != null) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Change Status Development Scholarship.",
// });
switch (getDevelopment.scholarshipType.trim().toUpperCase()) {
case "DOMESTICE":
scholarshipType = "การศึกษาในประเทศ";
@ -595,11 +646,6 @@ export class DevelopmentScholarshipController extends Controller {
});
} else if (_status == "NOTGRADUATE") {
getDevelopment.status = _status;
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Change Status Development Scholarship.",
// });
await this.developmentScholarshipRepository.save(getDevelopment, { data: request });
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ");