Task #2208 กรณีขอแก้ไขข้อมูลทะเบียนประวัติ และ IDP และคนขออยู่ในสำนักปลัดกรุงเทพมหานคร
All checks were successful
Build & Deploy on Dev / build (push) Successful in 59s

This commit is contained in:
harid 2026-01-21 13:53:29 +07:00
parent 757da877f6
commit ae3a634595
3 changed files with 66 additions and 11 deletions

View file

@ -23,7 +23,7 @@ import { Brackets } from "typeorm";
import CallAPI from "../interfaces/call-api";
import permission from "../interfaces/permission";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
@Route("api/v1/org/profile/edit")
@Tags("ProfileEdit")
@Security("bearerAuth")
@ -31,6 +31,7 @@ export class ProfileEditController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private profileEditRepo = AppDataSource.getRepository(ProfileEdit);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private orgRootRepo = AppDataSource.getRepository(OrgRoot);
@Get("user")
public async detailProfileEditUser(
@ -294,12 +295,32 @@ export class ProfileEditController extends Controller {
@Post()
public async newProfileEdit(@Request() req: RequestWithUser, @Body() body: CreateProfileEdit) {
const profile = await this.profileRepo.findOne({
where: { keycloak: req.user.sub },
relations: ["posLevel", "posType"],
relations: {
posLevel: true,
posType: true,
current_holders: true
},
where: {
keycloak: req.user.sub,
current_holders: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
}
}
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const orgRoot = await this.orgRootRepo.findOne({
select: {
isDeputy: true
},
where: {
id: profile.current_holders.find(x => x.orgRootId)!.orgRootId ?? ""
}
})
const data = new ProfileEdit();
const meta = {
@ -322,6 +343,7 @@ export class ProfileEditController extends Controller {
posLevelName: profile.posLevel.posLevelName,
posTypeName: profile.posType.posTypeName,
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
isDeputy: orgRoot?.isDeputy ?? false
})
.catch((error) => {
console.error("Error calling API:", error);