ค้นหาทะเบียนประวัติ
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}%`) },
|
where: { posDictName: Like(`%${keyword}%`) },
|
||||||
relations: ["posType", "posLevel", "posExecutive"],
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
});
|
});
|
||||||
if (!findPosDict) {
|
// if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "positionField":
|
case "positionField":
|
||||||
|
|
@ -186,9 +186,9 @@ export class PositionController extends Controller {
|
||||||
where: { posDictField: Like(`%${keyword}%`) },
|
where: { posDictField: Like(`%${keyword}%`) },
|
||||||
relations: ["posType", "posLevel", "posExecutive"],
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
});
|
});
|
||||||
if (!findPosDict) {
|
// if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "positionType":
|
case "positionType":
|
||||||
|
|
@ -229,9 +229,9 @@ export class PositionController extends Controller {
|
||||||
where: { posDictExecutiveField: Like(`%${keyword}%`) },
|
where: { posDictExecutiveField: Like(`%${keyword}%`) },
|
||||||
relations: ["posType", "posLevel", "posExecutive"],
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
});
|
});
|
||||||
if (!findPosDict) {
|
// if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "positionArea":
|
case "positionArea":
|
||||||
|
|
@ -239,18 +239,18 @@ export class PositionController extends Controller {
|
||||||
where: { posDictArea: Like(`%${keyword}%`) },
|
where: { posDictArea: Like(`%${keyword}%`) },
|
||||||
relations: ["posType", "posLevel", "posExecutive"],
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
});
|
});
|
||||||
if (!findPosDict) {
|
// if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
findPosDict = await this.posDictRepository.find({
|
findPosDict = await this.posDictRepository.find({
|
||||||
relations: ["posType", "posLevel", "posExecutive"],
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
});
|
});
|
||||||
if (!findPosDict) {
|
// if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -812,37 +812,33 @@ export class PositionController extends Controller {
|
||||||
// });
|
// });
|
||||||
|
|
||||||
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||||
.createQueryBuilder('posMaster')
|
.createQueryBuilder("posMaster")
|
||||||
.leftJoinAndSelect('posMaster.orgRoot', 'orgRoot')
|
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
|
||||||
.leftJoinAndSelect('posMaster.orgChild1', 'orgChild1')
|
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
|
||||||
.leftJoinAndSelect('posMaster.orgChild2', 'orgChild2')
|
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
|
||||||
.leftJoinAndSelect('posMaster.orgChild3', 'orgChild3')
|
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
|
||||||
.leftJoinAndSelect('posMaster.orgChild4', 'orgChild4')
|
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
||||||
.leftJoinAndSelect('posMaster.current_holder', 'current_holder')
|
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||||
.leftJoinAndSelect('posMaster.next_holder', 'next_holder')
|
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
|
||||||
.where(conditions)
|
.where(conditions)
|
||||||
.orWhere(
|
.orWhere(
|
||||||
new Brackets((qb) => {
|
new Brackets((qb) => {
|
||||||
qb.where(
|
qb.where(
|
||||||
body.keyword != null && body.keyword != ""
|
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 "
|
? "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",
|
: "1=1",
|
||||||
{
|
{
|
||||||
keyword: `%${body.keyword}%`,
|
keyword: `%${body.keyword}%`,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.andWhere(
|
.andWhere(checkChildConditions)
|
||||||
checkChildConditions
|
.andWhere(typeCondition);
|
||||||
)
|
}),
|
||||||
.andWhere(
|
)
|
||||||
typeCondition
|
.orderBy("posMaster.posMasterOrder", "ASC")
|
||||||
);
|
.skip((body.page - 1) * body.pageSize)
|
||||||
})
|
.take(body.pageSize)
|
||||||
)
|
.getManyAndCount();
|
||||||
.orderBy('posMaster.posMasterOrder', 'ASC')
|
|
||||||
.skip((body.page - 1) * body.pageSize)
|
|
||||||
.take(body.pageSize)
|
|
||||||
.getManyAndCount();
|
|
||||||
|
|
||||||
const formattedData = await Promise.all(
|
const formattedData = await Promise.all(
|
||||||
posMaster.map(async (posMaster) => {
|
posMaster.map(async (posMaster) => {
|
||||||
|
|
@ -855,14 +851,13 @@ export class PositionController extends Controller {
|
||||||
|
|
||||||
let profile: any;
|
let profile: any;
|
||||||
const chkRevision = await this.orgRevisionRepository.findOne({
|
const chkRevision = await this.orgRevisionRepository.findOne({
|
||||||
where: { id: posMaster.orgRevisionId }
|
where: { id: posMaster.orgRevisionId },
|
||||||
})
|
});
|
||||||
if(chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft){
|
if (chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft) {
|
||||||
profile = await this.profileRepository.findOne({
|
profile = await this.profileRepository.findOne({
|
||||||
where: { id: String(posMaster.current_holderId) },
|
where: { id: String(posMaster.current_holderId) },
|
||||||
});
|
});
|
||||||
}
|
} else if (!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft) {
|
||||||
else if(!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft){
|
|
||||||
profile = await this.profileRepository.findOne({
|
profile = await this.profileRepository.findOne({
|
||||||
where: { id: String(posMaster.next_holderId) },
|
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}`,
|
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
|
||||||
orgShortname: shortName,
|
orgShortname: shortName,
|
||||||
isSit: posMaster.isSit,
|
isSit: posMaster.isSit,
|
||||||
profilePosition:
|
profilePosition: profile == null || profile.position == null ? null : profile.position,
|
||||||
profile == null || profile.position == null ? null : profile.position,
|
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
|
||||||
profilePostype:
|
|
||||||
type == null || type.posTypeName == null ? null : type.posTypeName,
|
|
||||||
profilePoslevel:
|
profilePoslevel:
|
||||||
level == null || level.posLevelName == null ? null : level.posLevelName,
|
level == null || level.posLevelName == null ? null : level.posLevelName,
|
||||||
positions: positions.map((position) => ({
|
positions: positions.map((position) => ({
|
||||||
|
|
|
||||||
|
|
@ -384,4 +384,106 @@ export class ProfileController extends Controller {
|
||||||
return error;
|
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;
|
posTypeId: string | null;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 255,
|
||||||
|
comment: "อีเมล",
|
||||||
|
})
|
||||||
|
email: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 20,
|
||||||
|
comment: "เบอร์โทร",
|
||||||
|
})
|
||||||
|
phone: string;
|
||||||
|
|
||||||
// @Column({
|
// @Column({
|
||||||
// nullable: true,
|
// nullable: true,
|
||||||
// length: 40,
|
// length: 40,
|
||||||
|
|
@ -79,6 +93,13 @@ export class Profile extends EntityBase {
|
||||||
// unique: false,
|
// unique: false,
|
||||||
// })
|
// })
|
||||||
// next_holderId: string;
|
// next_holderId: string;
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "id keycloak",
|
||||||
|
length: 40,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
keycloak: string;
|
||||||
|
|
||||||
@OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder)
|
@OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder)
|
||||||
current_holders: PosMaster[];
|
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