แก้ import data ไมพบข้อมูลในทะเบียนประวัติ

This commit is contained in:
kittapath 2024-09-03 19:08:13 +07:00
parent 8c39019f4a
commit 78ce7fa612
2 changed files with 92 additions and 6 deletions

View file

@ -359,6 +359,52 @@ export class DevelopmentScholarshipController extends Controller {
return new HttpSuccess(formattedData);
}
/**
* API /
*
* @summary DEV_012 - / #12
*
* @param {string} id Id
*/
@Put("admin/{id}")
async UpdateDevelopmentScholarshipAdminById(
@Path() id: string,
@Body() requestBody: UpdateDevelopmentScholarship,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP");
const development = await this.developmentScholarshipRepository.findOne({
where: { id: id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
if (requestBody.posTypeId != null) {
const checkId = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
}
}
if (requestBody.posLevelId != null) {
const checkId = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
if (!checkId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
}
}
const before = structuredClone(development);
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
await this.developmentScholarshipRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
return new HttpSuccess(development.id);
}
/**
* API / ADMIN
*