ทะเบียนประวัติเพิ่มส่งค่าตำแหน่ง
This commit is contained in:
parent
5c9e50ce36
commit
e87c7a85ab
2 changed files with 292 additions and 39 deletions
|
|
@ -1,21 +1,4 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { Controller, Get, Post, Route, Tags, Body, Path, SuccessResponse, Response } from "tsoa";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -528,8 +511,9 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
}
|
||||
|
||||
const findProfile = await AppDataSource.getRepository(Profile)
|
||||
.createQueryBuilder("current_holder")
|
||||
.leftJoinAndSelect("current_holder.positions", "positions")
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
.leftJoinAndSelect("current_holders.positions", "positions")
|
||||
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
||||
.where({ id: id })
|
||||
.getOne();
|
||||
|
|
@ -561,7 +545,18 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
|
||||
.posExecutiveName;
|
||||
const root =
|
||||
findProfile.current_holders == null ||
|
||||
findProfile.current_holders.length == 0 ||
|
||||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
? null
|
||||
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
||||
return new HttpSuccess({
|
||||
rootId: root == null ? null : root.id,
|
||||
root: root == null ? null : root.orgRootName,
|
||||
orgRootShortName: root == null ? null : root.orgRootShortName,
|
||||
orgRevisionId: findRevision.id,
|
||||
profileId: findProfile.id,
|
||||
type: "OFFICER",
|
||||
rank: findProfile.rank,
|
||||
prefix: findProfile.prefix,
|
||||
|
|
@ -583,9 +578,17 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
*/
|
||||
@Get("employee/{id}")
|
||||
async GetProfileEmployeeById(@Path() id: string) {
|
||||
const findRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
if (!findRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
|
||||
const findProfile = await AppDataSource.getRepository(ProfileEmployee)
|
||||
.createQueryBuilder("current_holder")
|
||||
.leftJoinAndSelect("current_holder.positions", "positions")
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
.leftJoinAndSelect("current_holders.positions", "positions")
|
||||
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
||||
.where({ id: id })
|
||||
.getOne();
|
||||
|
|
@ -593,7 +596,19 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
|
||||
}
|
||||
|
||||
const root =
|
||||
findProfile.current_holders == null ||
|
||||
findProfile.current_holders.length == 0 ||
|
||||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
? null
|
||||
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
||||
|
||||
return new HttpSuccess({
|
||||
rootId: root == null ? null : root.id,
|
||||
root: root == null ? null : root.orgRootName,
|
||||
orgRootShortName: root == null ? null : root.orgRootShortName,
|
||||
orgRevisionId: findRevision.id,
|
||||
profileId: findProfile.id,
|
||||
type: "OFFICER",
|
||||
rank: findProfile.rank,
|
||||
prefix: findProfile.prefix,
|
||||
|
|
@ -605,4 +620,132 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
posTypeId: findProfile.posTypeId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API หา user profile officer
|
||||
*
|
||||
* @summary หา user profile officer
|
||||
*
|
||||
*/
|
||||
@Get("officer/citizen/{id}")
|
||||
async GetProfileByCitizenId(@Path() id: string) {
|
||||
const findRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
if (!findRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
|
||||
const findProfile = await AppDataSource.getRepository(Profile)
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("current_holders.positions", "positions")
|
||||
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
||||
.where({ citizenId: id })
|
||||
.getOne();
|
||||
if (!findProfile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
|
||||
}
|
||||
|
||||
const posExecutive =
|
||||
findProfile.current_holders == null ||
|
||||
findProfile.current_holders.length == 0 ||
|
||||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
|
||||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions ==
|
||||
null ||
|
||||
findProfile.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions
|
||||
.length == 0 ||
|
||||
findProfile.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true) == null ||
|
||||
findProfile.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
|
||||
null ||
|
||||
findProfile.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
|
||||
?.posExecutiveName == null
|
||||
? null
|
||||
: findProfile.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
|
||||
.posExecutiveName;
|
||||
const root =
|
||||
findProfile.current_holders == null ||
|
||||
findProfile.current_holders.length == 0 ||
|
||||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
? null
|
||||
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
||||
return new HttpSuccess({
|
||||
rootId: root == null ? null : root.id,
|
||||
root: root == null ? null : root.orgRootName,
|
||||
orgRootShortName: root == null ? null : root.orgRootShortName,
|
||||
orgRevisionId: findRevision.id,
|
||||
profileId: findProfile.id,
|
||||
type: "OFFICER",
|
||||
rank: findProfile.rank,
|
||||
prefix: findProfile.prefix,
|
||||
firstName: findProfile.firstName,
|
||||
lastName: findProfile.lastName,
|
||||
citizenId: findProfile.citizenId,
|
||||
position: findProfile.position,
|
||||
posExecutive: posExecutive,
|
||||
posLevelId: findProfile.posLevelId,
|
||||
posTypeId: findProfile.posTypeId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API หา user profile employee
|
||||
*
|
||||
* @summary หา user profile employee
|
||||
*
|
||||
*/
|
||||
@Get("employee/citizen/{id}")
|
||||
async GetProfileEmployeeByCitizenId(@Path() id: string) {
|
||||
const findRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
if (!findRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
|
||||
const findProfile = await AppDataSource.getRepository(ProfileEmployee)
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("current_holders.positions", "positions")
|
||||
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
||||
.where({ citizenId: id })
|
||||
.getOne();
|
||||
if (!findProfile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
|
||||
}
|
||||
|
||||
const root =
|
||||
findProfile.current_holders == null ||
|
||||
findProfile.current_holders.length == 0 ||
|
||||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
? null
|
||||
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
||||
|
||||
return new HttpSuccess({
|
||||
rootId: root == null ? null : root.id,
|
||||
root: root == null ? null : root.orgRootName,
|
||||
orgRootShortName: root == null ? null : root.orgRootShortName,
|
||||
orgRevisionId: findRevision.id,
|
||||
profileId: findProfile.id,
|
||||
type: "EMPLOYEE",
|
||||
rank: findProfile.rank,
|
||||
prefix: findProfile.prefix,
|
||||
firstName: findProfile.firstName,
|
||||
lastName: findProfile.lastName,
|
||||
citizenId: findProfile.citizenId,
|
||||
position: findProfile.position,
|
||||
posLevelId: findProfile.posLevelId,
|
||||
posTypeId: findProfile.posTypeId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue