Merge branch 'dev/methapon' into develop

This commit is contained in:
Methapon2001 2024-03-21 11:31:22 +07:00
commit dedd74d6ff
9 changed files with 509 additions and 878 deletions

View file

@ -16,31 +16,32 @@ import {
} from "tsoa"; } from "tsoa";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { Profile, CreateProfile, UpdateProfile } from "../entities/Profile"; import { Profile, CreateProfile, UpdateProfile, ProfileHistory } from "../entities/Profile";
import { Brackets, In, IsNull, Like, Not } from "typeorm"; import { Brackets, IsNull, Like, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision"; import { OrgRevision } from "../entities/OrgRevision";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import { request } from "http";
import { calculateRetireDate } from "../interfaces/utils"; import { calculateRetireDate } from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/profile") @Route("api/v1/org/profile")
@Tags("Profile") @Tags("Profile")
@Security("bearerAuth") @Security("bearerAuth")
@Response( @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
) )
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") @SuccessResponse(HttpStatus.OK, "สำเร็จ")
export class ProfileController extends Controller { export class ProfileController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
private posMasterRepository = AppDataSource.getRepository(PosMaster); private posMasterRepo = AppDataSource.getRepository(PosMaster);
private profileRepository = AppDataSource.getRepository(Profile); private profileRepo = AppDataSource.getRepository(Profile);
private posLevelRepository = AppDataSource.getRepository(PosLevel); private profileHistoryRepo = AppDataSource.getRepository(ProfileHistory);
private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepo = AppDataSource.getRepository(PosLevel);
private posTypeRepo = AppDataSource.getRepository(PosType);
/** /**
* API * API
@ -49,58 +50,32 @@ export class ProfileController extends Controller {
* *
*/ */
@Post() @Post()
async createProfile( async createProfile(@Request() request: RequestWithUser, @Body() body: CreateProfile) {
@Body() if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) {
requestBody: CreateProfile,
@Request() request: { user: Record<string, any> },
) {
const _profile = await this.profileRepository.findOne({
where: { citizenId: requestBody.citizenId },
});
if (_profile) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
"เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว", "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
); );
} }
if (requestBody.posLevelId == "") {
requestBody.posLevelId = null; if (body.posLevelId === "") body.posLevelId = null;
} if (body.posTypeId === "") body.posTypeId = null;
if (requestBody.posLevelId) {
const checkPosLevel = await this.posLevelRepository.findOne({ if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
where: { id: requestBody.posLevelId }, throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
});
if (!checkPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
} }
if (requestBody.posTypeId == "") { if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
requestBody.posTypeId = null; throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
if (requestBody.posTypeId) {
const checkPosType = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
} }
const checkCitizenId = await this.profileRepository.findOne({ const profile = Object.assign(new Profile(), body);
where: { citizenId: requestBody.citizenId },
});
if (checkCitizenId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว");
}
const profile = Object.assign(new Profile(), requestBody);
profile.createdUserId = request.user.sub; profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name; profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub; profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name; profile.lastUpdateFullName = request.user.name;
await this.profileRepository.save(profile); await this.profileRepo.save(profile);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -113,65 +88,49 @@ export class ProfileController extends Controller {
*/ */
@Put("{id}") @Put("{id}")
async updateProfile( async updateProfile(
@Request() request: RequestWithUser,
@Path() id: string, @Path() id: string,
@Body() @Body() body: UpdateProfile,
requestBody: CreateProfile,
@Request() request: { user: Record<string, any> },
) { ) {
const profile = await this.profileRepository.findOne({ where: { id: id } }); const exists =
if (!profile) { !!body.citizenId &&
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); (await this.profileRepo.findOne({
where: { id: Not(id), citizenId: body.citizenId },
}));
if (exists) {
throw new HttpError(HttpStatus.CONFLICT, "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว");
} }
const _profile = await this.profileRepository.findOne({ if (body.posLevelId === "") body.posLevelId = null;
where: { id: Not(id), citizenId: requestBody.citizenId }, if (body.posTypeId === "") body.posTypeId = null;
});
if (_profile) { if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
throw new HttpError( throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
);
} }
if (requestBody.posLevelId == "") { if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
requestBody.posLevelId = null; throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
if (requestBody.posLevelId) {
const checkPosLevel = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
if (!checkPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
} }
if (requestBody.posTypeId == "") { const record = await this.profileRepo.findOneBy({ id });
requestBody.posTypeId = null;
}
if (requestBody.posTypeId) {
const checkPosType = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
}
const checkCitizenId = await this.profileRepository.findOne({ if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
where: {
id: Not(id),
citizenId: requestBody.citizenId,
},
});
if (checkCitizenId) { await this.profileHistoryRepo.save(
throw new HttpError(HttpStatusCode.NOT_FOUND, "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว"); Object.assign(new ProfileHistory(), {
} ...record,
profileId: id,
id: undefined,
}),
);
Object.assign(record, body);
record.lastUpdateUserId = request.user.sub;
record.lastUpdateFullName = request.user.name;
await this.profileRepo.save(record);
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
this.profileRepository.merge(profile, requestBody);
await this.profileRepository.save(profile);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -184,13 +143,12 @@ export class ProfileController extends Controller {
*/ */
@Delete("{id}") @Delete("{id}")
async deleteProfile(@Path() id: string) { async deleteProfile(@Path() id: string) {
const delProfile = await this.profileRepository.findOne({ const result = await this.profileRepo.delete({ id });
where: { id },
}); if (result.affected && result.affected <= 0) {
if (!delProfile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
} }
await this.profileRepository.delete({ id: id });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -202,27 +160,38 @@ export class ProfileController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("{id}") @Get("{id}")
async detailProfile(@Path() id: string) { async getProfile(@Path() id: string) {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepo.findOne({
relations: { relations: {
posLevel: true, posLevel: true,
posType: true, posType: true,
gender: true,
relationship: true,
bloodGroup: true,
}, },
where: { id }, where: { id },
select: [
"id",
"prefix",
"firstName",
"lastName",
"citizenId",
"position",
"posLevelId",
"posTypeId",
],
}); });
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(profile);
}
@Get("history/{id}")
async getProfileHistory(@Path() id: string) {
const profile = await this.profileHistoryRepo.find({
relations: {
posLevel: true,
posType: true,
gender: true,
relationship: true,
bloodGroup: true,
},
where: { profileId: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess(profile); return new HttpSuccess(profile);
} }
@ -236,75 +205,36 @@ export class ProfileController extends Controller {
async listProfile( async listProfile(
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword: string = "",
) { ) {
const [profile, total] = await this.profileRepository.findAndCount({ const [record, total] = await this.profileRepo.findAndCount({
select: [ relations: {
"id", posLevel: true,
"prefix", posType: true,
"firstName", gender: true,
"lastName", relationship: true,
"citizenId", bloodGroup: true,
"position",
"posLevelId",
"posTypeId",
],
where: {
citizenId: Like(`%${keyword}%`),
position: Like(`%${keyword}%`),
prefix: Like(`%${keyword}%`),
firstName: Like(`%${keyword}%`),
lastName: Like(`%${keyword}%`),
// posLevel: { posLevelName: keyword },
// posType: { posTypeName: Like(`%${keyword}%`) },
// salaryEmployeeMins: { group: keyword },
// salaryEmployee: { group: keyword },
}, },
where: [
{ citizenId: Like(`%${keyword}%`) },
{ position: Like(`%${keyword}%`) },
{ prefix: Like(`%${keyword}%`) },
{ firstName: Like(`%${keyword}%`) },
{ lastName: Like(`%${keyword}%`) },
{ email: Like(`%${keyword}%`) },
{ telephoneNumber: Like(`%${keyword}%`) },
],
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
skip: (page - 1) * pageSize, skip: (page - 1) * pageSize,
take: pageSize, take: pageSize,
}); });
// if (keyword != undefined && keyword !== "") { return new HttpSuccess({ data: record, total });
// const formattedKeyword = keyword.toLowerCase().replace(/\s+/g, "");
// const filteredProfile = profile.filter(
// (x) =>
// (x.prefix + x.firstName + x.lastName).replace(/\s+/g, "").includes(formattedKeyword) ||
// x.citizenId?.toString().includes(keyword) ||
// x.position?.toString().includes(keyword),
// );
// const formattedData = filteredProfile.map((item) => ({
// id: item.id,
// prefix: item.prefix,
// firstName: item.firstName,
// lastName: item.lastName,
// citizenId: item.citizenId,
// position: item.position,
// posLevelId: item.posLevelId,
// posTypeId: item.posTypeId,
// }));
// return new HttpSuccess({ data: formattedData, total: formattedData.length });
// }
const formattedData = profile.map((item) => ({
id: item.id,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
position: item.position,
posLevelId: item.posLevelId,
posTypeId: item.posTypeId,
}));
return new HttpSuccess({ data: formattedData, total });
} }
/** /**
* API * API
* *
* @summary ORG_063 - (ADMIN) #68 * @summary ORG_063 - (ADMIN) #68
*
*/ */
@Post("search") @Post("search")
async searchProfileOrg( async searchProfileOrg(
@ -318,7 +248,7 @@ export class ProfileController extends Controller {
keyword?: string; keyword?: string;
}, },
) { ) {
const orgRevision = await this.orgRevisionRepository.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { where: {
orgRevisionIsDraft: true, orgRevisionIsDraft: true,
orgRevisionIsCurrent: false, orgRevisionIsCurrent: false,
@ -326,9 +256,9 @@ export class ProfileController extends Controller {
relations: ["posMasters"], relations: ["posMasters"],
}); });
if (!orgRevision) { if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
} }
const [profiles, total] = await this.profileRepository const [profiles, total] = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.next_holders", "next_holders") .leftJoinAndSelect("profile.next_holders", "next_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
@ -428,21 +358,21 @@ export class ProfileController extends Controller {
*/ */
@Get("keycloak/position") @Get("keycloak/position")
async getProfileByKeycloak(@Request() request: { user: Record<string, any> }) { async getProfileByKeycloak(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"], relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
const orgRevisionPublish = await this.orgRevisionRepository const orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false") .where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true") .andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne(); .getOne();
if (!orgRevisionPublish) { if (!orgRevisionPublish) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
} }
const _profile = { const _profile = {
@ -549,28 +479,28 @@ export class ProfileController extends Controller {
let findProfile: any; let findProfile: any;
switch (body.fieldName) { switch (body.fieldName) {
case "idcard": case "idcard":
findProfile = await this.profileRepository.find({ findProfile = await this.profileRepo.find({
where: { citizenId: Like(`%${body.keyword}%`) }, where: { citizenId: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"], relations: ["posType", "posLevel"],
}); });
break; break;
case "firstname": case "firstname":
findProfile = await this.profileRepository.find({ findProfile = await this.profileRepo.find({
where: { firstName: Like(`%${body.keyword}%`) }, where: { firstName: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"], relations: ["posType", "posLevel"],
}); });
break; break;
case "lastname": case "lastname":
findProfile = await this.profileRepository.find({ findProfile = await this.profileRepo.find({
where: { lastName: Like(`%${body.keyword}%`) }, where: { lastName: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"], relations: ["posType", "posLevel"],
}); });
break; break;
default: default:
findProfile = await this.profileRepository.find({ findProfile = await this.profileRepo.find({
relations: ["posType", "posLevel"], relations: ["posType", "posLevel"],
}); });
break; break;
@ -609,17 +539,17 @@ export class ProfileController extends Controller {
let commanderFullname_: any = {}; let commanderFullname_: any = {};
let commanderPosition_: any = {}; let commanderPosition_: any = {};
const findProfile = await this.profileRepository.findOne({ const findProfile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
}); });
const findRevision = await this.orgRevisionRepository.findOne({ const findRevision = await this.orgRevisionRepo.findOne({
where: { where: {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
}, },
}); });
const findPosMaster = await this.posMasterRepository.findOne({ const findPosMaster = await this.posMasterRepo.findOne({
where: { where: {
current_holderId: findProfile?.id, current_holderId: findProfile?.id,
orgRevisionId: findRevision?.id, orgRevisionId: findRevision?.id,
@ -648,7 +578,7 @@ export class ProfileController extends Controller {
condition = { orgRootId: childId, orgChild1Id: IsNull() }; condition = { orgRootId: childId, orgChild1Id: IsNull() };
} }
const findCmd = await this.posMasterRepository.findOne({ const findCmd = await this.posMasterRepo.findOne({
where: { where: {
current_holderId: Not(IsNull()) || Not(""), current_holderId: Not(IsNull()) || Not(""),
orgRevisionId: findRevision?.id, orgRevisionId: findRevision?.id,
@ -791,12 +721,12 @@ export class ProfileController extends Controller {
@Body() @Body()
requestBody: { citizenId: string }, requestBody: { citizenId: string },
) { ) {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepo.findOne({
where: { id: Not(id), citizenId: requestBody.citizenId }, where: { id: Not(id), citizenId: requestBody.citizenId },
}); });
if (profile) { if (profile) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
"เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว", "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
); );
} }
@ -838,7 +768,7 @@ export class ProfileController extends Controller {
.take(body.pageSize) .take(body.pageSize)
.getManyAndCount(); .getManyAndCount();
const orgRevisionActive = await this.orgRevisionRepository.findOne({ const orgRevisionActive = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
@ -928,11 +858,11 @@ export class ProfileController extends Controller {
period: string; period: string;
}, },
) { ) {
const findRevision = await this.orgRevisionRepository.findOne({ const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
} }
const [findPosMaster, total] = await AppDataSource.getRepository(PosMaster) const [findPosMaster, total] = await AppDataSource.getRepository(PosMaster)
@ -1024,7 +954,7 @@ export class ProfileController extends Controller {
.take(body.pageSize) .take(body.pageSize)
.getManyAndCount(); .getManyAndCount();
if (!findPosMaster) { if (!findPosMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. PosMaster");
} }
const formattedData = findPosMaster.map((item) => { const formattedData = findPosMaster.map((item) => {
@ -1142,12 +1072,12 @@ export class ProfileController extends Controller {
@Path() revisionId: string, @Path() revisionId: string,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"], relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
const _profile = { const _profile = {

View file

@ -16,30 +16,37 @@ import {
} from "tsoa"; } from "tsoa";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { Brackets, IsNull, Like, Not } from "typeorm"; import { Brackets, IsNull, Like, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision"; import { OrgRevision } from "../entities/OrgRevision";
import { calculateRetireDate } from "../interfaces/utils"; import { calculateRetireDate } from "../interfaces/utils";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { ProfileEmployee, CreateProfileEmployee } from "../entities/ProfileEmployee"; import {
ProfileEmployee,
CreateProfileEmployee,
UpdateProfileEmployee,
ProfileEmployeeHistory,
} from "../entities/ProfileEmployee";
import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosType } from "../entities/EmployeePosType";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/profile-employee") @Route("api/v1/org/profile-employee")
@Tags("Profile") @Tags("Profile")
@Security("bearerAuth") @Security("bearerAuth")
@Response( @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
) )
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") @SuccessResponse(HttpStatus.OK, "สำเร็จ")
export class ProfileEmployeeController extends Controller { export class ProfileEmployeeController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
private posMasterRepository = AppDataSource.getRepository(EmployeePosMaster); private posMasterRepo = AppDataSource.getRepository(EmployeePosMaster);
private profileRepository = AppDataSource.getRepository(ProfileEmployee); private profileRepo = AppDataSource.getRepository(ProfileEmployee);
private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel); private profileHistoryRepo = AppDataSource.getRepository(ProfileEmployeeHistory);
private posTypeRepository = AppDataSource.getRepository(EmployeePosType); private posLevelRepo = AppDataSource.getRepository(EmployeePosLevel);
private posTypeRepo = AppDataSource.getRepository(EmployeePosType);
/** /**
* API * API
@ -48,58 +55,32 @@ export class ProfileEmployeeController extends Controller {
* *
*/ */
@Post() @Post()
async createProfile( async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) {
@Body() if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) {
requestBody: CreateProfileEmployee,
@Request() request: { user: Record<string, any> },
) {
const _profile = await this.profileRepository.findOne({
where: { citizenId: requestBody.citizenId },
});
if (_profile) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
"เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว", "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
); );
} }
if (requestBody.posLevelId == "") {
requestBody.posLevelId = null; if (body.posLevelId === "") body.posLevelId = null;
} if (body.posTypeId === "") body.posTypeId = null;
if (requestBody.posLevelId) {
const checkPosLevel = await this.posLevelRepository.findOne({ if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
where: { id: requestBody.posLevelId }, throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
});
if (!checkPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
} }
if (requestBody.posTypeId == "") { if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
requestBody.posTypeId = null; throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
if (requestBody.posTypeId) {
const checkPosType = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
} }
const checkCitizenId = await this.profileRepository.findOne({ const profile = Object.assign(new ProfileEmployee(), body);
where: { citizenId: requestBody.citizenId },
});
if (checkCitizenId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว");
}
const profile = Object.assign(new ProfileEmployee(), requestBody);
profile.createdUserId = request.user.sub; profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name; profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub; profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name; profile.lastUpdateFullName = request.user.name;
await this.profileRepository.save(profile); await this.profileRepo.save(profile);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -112,65 +93,49 @@ export class ProfileEmployeeController extends Controller {
*/ */
@Put("{id}") @Put("{id}")
async updateProfile( async updateProfile(
@Request() request: RequestWithUser,
@Path() id: string, @Path() id: string,
@Body() @Body() body: UpdateProfileEmployee,
requestBody: CreateProfileEmployee,
@Request() request: { user: Record<string, any> },
) { ) {
const profile = await this.profileRepository.findOne({ where: { id: id } }); const exists =
if (!profile) { !!body.citizenId &&
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); (await this.profileRepo.findOne({
where: { id: Not(id), citizenId: body.citizenId },
}));
if (exists) {
throw new HttpError(HttpStatus.CONFLICT, "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว");
} }
const _profile = await this.profileRepository.findOne({ if (body.posLevelId === "") body.posLevelId = null;
where: { id: Not(id), citizenId: requestBody.citizenId }, if (body.posTypeId === "") body.posTypeId = null;
});
if (_profile) { if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
throw new HttpError( throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
);
} }
if (requestBody.posLevelId == "") { if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
requestBody.posLevelId = null; throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
if (requestBody.posLevelId) {
const checkPosLevel = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
if (!checkPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
} }
if (requestBody.posTypeId == "") { const record = await this.profileRepo.findOneBy({ id });
requestBody.posTypeId = null;
}
if (requestBody.posTypeId) {
const checkPosType = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
}
const checkCitizenId = await this.profileRepository.findOne({ if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
where: {
id: Not(id),
citizenId: requestBody.citizenId,
},
});
if (checkCitizenId) { await this.profileHistoryRepo.save(
throw new HttpError(HttpStatusCode.NOT_FOUND, "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว"); Object.assign(new ProfileEmployeeHistory(), {
} ...record,
profileEmployeeId: id,
id: undefined,
}),
);
Object.assign(record, body);
record.lastUpdateUserId = request.user.sub;
record.lastUpdateFullName = request.user.name;
await this.profileRepo.save(record);
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
this.profileRepository.merge(profile, requestBody);
await this.profileRepository.save(profile);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -183,13 +148,12 @@ export class ProfileEmployeeController extends Controller {
*/ */
@Delete("{id}") @Delete("{id}")
async deleteProfile(@Path() id: string) { async deleteProfile(@Path() id: string) {
const delProfile = await this.profileRepository.findOne({ const result = await this.profileRepo.delete({ id });
where: { id },
}); if (result.affected && result.affected <= 0) {
if (!delProfile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
} }
await this.profileRepository.delete({ id: id });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -202,22 +166,19 @@ export class ProfileEmployeeController extends Controller {
*/ */
@Get("{id}") @Get("{id}")
async detailProfile(@Path() id: string) { async detailProfile(@Path() id: string) {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
posType: true,
gender: true,
relationship: true,
bloodGroup: true,
},
where: { id }, where: { id },
select: [
"id",
"prefix",
"firstName",
"lastName",
"citizenId",
"position",
"posLevelId",
"posTypeId",
],
}); });
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(profile); return new HttpSuccess(profile);
} }
@ -231,57 +192,48 @@ export class ProfileEmployeeController extends Controller {
async listProfile( async listProfile(
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword: string = "",
) { ) {
const [profile, total] = await this.profileRepository.findAndCount({ const [record, total] = await this.profileRepo.findAndCount({
select: [ relations: {
"id", posLevel: true,
"prefix", posType: true,
"firstName", gender: true,
"lastName", relationship: true,
"citizenId", bloodGroup: true,
"position", },
"posLevelId", where: [
"posTypeId", { citizenId: Like(`%${keyword}%`) },
{ position: Like(`%${keyword}%`) },
{ prefix: Like(`%${keyword}%`) },
{ firstName: Like(`%${keyword}%`) },
{ lastName: Like(`%${keyword}%`) },
{ email: Like(`%${keyword}%`) },
{ telephoneNumber: Like(`%${keyword}%`) },
], ],
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
skip: (page - 1) * pageSize, skip: (page - 1) * pageSize,
take: pageSize, take: pageSize,
}); });
if (keyword != undefined && keyword !== "") { return new HttpSuccess({ data: record, total });
const formattedKeyword = keyword.toLowerCase().replace(/\s+/g, ""); }
const filteredProfile = profile.filter(
(x) =>
(x.prefix + x.firstName + x.lastName).replace(/\s+/g, "").includes(formattedKeyword) ||
x.citizenId?.toString().includes(keyword) ||
x.position?.toString().includes(keyword),
);
const formattedData = filteredProfile.map((item) => ({ @Get("history/{id}")
id: item.id, async getProfileHistory(@Path() id: string) {
prefix: item.prefix, const profile = await this.profileHistoryRepo.find({
firstName: item.firstName, relations: {
lastName: item.lastName, posLevel: true,
citizenId: item.citizenId, posType: true,
position: item.position, gender: true,
posLevelId: item.posLevelId, relationship: true,
posTypeId: item.posTypeId, bloodGroup: true,
})); },
where: { profileEmployeeId: id },
});
return new HttpSuccess({ data: formattedData, total: formattedData.length }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const formattedData = profile.map((item) => ({ return new HttpSuccess(profile);
id: item.id,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
position: item.position,
posLevelId: item.posLevelId,
posTypeId: item.posTypeId,
}));
return new HttpSuccess({ data: formattedData, total });
} }
/** /**
@ -302,7 +254,7 @@ export class ProfileEmployeeController extends Controller {
keyword?: string; keyword?: string;
}, },
) { ) {
const orgRevision = await this.orgRevisionRepository.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { where: {
orgRevisionIsDraft: true, orgRevisionIsDraft: true,
orgRevisionIsCurrent: false, orgRevisionIsCurrent: false,
@ -310,9 +262,9 @@ export class ProfileEmployeeController extends Controller {
relations: ["posMasters"], relations: ["posMasters"],
}); });
if (!orgRevision) { if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
} }
const [profiles, total] = await this.profileRepository const [profiles, total] = await this.profileRepo
.createQueryBuilder("profileEmployee") .createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.next_holders", "next_holders") .leftJoinAndSelect("profileEmployee.next_holders", "next_holders")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
@ -412,21 +364,21 @@ export class ProfileEmployeeController extends Controller {
*/ */
@Get("keycloak/position") @Get("keycloak/position")
async getProfileByKeycloak(@Request() request: { user: Record<string, any> }) { async getProfileByKeycloak(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"], relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
const orgRevisionPublish = await this.orgRevisionRepository const orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false") .where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true") .andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne(); .getOne();
if (!orgRevisionPublish) { if (!orgRevisionPublish) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
} }
const _profile = { const _profile = {
@ -533,28 +485,28 @@ export class ProfileEmployeeController extends Controller {
let findProfile: any; let findProfile: any;
switch (body.fieldName) { switch (body.fieldName) {
case "idcard": case "idcard":
findProfile = await this.profileRepository.find({ findProfile = await this.profileRepo.find({
where: { citizenId: Like(`%${body.keyword}%`) }, where: { citizenId: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"], relations: ["posType", "posLevel"],
}); });
break; break;
case "firstname": case "firstname":
findProfile = await this.profileRepository.find({ findProfile = await this.profileRepo.find({
where: { firstName: Like(`%${body.keyword}%`) }, where: { firstName: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"], relations: ["posType", "posLevel"],
}); });
break; break;
case "lastname": case "lastname":
findProfile = await this.profileRepository.find({ findProfile = await this.profileRepo.find({
where: { lastName: Like(`%${body.keyword}%`) }, where: { lastName: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"], relations: ["posType", "posLevel"],
}); });
break; break;
default: default:
findProfile = await this.profileRepository.find({ findProfile = await this.profileRepo.find({
relations: ["posType", "posLevel"], relations: ["posType", "posLevel"],
}); });
break; break;
@ -593,17 +545,17 @@ export class ProfileEmployeeController extends Controller {
let commanderFullname_: any = {}; let commanderFullname_: any = {};
let commanderPosition_: any = {}; let commanderPosition_: any = {};
const findProfile = await this.profileRepository.findOne({ const findProfile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
}); });
const findRevision = await this.orgRevisionRepository.findOne({ const findRevision = await this.orgRevisionRepo.findOne({
where: { where: {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
}, },
}); });
const findPosMaster = await this.posMasterRepository.findOne({ const findPosMaster = await this.posMasterRepo.findOne({
where: { where: {
current_holderId: findProfile?.id, current_holderId: findProfile?.id,
orgRevisionId: findRevision?.id, orgRevisionId: findRevision?.id,
@ -632,7 +584,7 @@ export class ProfileEmployeeController extends Controller {
condition = { orgRootId: childId, orgChild1Id: IsNull() }; condition = { orgRootId: childId, orgChild1Id: IsNull() };
} }
const findCmd = await this.posMasterRepository.findOne({ const findCmd = await this.posMasterRepo.findOne({
where: { where: {
current_holderId: Not(IsNull()) || Not(""), current_holderId: Not(IsNull()) || Not(""),
orgRevisionId: findRevision?.id, orgRevisionId: findRevision?.id,
@ -775,12 +727,12 @@ export class ProfileEmployeeController extends Controller {
@Body() @Body()
requestBody: { citizenId: string }, requestBody: { citizenId: string },
) { ) {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepo.findOne({
where: { id: Not(id), citizenId: requestBody.citizenId }, where: { id: Not(id), citizenId: requestBody.citizenId },
}); });
if (profile) { if (profile) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
"เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว", "เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
); );
} }
@ -822,7 +774,7 @@ export class ProfileEmployeeController extends Controller {
.take(body.pageSize) .take(body.pageSize)
.getManyAndCount(); .getManyAndCount();
const orgRevisionActive = await this.orgRevisionRepository.findOne({ const orgRevisionActive = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
@ -912,11 +864,11 @@ export class ProfileEmployeeController extends Controller {
period: string; period: string;
}, },
) { ) {
const findRevision = await this.orgRevisionRepository.findOne({ const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
} }
const [findPosMaster, total] = await AppDataSource.getRepository(EmployeePosMaster) const [findPosMaster, total] = await AppDataSource.getRepository(EmployeePosMaster)
@ -1007,7 +959,7 @@ export class ProfileEmployeeController extends Controller {
.take(body.pageSize) .take(body.pageSize)
.getManyAndCount(); .getManyAndCount();
if (!findPosMaster) { if (!findPosMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. PosMaster");
} }
const formattedData = findPosMaster.map((item) => { const formattedData = findPosMaster.map((item) => {
@ -1114,12 +1066,12 @@ export class ProfileEmployeeController extends Controller {
@Path() revisionId: string, @Path() revisionId: string,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"], relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
const _profile = { const _profile = {

View file

@ -1,204 +0,0 @@
import {
Controller,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
SuccessResponse,
Response,
Get,
Query,
Patch,
Example,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import {
ProfileInformationHistory,
ProfileInformation,
CreateProfileInformation,
UpdateProfileInformation,
} from "../entities/ProfileInformation";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { AppDataSource } from "../database/data-source";
@Route("api/v1/org/profile/information")
@Tags("ProfileInformation")
@Security("bearerAuth")
export class ProfileInformationController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private profileInformationRepo = AppDataSource.getRepository(ProfileInformation);
private profileInformationHistoryRepo = AppDataSource.getRepository(ProfileInformationHistory);
@Get("{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "42deba79-0725-403f-898d-6c142b2842a5",
createdAt: "2024-03-19T19:47:26.512Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T20:01:15.000Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
citizenId: "1849900687228",
prefix: "นาย",
firstName: "ธนพนธ์",
lastName: "แสงจันทร์",
birthDate: "2024-03-20T02:59:27.000Z",
ethnicity: "ไทย",
religion: "-",
telephoneNumber: "0639195701",
genderId: "74ec022c-b961-47f4-985e-2d9cbb10984c",
relationshipId: "5872f993-6dc3-44c7-85d3-f56825abd96d",
bloodGroupId: "fab11ded-8177-4e23-a791-78a10bc92333",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
},
],
})
public async detailProfileInformation(@Path() profileId: string) {
const getProfileInformation = await this.profileInformationRepo.findOne({
relations: {
bloodGroup: true,
relationship: true,
gender: true,
},
where: { profileId },
});
if (!getProfileInformation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileInformation);
}
@Get("history/{informationId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "9abba9df-5fa0-4056-847d-4b3680b61ee5",
createdAt: "2024-03-19T20:07:24.320Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T20:07:24.320Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "string",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
citizenId: "1849900687228",
prefix: "นาย",
firstName: "ธนพนธ์",
lastName: "แสงจันทร์",
birthDate: "2024-03-20T03:05:41.000Z",
ethnicity: "ไทย",
religion: "-",
telephoneNumber: "0639195701",
genderId: "74ec022c-b961-47f4-985e-2d9cbb10984c",
relationshipId: "5872f993-6dc3-44c7-85d3-f56825abd96d",
bloodGroupId: "fab11ded-8177-4e23-a791-78a10bc92333",
profileId: null,
profileInformationId: "42deba79-0725-403f-898d-6c142b2842a5",
},
],
})
public async getProfileInformationHistory(@Path() informationId: string) {
const record = await this.profileInformationHistoryRepo.find({
relations: {
bloodGroup: true,
relationship: true,
gender: true,
},
where: {
profileInformationId: informationId,
},
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileInformation(
@Request() req: RequestWithUser,
@Body() body: CreateProfileInformation,
) {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const data = new ProfileInformation();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
};
Object.assign(data, { ...body, ...meta });
await this.profileInformationRepo.save(data);
return new HttpSuccess();
}
@Patch("{informationId}")
public async editProfileInformation(
@Body() requestBody: UpdateProfileInformation,
@Request() req: RequestWithUser,
@Path() informationId: string,
) {
const record = await this.profileInformationRepo.findOneBy({ id: informationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileInformationHistory();
console.log(requestBody);
Object.assign(history, { ...record, id: undefined });
Object.assign(record, requestBody);
history.profileInformationId = informationId;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
await Promise.all([
this.profileInformationRepo.save(record),
this.profileInformationHistoryRepo.save(history),
]);
return new HttpSuccess();
}
@Delete("{informationId}")
public async deleteProfileInformation(@Path() informationId: string) {
await this.profileInformationHistoryRepo.delete({
profileInformationId: informationId,
});
const result = await this.profileInformationRepo.delete({ id: informationId });
if (result.affected && result.affected <= 0)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess();
}
}

View file

@ -1,7 +1,7 @@
import { Entity, Column, OneToMany } from "typeorm"; import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { Profile } from "./Profile";
import { ProfileInformation } from "./ProfileInformation"; import { ProfileEmployee } from "./ProfileEmployee";
@Entity("bloodGroup") @Entity("bloodGroup")
export class BloodGroup extends EntityBase { export class BloodGroup extends EntityBase {
@ -13,8 +13,11 @@ export class BloodGroup extends EntityBase {
}) })
name: string; name: string;
@OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.bloodGroupId) @OneToMany(() => Profile, (v) => v.bloodGroup)
profileInformations: ProfileInformation[]; profile: Profile[];
@OneToMany(() => Profile, (v) => v.bloodGroup)
profileEmployee: ProfileEmployee[];
} }
export class CreateBloodGroup { export class CreateBloodGroup {

View file

@ -1,7 +1,7 @@
import { Entity, Column, OneToMany } from "typeorm"; import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { Profile } from "./Profile";
import { ProfileInformation } from "./ProfileInformation"; import { ProfileEmployee } from "./ProfileEmployee";
@Entity("gender") @Entity("gender")
export class Gender extends EntityBase { export class Gender extends EntityBase {
@ -13,8 +13,11 @@ export class Gender extends EntityBase {
}) })
name: string; name: string;
@OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.genderId) @OneToMany(() => Profile, (v) => v.gender)
profileInformations: ProfileInformation[]; profile: Profile[];
@OneToMany(() => ProfileEmployee, (v) => v.gender)
profileEmployee: ProfileEmployee[];
} }
export class CreateGender { export class CreateGender {

View file

@ -1,4 +1,4 @@
import { Entity, Column, OneToMany, OneToOne, JoinColumn, ManyToMany, ManyToOne } from "typeorm"; import { Entity, Column, OneToMany, JoinColumn, ManyToOne } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { PosMaster } from "./PosMaster"; import { PosMaster } from "./PosMaster";
import { PosLevel } from "./PosLevel"; import { PosLevel } from "./PosLevel";
@ -16,9 +16,11 @@ import { ProfileAbility } from "./ProfileAbility";
import { ProfileDuty } from "./ProfileDuty"; import { ProfileDuty } from "./ProfileDuty";
import { ProfileNopaid } from "./ProfileNopaid"; import { ProfileNopaid } from "./ProfileNopaid";
import { ProfileOther } from "./ProfileOther"; import { ProfileOther } from "./ProfileOther";
import { ProfileInformation } from "./ProfileInformation";
import { ProfileFamilyHistory } from "./ProfileFamily"; import { ProfileFamilyHistory } from "./ProfileFamily";
import { ProfileGovernment } from "./ProfileGovernment"; import { ProfileGovernment } from "./ProfileGovernment";
import { Gender } from "./Gender";
import { Relationship } from "./Relationship";
import { BloodGroup } from "./BloodGroup";
@Entity("profile") @Entity("profile")
export class Profile extends EntityBase { export class Profile extends EntityBase {
@ -139,6 +141,63 @@ export class Profile extends EntityBase {
}) })
birthDate: Date; birthDate: Date;
@Column({
nullable: true,
comment: "เชื้อชาติ",
length: 255,
default: null,
})
ethnicity: string;
@Column({
nullable: true,
comment: "ศาสนา",
length: 255,
default: null,
})
religion: string;
@Column({
nullable: true,
comment: "เบอร์โทร",
length: 255,
default: null,
})
telephoneNumber: string;
@Column({
nullable: true,
comment: "เพศ",
length: 40,
default: null,
})
genderId: string;
@ManyToOne(() => Gender, (v) => v.profile)
gender: Gender;
@Column({
nullable: true,
comment: "ความสัมพันธ์",
length: 40,
default: null,
})
relationshipId: string;
@ManyToOne(() => Relationship, (v) => v.profile)
relationship: Relationship;
@Column({
nullable: true,
comment: "กรุ๊ปเลือด",
length: 40,
default: null,
})
bloodGroupId: string;
@ManyToOne(() => BloodGroup, (v) => v.profile)
bloodGroup: BloodGroup;
@OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder) @OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder)
current_holders: PosMaster[]; current_holders: PosMaster[];
@ -190,6 +249,9 @@ export class Profile extends EntityBase {
@OneToMany(() => ProfileGovernment, (profileGovernment) => profileGovernment.profile) @OneToMany(() => ProfileGovernment, (profileGovernment) => profileGovernment.profile)
profileGovernment: ProfileGovernment[]; profileGovernment: ProfileGovernment[];
@OneToMany(() => ProfileHistory, (v) => v.profile)
histories: ProfileHistory[];
@ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles) @ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles)
@JoinColumn({ name: "posLevelId" }) @JoinColumn({ name: "posLevelId" })
posLevel: PosLevel; posLevel: PosLevel;
@ -197,32 +259,61 @@ export class Profile extends EntityBase {
@ManyToOne(() => PosType, (posType) => posType.profiles) @ManyToOne(() => PosType, (posType) => posType.profiles)
@JoinColumn({ name: "posTypeId" }) @JoinColumn({ name: "posTypeId" })
posType: PosType; posType: PosType;
}
@OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.profile) @Entity("profileHistory")
profileInformation: ProfileInformation[]; export class ProfileHistory extends Profile {
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง ProfileInformation",
default: null,
})
profileId: string;
@ManyToOne(() => Profile, (v) => v.histories, { onDelete: "CASCADE" })
profile: Profile;
} }
export class CreateProfile { export class CreateProfile {
@Column()
prefix: string; prefix: string;
@Column()
firstName: string; firstName: string;
@Column()
lastName: string; lastName: string;
@Column()
citizenId: string;
@Column()
position: string; position: string;
email: string | null;
@Column("uuid") phone: string | null;
isProbation: boolean | null;
dateRetire: Date | null;
birthDate: Date | null;
ethnicity: string | null;
religion: string | null;
telephoneNumber: string | null;
citizenId: string;
posLevelId: string | null; posLevelId: string | null;
@Column("uuid")
posTypeId: string | null; posTypeId: string | null;
genderId: string | null;
relationshipId: string | null;
bloodGroupId: string | null;
} }
export type UpdateProfile = Partial<CreateProfile>; export type UpdateProfile = {
prefix?: string | null;
firstName?: string | null;
lastName?: string | null;
position?: string | null;
email?: string | null;
phone?: string | null;
keycloak?: string | null;
isProbation?: boolean | null;
dateRetire?: Date | null;
birthDate?: Date | null;
ethnicity?: string | null;
religion?: string | null;
telephoneNumber?: string | null;
citizenId?: string | null;
posLevelId?: string | null;
posTypeId?: string | null;
genderId?: string | null;
relationshipId?: string | null;
bloodGroupId?: string | null;
};

View file

@ -1,26 +1,13 @@
import { Entity, Column, OneToMany, OneToOne, JoinColumn, ManyToMany, ManyToOne } from "typeorm"; import { Entity, Column, OneToMany, ManyToOne } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { PosMaster } from "./PosMaster";
import { PosLevel } from "./PosLevel";
import { PosType } from "./PosType";
import { ProfileSalary } from "./ProfileSalary";
import { ProfileDiscipline } from "./ProfileDiscipline";
import { ProfileCertificate } from "./ProfileCertificate";
import { ProfileEducation } from "./ProfileEducation";
import { ProfileTraining } from "./ProfileTraining";
import { ProfileInsignia } from "./ProfileInsignia";
import { ProfileHonor } from "./ProfileHonor";
import { ProfileAssessment } from "./ProfileAssessment";
import { ProfileLeave } from "./ProfileLeave";
import { ProfileAbility } from "./ProfileAbility";
import { ProfileDuty } from "./ProfileDuty";
import { ProfileNopaid } from "./ProfileNopaid";
import { ProfileOther } from "./ProfileOther";
import { EmployeePosLevel } from "./EmployeePosLevel"; import { EmployeePosLevel } from "./EmployeePosLevel";
import { EmployeePosType } from "./EmployeePosType"; import { EmployeePosType } from "./EmployeePosType";
import { EmployeePosMaster } from "./EmployeePosMaster"; import { EmployeePosMaster } from "./EmployeePosMaster";
import { ProfileSalaryEmployee } from "./ProfileSalaryEmployee"; import { ProfileSalaryEmployee } from "./ProfileSalaryEmployee";
import { ProfileDisciplineEmployee } from "./ProfileDisciplineEmployee"; import { ProfileDisciplineEmployee } from "./ProfileDisciplineEmployee";
import { BloodGroup } from "./BloodGroup";
import { Relationship } from "./Relationship";
import { Gender } from "./Gender";
@Entity("profileEmployee") @Entity("profileEmployee")
export class ProfileEmployee extends EntityBase { export class ProfileEmployee extends EntityBase {
@ -92,25 +79,6 @@ export class ProfileEmployee extends EntityBase {
}) })
phone: string; phone: string;
// @Column({
// nullable: true,
// length: 40,
// comment:
// "คนครองปัจจุบัน เมื่อทำสำเนาโครงสร้างและตำแหน่งพร้อมกับคนครองมา คนครองจะอยู่ในฟิลด์นี้",
// default: null,
// unique: false,
// })
// current_holderId: string;
// @Column({
// nullable: true,
// length: 40,
// comment:
// "คนที่กำลังจะมาครอง ตอนปรับโครงสร้าง ถ้าเลือกให้ใครมาครอง ProfileId ของคนนั้นจะมาอยู่ในช่องนี้ รวมทั้งตอนเลือกตำแหน่งเพื่อบรรจุ แต่งตั้ง เลื่อน ย้าย ในระบบบรรจุแต่งตั้งด้วย",
// default: null,
// unique: false,
// })
// next_holderId: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "id keycloak", comment: "id keycloak",
@ -149,81 +117,135 @@ export class ProfileEmployee extends EntityBase {
}) })
salaryLevel: number | null; salaryLevel: number | null;
@OneToMany(() => EmployeePosMaster, (posMaster) => posMaster.current_holder) @Column({
nullable: true,
comment: "เชื้อชาติ",
length: 255,
default: null,
})
ethnicity: string;
@Column({
nullable: true,
comment: "ศาสนา",
length: 255,
default: null,
})
religion: string;
@Column({
nullable: true,
comment: "เบอร์โทร",
length: 255,
default: null,
})
telephoneNumber: string;
@Column({
nullable: true,
comment: "เพศ",
length: 40,
default: null,
})
genderId: string;
@ManyToOne(() => Gender, (v) => v.profileEmployee)
gender: Gender;
@Column({
nullable: true,
comment: "ความสัมพันธ์",
length: 40,
default: null,
})
relationshipId: string;
@ManyToOne(() => Relationship, (v) => v.profileEmployee)
relationship: Relationship;
@Column({
nullable: true,
comment: "กรุ๊ปเลือด",
length: 40,
default: null,
})
bloodGroupId: string;
@ManyToOne(() => BloodGroup, (v) => v.profileEmployee)
bloodGroup: BloodGroup;
@OneToMany(() => EmployeePosMaster, (v) => v.current_holder)
current_holders: EmployeePosMaster[]; current_holders: EmployeePosMaster[];
@OneToMany(() => EmployeePosMaster, (posMaster) => posMaster.next_holder) @OneToMany(() => EmployeePosMaster, (v) => v.next_holder)
next_holders: EmployeePosMaster[]; next_holders: EmployeePosMaster[];
@OneToMany(() => ProfileSalaryEmployee, (profileSalary) => profileSalary.profile) @OneToMany(() => ProfileSalaryEmployee, (v) => v.profile)
profileSalary: ProfileSalaryEmployee[]; profileSalary: ProfileSalaryEmployee[];
@OneToMany(() => ProfileDisciplineEmployee, (profileDiscipline) => profileDiscipline.profile) @OneToMany(() => ProfileDisciplineEmployee, (v) => v.profile)
profileDiscipline: ProfileDisciplineEmployee[]; profileDiscipline: ProfileDisciplineEmployee[];
// @OneToMany(() => ProfileCertificate, (profileCertificate) => profileCertificate.profile) @ManyToOne(() => EmployeePosLevel, (v) => v.profiles)
// profileCertificates: ProfileCertificate[];
// @OneToMany(() => ProfileEducation, (profileEducation) => profileEducation.profile)
// profileEducations: ProfileEducation[];
// @OneToMany(() => ProfileTraining, (profileTraining) => profileTraining.profile)
// profileTrainings: ProfileTraining[];
// @OneToMany(() => ProfileInsignia, (profileInsignia) => profileInsignia.profile)
// profileInsignias: ProfileInsignia[];
// @OneToMany(() => ProfileHonor, (profileHonor) => profileHonor.profile)
// profileHonors: ProfileHonor[];
// @OneToMany(() => ProfileAssessment, (profileAssessment) => profileAssessment.profile)
// profileAssessments: ProfileAssessment[];
// @OneToMany(() => ProfileLeave, (profileLeave) => profileLeave.profile)
// profileLeaves: ProfileLeave[];
// @OneToMany(() => ProfileAbility, (profileAbility) => profileAbility.profile)
// profileAbilities: ProfileAbility[];
// @OneToMany(() => ProfileDuty, (profileDuty) => profileDuty.profile)
// profileDutys: ProfileDuty[];
// @OneToMany(() => ProfileNopaid, (profileNopaid) => profileNopaid.profile)
// profileNopaids: ProfileNopaid[];
// @OneToMany(() => ProfileOther, (profileOther) => profileOther.profile)
// profileOthers: ProfileOther[];
@ManyToOne(() => EmployeePosLevel, (posLevel) => posLevel.profiles)
@JoinColumn({ name: "posLevelId" })
posLevel: EmployeePosLevel; posLevel: EmployeePosLevel;
@ManyToOne(() => EmployeePosType, (posType) => posType.profiles) @ManyToOne(() => EmployeePosType, (v) => v.profiles)
@JoinColumn({ name: "posTypeId" })
posType: EmployeePosType; posType: EmployeePosType;
@OneToMany(() => ProfileEmployeeHistory, (v) => v.profileEmployee)
histories: ProfileEmployeeHistory[];
}
@Entity("profileEmployeeHistory")
export class ProfileEmployeeHistory extends ProfileEmployee {
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง ProfileInformation",
default: null,
})
profileEmployeeId: string;
@ManyToOne(() => ProfileEmployee, (v) => v.histories, { onDelete: "CASCADE" })
profileEmployee: ProfileEmployee;
} }
export class CreateProfileEmployee { export class CreateProfileEmployee {
@Column()
prefix: string; prefix: string;
@Column()
firstName: string; firstName: string;
@Column()
lastName: string; lastName: string;
@Column()
citizenId: string;
@Column()
position: string; position: string;
isProbation: boolean | null;
@Column("uuid") dateRetire: Date | null;
birthDate: Date | null;
salaryLevel: number | null;
ethnicity: string | null;
religion: string | null;
telephoneNumber: string | null;
citizenId: string;
posLevelId: string | null; posLevelId: string | null;
@Column("uuid")
posTypeId: string | null; posTypeId: string | null;
genderId: string | null;
relationshipId: string | null;
bloodGroupId: string | null;
} }
export type UpdateProfileEmployee = Partial<CreateProfileEmployee>; export type UpdateProfileEmployee = {
prefix?: string | null;
firstName?: string | null;
lastName?: string | null;
position?: string | null;
isProbation?: boolean | null;
dateRetire?: Date | null;
birthDate?: Date | null;
salaryLevel?: number | null;
ethnicity?: string | null;
religion?: string | null;
telephoneNumber?: string | null;
citizenId?: string;
posLevelId?: string | null;
posTypeId?: string | null;
genderId?: string | null;
relationshipId?: string | null;
bloodGroupId?: string | null;
};

View file

@ -1,169 +0,0 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { Profile } from "./Profile";
import { BloodGroup } from "./BloodGroup";
import { Relationship } from "./Relationship";
import { Gender } from "./Gender";
@Entity("profileInformation")
export class ProfileInformation extends EntityBase {
@Column({
nullable: true,
comment: "เลขประจำตัวประชาชน",
default: null,
length: 13,
})
citizenId: string;
@Column({
nullable: true,
comment: "คำนำหน้าชื่อ",
length: 40,
default: null,
})
prefix: string;
@Column({
nullable: true,
comment: "ชื่อ",
length: 255,
default: null,
})
firstName: string;
@Column({
nullable: true,
comment: "นามสกุล",
length: 255,
default: null,
})
lastName: string;
@Column({
nullable: true,
type: "datetime",
comment: "วันเกิด",
default: null,
})
birthDate: Date;
@Column({
nullable: true,
comment: "เชื้อชาติ",
length: 255,
default: null,
})
ethnicity: string;
@Column({
nullable: true,
comment: "ศาสนา",
length: 255,
default: null,
})
religion: string;
@Column({
nullable: true,
comment: "เบอร์โทร",
length: 255,
default: null,
})
telephoneNumber: string;
@OneToMany(() => ProfileInformationHistory, (v) => v.profileInformation)
profileInformationHistory: ProfileInformationHistory[];
@Column({
nullable: true,
comment: "เพศ",
length: 40,
default: null,
})
genderId: string;
@ManyToOne(() => Gender, (v) => v.profileInformations)
@JoinColumn({ name: "genderId" })
gender: Gender;
@Column({
nullable: true,
comment: "ความสัมพันธ์",
length: 40,
default: null,
})
relationshipId: string;
@ManyToOne(() => Relationship, (v) => v.profileInformations)
@JoinColumn({ name: "relationshipId" })
relationship: Relationship;
@Column({
nullable: true,
comment: "กรุ๊ปเลือด",
length: 40,
default: null,
})
bloodGroupId: string;
@ManyToOne(() => BloodGroup, (v) => v.profileInformations)
@JoinColumn({ name: "bloodGroupId" })
bloodGroup: BloodGroup;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง Profile",
default: null,
})
profileId: string;
@ManyToOne(() => Profile, (v) => v.profileInformation)
@JoinColumn({ name: "profileId" })
profile: Profile;
}
export class CreateProfileInformation {
profileId: string | null;
citizenId: string | null;
prefix: string | null;
firstName: string | null;
lastName: string | null;
birthDate: Date | null;
ethnicity: string | null;
religion: string | null;
telephoneNumber: string | null;
genderId: string | null;
relationshipId: string | null;
bloodGroupId: string | null;
}
export type UpdateProfileInformation = {
citizenId?: string | null;
prefix?: string | null;
firstName?: string | null;
lastName?: string | null;
birthDate?: Date | null;
ethnicity?: string | null;
religion?: string | null;
telephoneNumber?: string | null;
genderId?: string | null;
relationshipId?: string | null;
bloodGroupId?: string | null;
};
@Entity("profileInformationHistory")
export class ProfileInformationHistory extends ProfileInformation {
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง ProfileInformation",
default: null,
})
profileInformationId: string;
@ManyToOne(() => ProfileInformation, (v) => v.profileInformationHistory, { onDelete: "CASCADE" })
@JoinColumn({ name: "profileInformationId" })
profileInformation: ProfileInformation;
}

View file

@ -1,7 +1,8 @@
import { Entity, Column, OneToMany } from "typeorm"; import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { ProfileInformation } from "./ProfileInformation"; import { Profile } from "./Profile";
import { ProfileEmployee } from "./ProfileEmployee";
@Entity("relationship") @Entity("relationship")
export class Relationship extends EntityBase { export class Relationship extends EntityBase {
@ -13,12 +14,14 @@ export class Relationship extends EntityBase {
}) })
name: string; name: string;
@OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.relationshipId) @OneToMany(() => Profile, (v) => v.relationship)
profileInformations: ProfileInformation[]; profile: Profile[];
@OneToMany(() => ProfileEmployee, (v) => v.relationship)
profileEmployee: ProfileEmployee[];
} }
export class CreateRelationship { export class CreateRelationship {
@Column()
name: string; name: string;
} }