diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 6cde6f26..c42e6f81 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -53,6 +53,7 @@ import { ProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; import CallAPI from "../interfaces/call-api"; import Extension from "../interfaces/extension"; +import { Prefixe } from "../entities/Prefixe"; @Route("api/v1/org/profile") @Tags("Profile") @@ -83,7 +84,10 @@ export class ProfileController extends Controller { private educationRepository = AppDataSource.getRepository(ProfileEducation); private salaryRepository = AppDataSource.getRepository(ProfileSalary); private profileEducationRepository = AppDataSource.getRepository(ProfileEducation); - + private prefixRepo = AppDataSource.getRepository(Prefixe); + private provinceRepo = AppDataSource.getRepository(Province); + private districtRepo = AppDataSource.getRepository(District); + private subDistrictRepo = AppDataSource.getRepository(SubDistrict); /** * report ประวัติแบบย่อ ข้าราชการ * @@ -4483,4 +4487,108 @@ export class ProfileController extends Controller { await this.profileRepo.save(profile); return new HttpSuccess(profile); } + + /** + * API สร้างทะเบียนประวัติใหม่ + * + * @summary ORG_065 - สร้างทะเบียนประวัติใหม่ (ADMIN) #XXX + * + */ + @Post("all/dump-db") + async createProfileAllDump( + @Request() request: RequestWithUser, + @Body() body: CreateProfileAllFields, + ) { + const profile: Profile = Object.assign(new Profile(), body); + if (body && body.posLevelId) { + const findPosLevel = await this.posLevelRepo.findOne({ + where: { posLevelName: body.posLevelId }, + select:['id','posLevelName'] + }); + if (findPosLevel) { + profile.posLevelId = findPosLevel.id; + } + } + if (body && body.posTypeId) { + const findPosType = await this.posTypeRepo.findOne({ + where: { posTypeName: body.posTypeId }, + select:['id','posTypeName'] + }); + if (findPosType) { + profile.posTypeId = findPosType.id; + } + } + if (body && body.prefix) { + const findPrefix = await this.prefixRepo.findOne({ + where: { name: body.prefix }, + select:['id','name'] + }); + if (findPrefix) { + profile.prefix = findPrefix.id; + } + } + //current + if (body && body.currentProvinceId) { + const findProvince = await this.provinceRepo.findOne({ + where: { name: body.currentProvinceId }, + select:['id','name'] + }); + if (findProvince) { + profile.currentProvinceId = findProvince.id; + } + } + if (body && body.currentDistrictId) { + const findDistrict = await this.districtRepo.findOne({ + where: { name: body.currentDistrictId }, + select:['id','name'] + }); + if (findDistrict) { + profile.currentDistrictId = findDistrict.id; + } + } + if (body && body.currentSubDistrictId) { + const findSubDistrict = await this.subDistrictRepo.findOne({ + where: { name: body.currentSubDistrictId }, + select:['id','name'] + }); + if (findSubDistrict) { + profile.currentSubDistrictId = findSubDistrict.id; + } + } + //register + if (body && body.registrationProvinceId) { + const findProvince_regis = await this.provinceRepo.findOne({ + where: { name: body.registrationProvinceId }, + select:['id','name'] + }); + if (findProvince_regis) { + profile.registrationProvinceId = findProvince_regis.id; + } + } + if (body && body.registrationDistrictId) { + const findDistrict_regis = await this.districtRepo.findOne({ + where: { name: body.registrationDistrictId }, + select:['id','name'] + }); + if (findDistrict_regis) { + profile.registrationDistrictId = findDistrict_regis.id; + } + } + if (body && body.registrationSubDistrictId) { + const findSubDistrict_regis = await this.subDistrictRepo.findOne({ + where: { name: body.registrationSubDistrictId }, + select:['id','name'] + }); + if (findSubDistrict_regis) { + profile.registrationSubDistrictId = findSubDistrict_regis.id; + } + } + + profile.createdUserId = request.user.sub; + profile.createdFullName = request.user.name; + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + await this.profileRepo.save(profile); + return new HttpSuccess(profile.id); + } } diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index ffc7015e..5148f88c 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -688,6 +688,7 @@ export class CreateProfileAllFields { currentZipCode: string | null; } + export type UpdateProfile = { rank?: string | null; prefix?: string | null;