diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 45555676..cd3c7dfb 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -216,11 +216,9 @@ export class ProfileController extends Controller { @Request() request: RequestWithUser, @Body() body: CreateProfileAllFields, ) { - if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) { - throw new HttpError( - HttpStatus.INTERNAL_SERVER_ERROR, - "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว", - ); + const profileExist = await this.profileRepo.findOneBy({ citizenId: body.citizenId }) + if (profileExist) { + return new HttpSuccess(profileExist.id); } if (body.posLevelId === "") body.posLevelId = null; diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index f9c03233..8befca12 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -564,43 +564,43 @@ export class CreateProfile { } export class CreateProfileAllFields { - rank: string; + rank: string | null; prefix: string; firstName: string; lastName: string; citizenId: string; - position: string; + position: string | null; posLevelId: string | null; posTypeId: string | null; - email: string; - phone: string; - keycloak: string; - isProbation: boolean; - isLeave : boolean; + email: string | null; + phone: string | null; + keycloak: string | null; + isProbation: boolean | null; + isLeave : boolean | null; dateRetire : Date | null; dateAppoint : Date | null; dateStart: Date | null; - govAgeAbsent: number; - govAgePlus: number; + govAgeAbsent: number | null; + govAgePlus: number | null; birthDate: Date | null; reasonSameDate : Date | null; - ethnicity : string; - telephoneNumber : string; - nationality : string; - gender : string; - relationship : string; - religion : string; - bloodGroup : string; - registrationAddress : string; - registrationProvinceId : string; - registrationDistrictId: string; - registrationSubDistrictId : string; - registrationZipCode : string; - currentAddress : string; - currentProvinceId : string; - currentDistrictId : string; - currentSubDistrictId : string; - currentZipCode : string; + ethnicity : string | null; + telephoneNumber : string | null; + nationality : string | null; + gender : string | null; + relationship : string | null; + religion : string | null; + bloodGroup : string | null; + registrationAddress : string | null; + registrationProvinceId : string | null; + registrationDistrictId: string | null; + registrationSubDistrictId : string | null; + registrationZipCode : string | null; + currentAddress : string | null; + currentProvinceId : string | null; + currentDistrictId : string | null; + currentSubDistrictId : string | null; + currentZipCode : string | null; }; export type UpdateProfile = {