ทะเบียนประวัติใหม่

This commit is contained in:
Bright 2024-05-02 21:09:29 +07:00
parent 769352b4c2
commit 23b1b58dca
2 changed files with 76 additions and 1 deletions

View file

@ -19,7 +19,7 @@ import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { Profile, CreateProfile, UpdateProfile, ProfileHistory } from "../entities/Profile";
import { Profile, CreateProfile, UpdateProfile, ProfileHistory, CreateProfileAllFields } from "../entities/Profile";
import { Brackets, IsNull, Like, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { PosMaster } from "../entities/PosMaster";
@ -199,6 +199,41 @@ export class ProfileController extends Controller {
return new HttpSuccess();
}
/**
* API
*
* @summary ORG_065 - (ADMIN) #XXX
*
*/
@Post("all")
async createProfileAll(@Request() request: RequestWithUser, @Body() body: CreateProfileAllFields) {
if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) {
throw new HttpError(
HttpStatus.INTERNAL_SERVER_ERROR,
"เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
);
}
if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null;
if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
const profile: Profile = Object.assign(new Profile(), body);
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);
}
/**
* API
*

View file

@ -563,6 +563,46 @@ export class CreateProfile {
// bloodGroup: string | null;
}
export class CreateProfileAllFields {
rank: string;
prefix: string;
firstName: string;
lastName: string;
citizenId: string;
position: string;
posLevelId: string | null;
posTypeId: string | null;
email: string;
phone: string;
keycloak: string;
isProbation: boolean;
isLeave : boolean;
dateRetire : Date | null;
dateAppoint : Date | null;
dateStart: Date | null;
govAgeAbsent: number;
govAgePlus: number;
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;
};
export type UpdateProfile = {
rank?: string | null;
prefix?: string | null;