ค้นหาทะเบียนประวัติ
This commit is contained in:
parent
14bc29b675
commit
5fc7aa0938
5 changed files with 207 additions and 55 deletions
|
|
@ -176,9 +176,9 @@ export class PositionController extends Controller {
|
|||
where: { posDictName: Like(`%${keyword}%`) },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
// if (!findPosDict) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
// }
|
||||
break;
|
||||
|
||||
case "positionField":
|
||||
|
|
@ -186,9 +186,9 @@ export class PositionController extends Controller {
|
|||
where: { posDictField: Like(`%${keyword}%`) },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
// if (!findPosDict) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
// }
|
||||
break;
|
||||
|
||||
case "positionType":
|
||||
|
|
@ -229,9 +229,9 @@ export class PositionController extends Controller {
|
|||
where: { posDictExecutiveField: Like(`%${keyword}%`) },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
// if (!findPosDict) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
// }
|
||||
break;
|
||||
|
||||
case "positionArea":
|
||||
|
|
@ -239,18 +239,18 @@ export class PositionController extends Controller {
|
|||
where: { posDictArea: Like(`%${keyword}%`) },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
// if (!findPosDict) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
// }
|
||||
break;
|
||||
|
||||
default:
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
// if (!findPosDict) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -812,37 +812,33 @@ export class PositionController extends Controller {
|
|||
// });
|
||||
|
||||
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder('posMaster')
|
||||
.leftJoinAndSelect('posMaster.orgRoot', 'orgRoot')
|
||||
.leftJoinAndSelect('posMaster.orgChild1', 'orgChild1')
|
||||
.leftJoinAndSelect('posMaster.orgChild2', 'orgChild2')
|
||||
.leftJoinAndSelect('posMaster.orgChild3', 'orgChild3')
|
||||
.leftJoinAndSelect('posMaster.orgChild4', 'orgChild4')
|
||||
.leftJoinAndSelect('posMaster.current_holder', 'current_holder')
|
||||
.leftJoinAndSelect('posMaster.next_holder', 'next_holder')
|
||||
.where(conditions)
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(current_holder.prefix, current_holder.firstName, current_holder.lastName) LIKE :keyword OR :keyword LIKE current_holder.prefix OR :keyword LIKE current_holder.firstName OR :keyword LIKE current_holder.lastName "
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
checkChildConditions
|
||||
)
|
||||
.andWhere(
|
||||
typeCondition
|
||||
);
|
||||
})
|
||||
)
|
||||
.orderBy('posMaster.posMasterOrder', 'ASC')
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
|
||||
.where(conditions)
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(current_holder.prefix, current_holder.firstName, current_holder.lastName) LIKE :keyword OR :keyword LIKE current_holder.prefix OR :keyword LIKE current_holder.firstName OR :keyword LIKE current_holder.lastName "
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(checkChildConditions)
|
||||
.andWhere(typeCondition);
|
||||
}),
|
||||
)
|
||||
.orderBy("posMaster.posMasterOrder", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const formattedData = await Promise.all(
|
||||
posMaster.map(async (posMaster) => {
|
||||
|
|
@ -855,14 +851,13 @@ export class PositionController extends Controller {
|
|||
|
||||
let profile: any;
|
||||
const chkRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: posMaster.orgRevisionId }
|
||||
})
|
||||
if(chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft){
|
||||
where: { id: posMaster.orgRevisionId },
|
||||
});
|
||||
if (chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft) {
|
||||
profile = await this.profileRepository.findOne({
|
||||
where: { id: String(posMaster.current_holderId) },
|
||||
});
|
||||
}
|
||||
else if(!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft){
|
||||
} else if (!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft) {
|
||||
profile = await this.profileRepository.findOne({
|
||||
where: { id: String(posMaster.next_holderId) },
|
||||
});
|
||||
|
|
@ -940,10 +935,8 @@ export class PositionController extends Controller {
|
|||
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
|
||||
orgShortname: shortName,
|
||||
isSit: posMaster.isSit,
|
||||
profilePosition:
|
||||
profile == null || profile.position == null ? null : profile.position,
|
||||
profilePostype:
|
||||
type == null || type.posTypeName == null ? null : type.posTypeName,
|
||||
profilePosition: profile == null || profile.position == null ? null : profile.position,
|
||||
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
|
||||
profilePoslevel:
|
||||
level == null || level.posLevelName == null ? null : level.posLevelName,
|
||||
positions: positions.map((position) => ({
|
||||
|
|
|
|||
|
|
@ -384,4 +384,106 @@ export class ProfileController extends Controller {
|
|||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลทะเบียนประวัติตาม keycloak
|
||||
*
|
||||
* @summary ORG_065 - ข้อมูลทะเบียนประวัติตาม keycloak (ADMIN) #70
|
||||
*
|
||||
*/
|
||||
@Get("keycloak/position")
|
||||
async getProfileByKeycloak(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
relations: ["posLevel", "posType"],
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
|
||||
}
|
||||
const _profile = {
|
||||
profileId: profile.id,
|
||||
prefix: profile.prefix,
|
||||
firstName: profile.firstName,
|
||||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
position: profile.position,
|
||||
posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName,
|
||||
posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank,
|
||||
posLevelId: profile.posLevel == null ? null : profile.posLevel.id,
|
||||
posTypeName: profile.posType == null ? null : profile.posType.posTypeName,
|
||||
posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank,
|
||||
posTypeId: profile.posType == null ? null : profile.posType.id,
|
||||
};
|
||||
try {
|
||||
return new HttpSuccess(_profile);
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API ค้นหาข้อมูลทะเบียนประวัติ
|
||||
*
|
||||
* @summary ORG_065 - ค้นหาข้อมูลทะเบียนประวัติ (ADMIN) #70
|
||||
*
|
||||
*/
|
||||
@Post("search-personal")
|
||||
async getProfileBySearchKeyword(
|
||||
@Body()
|
||||
body: {
|
||||
fieldName: string;
|
||||
keyword?: number;
|
||||
},
|
||||
) {
|
||||
try {
|
||||
let findProfile: any;
|
||||
switch (body.fieldName) {
|
||||
case "idcard":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { citizenId: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
|
||||
case "firstname":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { firstName: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
|
||||
case "lastname":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { lastName: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
findProfile = await this.profileRepository.find({
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
const mapDataProfile = await Promise.all(
|
||||
findProfile.map(async (item: Profile) => {
|
||||
return {
|
||||
id: item.id,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
idcard: item.citizenId,
|
||||
email: item.email,
|
||||
phone: item.phone,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess(mapDataProfile);
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,20 @@ export class Profile extends EntityBase {
|
|||
})
|
||||
posTypeId: string | null;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 255,
|
||||
comment: "อีเมล",
|
||||
})
|
||||
email: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 20,
|
||||
comment: "เบอร์โทร",
|
||||
})
|
||||
phone: string;
|
||||
|
||||
// @Column({
|
||||
// nullable: true,
|
||||
// length: 40,
|
||||
|
|
@ -79,6 +93,13 @@ export class Profile extends EntityBase {
|
|||
// unique: false,
|
||||
// })
|
||||
// next_holderId: string;
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "id keycloak",
|
||||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
keycloak: string;
|
||||
|
||||
@OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder)
|
||||
current_holders: PosMaster[];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableProfileAddKeycloak1708054669956 implements MigrationInterface {
|
||||
name = 'UpdateTableProfileAddKeycloak1708054669956'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`keycloak\` varchar(40) NULL COMMENT 'id keycloak'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` DROP FOREIGN KEY \`FK_de774e32853add3313ff44bd793\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` CHANGE \`posTypeId\` \`posTypeId\` varchar(40) NULL COMMENT 'ไอดีประเภทตำแหน่ง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` ADD CONSTRAINT \`FK_de774e32853add3313ff44bd793\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` DROP FOREIGN KEY \`FK_de774e32853add3313ff44bd793\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` CHANGE \`posTypeId\` \`posTypeId\` varchar(40) NULL COMMENT 'ไอดีประเภทตำแหน่'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` ADD CONSTRAINT \`FK_de774e32853add3313ff44bd793\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`keycloak\``);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableProfileAddEmail1708058097765 implements MigrationInterface {
|
||||
name = 'UpdateTableProfileAddEmail1708058097765'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`email\` varchar(255) NULL COMMENT 'อีเมล'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`phone\` varchar(20) NULL COMMENT 'เบอร์โทร'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`phone\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`email\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue