Merge branch 'develop'
This commit is contained in:
commit
07d89d835c
39 changed files with 1788 additions and 5258 deletions
|
|
@ -13,12 +13,16 @@ import { OrganizationController } from "./controllers/OrganizationController";
|
|||
import logMiddleware from "./middlewares/logs";
|
||||
import { CommandController } from "./controllers/CommandController";
|
||||
import { ProfileSalaryController } from "./controllers/ProfileSalaryController";
|
||||
import { DateSerializer } from "./interfaces/date-serializer";
|
||||
|
||||
import { initWebSocket } from "./services/webSocket";
|
||||
|
||||
async function main() {
|
||||
await AppDataSource.initialize();
|
||||
|
||||
// Setup custom Date serialization for local timezone
|
||||
DateSerializer.setupDateSerialization();
|
||||
|
||||
initWebSocket();
|
||||
|
||||
const app = express();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import { In } from "typeorm";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ApiName } from "../entities/ApiName";
|
||||
import { ApiHistory } from "../entities/ApiHistory";
|
||||
|
||||
const jwt = require("jsonwebtoken");
|
||||
@Route("api/v1/org/apiKey")
|
||||
@Tags("ApiKey")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -32,6 +34,32 @@ export class ApiKeyController extends Controller {
|
|||
private apiNameRepository = AppDataSource.getRepository(ApiName);
|
||||
private apiHistoryRepository = AppDataSource.getRepository(ApiHistory);
|
||||
|
||||
/**
|
||||
* API ตรวจสอบและถอดรหัส JWT token
|
||||
*
|
||||
* @summary ตรวจสอบ JWT API Key
|
||||
*/
|
||||
@Post("verify")
|
||||
async verifyApiKey(@Body() requestBody: { token: string }) {
|
||||
try {
|
||||
const jwtSecret = process.env.JWT_SECRET || "your-default-secret-key";
|
||||
console.log("JWT_SECRET from env:", process.env.JWT_SECRET ? "exists" : "not found");
|
||||
console.log("Using secret:", jwtSecret);
|
||||
|
||||
const decoded = jwt.verify(requestBody.token, jwtSecret);
|
||||
return new HttpSuccess({
|
||||
valid: true,
|
||||
data: decoded,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("JWT Verification Error:", error.message);
|
||||
return new HttpSuccess({
|
||||
valid: false,
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API สร้าง Api Key
|
||||
*
|
||||
|
|
@ -52,8 +80,33 @@ export class ApiKeyController extends Controller {
|
|||
const apiName = await this.apiNameRepository.find({
|
||||
where: { id: In(requestBody.apiId) },
|
||||
});
|
||||
|
||||
const apiKey = Object.assign(new ApiKey(), requestBody);
|
||||
apiKey.keyApi = require("crypto").randomBytes(64).toString("base64");
|
||||
|
||||
// Create JWT token with embedded data
|
||||
const tokenPayload = {
|
||||
keyId: apiKey.id || require("crypto").randomUUID(),
|
||||
name: apiKey.name,
|
||||
accessType: apiKey.accessType,
|
||||
dnaRootId: apiKey.dnaRootId,
|
||||
dnaChild1Id: apiKey.dnaChild1Id,
|
||||
dnaChild2Id: apiKey.dnaChild2Id,
|
||||
dnaChild3Id: apiKey.dnaChild3Id,
|
||||
dnaChild4Id: apiKey.dnaChild4Id,
|
||||
apiIds: requestBody.apiId,
|
||||
createdBy: request.user.sub,
|
||||
createdAt: new Date().toISOString(),
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
};
|
||||
|
||||
// Sign JWT with secret (you should use environment variable for the secret)
|
||||
const jwtSecret = process.env.JWT_SECRET || "your-default-secret-key";
|
||||
|
||||
const jwtToken = jwt.sign(tokenPayload, jwtSecret, {
|
||||
expiresIn: "365d", // 1 year expiration
|
||||
});
|
||||
|
||||
apiKey.keyApi = jwtToken;
|
||||
apiKey.apiNames = apiName;
|
||||
apiKey.createdUserId = request.user.sub;
|
||||
apiKey.createdFullName = request.user.name;
|
||||
|
|
@ -104,6 +157,12 @@ export class ApiKeyController extends Controller {
|
|||
createdUserId: _data.createdUserId,
|
||||
createdFullName: _data.createdFullName,
|
||||
name: _data.name,
|
||||
accessType: _data.accessType,
|
||||
dnaRootId: _data.dnaRootId,
|
||||
dnaChild1Id: _data.dnaChild1Id,
|
||||
dnaChild2Id: _data.dnaChild2Id,
|
||||
dnaChild3Id: _data.dnaChild3Id,
|
||||
dnaChild4Id: _data.dnaChild4Id,
|
||||
apiNames: _data.apiNames.map((x) => ({
|
||||
id: x.id,
|
||||
name: x.name,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Query,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
|
|
@ -36,8 +37,21 @@ export class AuthRoleController extends Controller {
|
|||
private redis = require("redis");
|
||||
|
||||
@Get("list")
|
||||
public async listAuthRole() {
|
||||
const getList = await this.authRoleRepo.find();
|
||||
public async listAuthRole(
|
||||
@Request() req: RequestWithUser,
|
||||
@Query("isAdminVisibled") isAdminVisibled : string = "false",
|
||||
) {
|
||||
let condition: any = {};
|
||||
if(isAdminVisibled.toLowerCase() === "true"){
|
||||
condition = { isAdminVisibled: true };
|
||||
}else{
|
||||
condition = {};
|
||||
}
|
||||
const getList = await this.authRoleRepo.find(
|
||||
{
|
||||
where: condition,
|
||||
}
|
||||
);
|
||||
// if (!getList || getList.length === 0) {
|
||||
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
|
|
@ -161,6 +175,7 @@ export class AuthRoleController extends Controller {
|
|||
body: {
|
||||
roleName: string;
|
||||
roleDescription: string;
|
||||
isAdminVisibled?: boolean;
|
||||
authRoleAttrs: Array<{
|
||||
// id: string;
|
||||
authSysId: string;
|
||||
|
|
@ -187,6 +202,7 @@ export class AuthRoleController extends Controller {
|
|||
}));
|
||||
|
||||
Object.assign(record, {
|
||||
isAdminVisibled: body.isAdminVisibled?body.isAdminVisibled:false,
|
||||
roleName: body.roleName,
|
||||
roleDescription: body.roleDescription,
|
||||
lastUpdateFullName: req.user.name,
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ import {
|
|||
getUserByUsername,
|
||||
getRoleMappings,
|
||||
removeUserRoles,
|
||||
getToken,
|
||||
} from "../keycloak";
|
||||
import { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation";
|
||||
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
|
||||
|
|
@ -1476,24 +1477,7 @@ export class CommandController extends Controller {
|
|||
}
|
||||
// @Get("XXX")
|
||||
async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) {
|
||||
let body = {
|
||||
client_id: "gettoken",
|
||||
client_secret: process.env.AUTH_ACCOUNT_SECRET,
|
||||
grant_type: "client_credentials",
|
||||
};
|
||||
const postData = querystring.stringify(body);
|
||||
const response = await axios.post(
|
||||
`${process.env.KC_URL}/realms/${process.env.KC_REALMS}/protocol/openid-connect/token`,
|
||||
postData,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
},
|
||||
);
|
||||
const adminToken = response.data.access_token;
|
||||
// const adminToken = request.headers["authorization"]?.replace("Bearer ", "");
|
||||
const adminToken = await getToken() ?? "";
|
||||
const today = new Date();
|
||||
today.setUTCHours(0, 0, 0, 0);
|
||||
let type: string = "OFFICER";
|
||||
|
|
@ -1666,32 +1650,30 @@ export class CommandController extends Controller {
|
|||
}
|
||||
|
||||
async posMasterRetire(profileId: string, type: string, _Date: Date) {
|
||||
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||
const revisionIsCurrent = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
if (orgRevision) {
|
||||
if (revisionIsCurrent) {
|
||||
let _posMaster: any = null;
|
||||
let _position: any = null;
|
||||
if (type == "OFFICER") {
|
||||
_posMaster = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgRevisionId: orgRevision.id,
|
||||
orgRevisionId: revisionIsCurrent.id,
|
||||
current_holderId: profileId,
|
||||
},
|
||||
});
|
||||
if (_posMaster) {
|
||||
_position = await this.positionRepository.findOne({
|
||||
where: {
|
||||
await this.positionRepository.update(
|
||||
{
|
||||
posMasterId: _posMaster.id,
|
||||
positionIsSelected: true,
|
||||
},
|
||||
});
|
||||
if (_position) {
|
||||
_position.positionIsSelected = false;
|
||||
_position.lastUpdateFullName = "System Administrator";
|
||||
_position.lastUpdatedAt = _Date;
|
||||
await this.positionRepository.save(_position);
|
||||
}
|
||||
{
|
||||
positionIsSelected: false,
|
||||
lastUpdateFullName: "System Administrator",
|
||||
lastUpdatedAt: _Date,
|
||||
}
|
||||
);
|
||||
_posMaster.isSit = false;
|
||||
_posMaster.current_holderId = null;
|
||||
_posMaster.lastUpdateFullName = "System Administrator";
|
||||
|
|
@ -1699,26 +1681,57 @@ export class CommandController extends Controller {
|
|||
await this.posMasterRepository.save(_posMaster);
|
||||
await CreatePosMasterHistoryOfficer(_posMaster.id, null);
|
||||
}
|
||||
const revisionIsDraft = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true },
|
||||
});
|
||||
if (revisionIsDraft) {
|
||||
_posMaster = null;
|
||||
_posMaster = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgRevisionId: revisionIsDraft.id,
|
||||
next_holderId: profileId,
|
||||
},
|
||||
});
|
||||
if (_posMaster) {
|
||||
await this.positionRepository.update(
|
||||
{
|
||||
posMasterId: _posMaster.id,
|
||||
positionIsSelected: true,
|
||||
},
|
||||
{
|
||||
positionIsSelected: false,
|
||||
lastUpdateFullName: "System Administrator",
|
||||
lastUpdatedAt: _Date,
|
||||
}
|
||||
);
|
||||
_posMaster.isSit = false;
|
||||
_posMaster.next_holderId = null;
|
||||
_posMaster.lastUpdateFullName = "System Administrator";
|
||||
_posMaster.lastUpdatedAt = _Date;
|
||||
await this.posMasterRepository.save(_posMaster);
|
||||
await CreatePosMasterHistoryOfficer(_posMaster.id, null);
|
||||
}
|
||||
// console.log("clear posMaster & position 'Draf' success")
|
||||
}
|
||||
} else if (type == "EMPLOYEE") {
|
||||
_posMaster = await this.employeePosMasterRepository.findOne({
|
||||
where: {
|
||||
orgRevisionId: orgRevision.id,
|
||||
orgRevisionId: revisionIsCurrent.id,
|
||||
current_holderId: profileId,
|
||||
},
|
||||
});
|
||||
if (_posMaster) {
|
||||
_position = await this.employeePositionRepository.findOne({
|
||||
where: {
|
||||
await this.employeePositionRepository.update(
|
||||
{
|
||||
posMasterId: _posMaster.id,
|
||||
positionIsSelected: true,
|
||||
},
|
||||
});
|
||||
if (_position) {
|
||||
_position.positionIsSelected = false;
|
||||
_position.lastUpdateFullName = "System Administrator";
|
||||
_position.lastUpdatedAt = _Date;
|
||||
await this.employeePositionRepository.save(_position);
|
||||
}
|
||||
{
|
||||
positionIsSelected: false,
|
||||
lastUpdateFullName: "System Administrator",
|
||||
lastUpdatedAt: _Date,
|
||||
}
|
||||
);
|
||||
_posMaster.isSit = false;
|
||||
_posMaster.current_holderId = null;
|
||||
_posMaster.lastUpdateFullName = "System Administrator";
|
||||
|
|
@ -1727,6 +1740,7 @@ export class CommandController extends Controller {
|
|||
await CreatePosMasterHistoryEmployee(_posMaster.id, null);
|
||||
}
|
||||
}
|
||||
// console.log("clear posMaster & position 'Current' success")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1006,6 +1006,7 @@ export class EmployeePositionController extends Controller {
|
|||
*/
|
||||
@Post("master/list")
|
||||
async listEmp(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
id: string;
|
||||
|
|
@ -1026,7 +1027,7 @@ export class EmployeePositionController extends Controller {
|
|||
let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
|
||||
let _data = await new permission().PermissionOrgList(request, "SYS_ORG_EMP");
|
||||
if (body.type === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.id,
|
||||
|
|
@ -1139,6 +1140,56 @@ export class EmployeePositionController extends Controller {
|
|||
.leftJoinAndSelect("positions.posType", "posType")
|
||||
.leftJoinAndSelect("positions.posLevel", "posLevel")
|
||||
.where(conditions)
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null
|
||||
? _data.root[0] != null
|
||||
? `posMaster.orgRootId IN (:...root)`
|
||||
: `posMaster.orgRootId is null`
|
||||
: "1=1",
|
||||
{
|
||||
root: _data.root,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child1 != undefined && _data.child1 != null
|
||||
? _data.child1[0] != null
|
||||
? `posMaster.orgChild1Id IN (:...child1)`
|
||||
: `posMaster.orgChild1Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child1: _data.child1,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child2 != undefined && _data.child2 != null
|
||||
? _data.child2[0] != null
|
||||
? `posMaster.orgChild2Id IN (:...child2)`
|
||||
: `posMaster.orgChild2Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child2: _data.child2,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child3 != undefined && _data.child3 != null
|
||||
? _data.child3[0] != null
|
||||
? `posMaster.orgChild3Id IN (:...child3)`
|
||||
: `posMaster.orgChild3Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child3: _data.child3,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child4 != undefined && _data.child4 != null
|
||||
? _data.child4[0] != null
|
||||
? `posMaster.orgChild4Id IN (:...child4)`
|
||||
: `posMaster.orgChild4Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child4: _data.child4,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.andWhere(
|
||||
|
|
@ -1330,6 +1381,40 @@ export class EmployeePositionController extends Controller {
|
|||
};
|
||||
}),
|
||||
);
|
||||
|
||||
if(_data.privilege === 'NORMAL'|| _data.privilege === 'PARENT'|| _data.privilege === 'CHILD'){ //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า
|
||||
const nextChildMap:any = { //เอาไวเช็ค CHILD ถัดไป
|
||||
0: _data.child1,
|
||||
1: _data.child2,
|
||||
2: _data.child3,
|
||||
3: _data.child4,
|
||||
};
|
||||
const childValue = nextChildMap[body.type];
|
||||
if(_data.privilege === 'NORMAL'){
|
||||
if (Array.isArray(childValue) && childValue.some(item => item != null)) {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
}else if(_data.privilege === 'PARENT'){
|
||||
if (body.type == 0){
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
} else if (_data.privilege === 'CHILD') {
|
||||
const higherChildChecks = [
|
||||
{ type: [0], child: _data.child1, next: _data.child2 },
|
||||
{ type: [0, 1], child: _data.child2, next: _data.child3 },
|
||||
{ type: [0, 1, 2], child: _data.child3, next: _data.child4 },
|
||||
{ type: [0, 1, 2, 3], child: _data.child4, next: true },
|
||||
];
|
||||
|
||||
for (const check of higherChildChecks) {
|
||||
if (Array.isArray(check.child) && check.next == null) {
|
||||
if (check.type.includes(body.type)) {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -754,6 +754,7 @@ export class EmployeeTempPositionController extends Controller {
|
|||
*/
|
||||
@Post("master/list")
|
||||
async listEmp(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
id: string;
|
||||
|
|
@ -774,7 +775,7 @@ export class EmployeeTempPositionController extends Controller {
|
|||
let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
|
||||
let _data = await new permission().PermissionOrgList(request, "SYS_ORG_TEMP");
|
||||
if (body.type === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.id,
|
||||
|
|
@ -887,6 +888,56 @@ export class EmployeeTempPositionController extends Controller {
|
|||
.leftJoinAndSelect("positions.posType", "posType")
|
||||
.leftJoinAndSelect("positions.posLevel", "posLevel")
|
||||
.where(conditions)
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null
|
||||
? _data.root[0] != null
|
||||
? `posMaster.orgRootId IN (:...root)`
|
||||
: `posMaster.orgRootId is null`
|
||||
: "1=1",
|
||||
{
|
||||
root: _data.root,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child1 != undefined && _data.child1 != null
|
||||
? _data.child1[0] != null
|
||||
? `posMaster.orgChild1Id IN (:...child1)`
|
||||
: `posMaster.orgChild1Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child1: _data.child1,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child2 != undefined && _data.child2 != null
|
||||
? _data.child2[0] != null
|
||||
? `posMaster.orgChild2Id IN (:...child2)`
|
||||
: `posMaster.orgChild2Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child2: _data.child2,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child3 != undefined && _data.child3 != null
|
||||
? _data.child3[0] != null
|
||||
? `posMaster.orgChild3Id IN (:...child3)`
|
||||
: `posMaster.orgChild3Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child3: _data.child3,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child4 != undefined && _data.child4 != null
|
||||
? _data.child4[0] != null
|
||||
? `posMaster.orgChild4Id IN (:...child4)`
|
||||
: `posMaster.orgChild4Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child4: _data.child4,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.andWhere(
|
||||
|
|
@ -1078,6 +1129,39 @@ export class EmployeeTempPositionController extends Controller {
|
|||
};
|
||||
}),
|
||||
);
|
||||
if(_data.privilege === 'NORMAL'|| _data.privilege === 'PARENT'|| _data.privilege === 'CHILD'){ //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า
|
||||
const nextChildMap:any = { //เอาไวเช็ค CHILD ถัดไป
|
||||
0: _data.child1,
|
||||
1: _data.child2,
|
||||
2: _data.child3,
|
||||
3: _data.child4,
|
||||
};
|
||||
const childValue = nextChildMap[body.type];
|
||||
if(_data.privilege === 'NORMAL'){
|
||||
if (Array.isArray(childValue) && childValue.some(item => item != null)) {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
}else if(_data.privilege === 'PARENT'){
|
||||
if (body.type == 0){
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
} else if (_data.privilege === 'CHILD') {
|
||||
const higherChildChecks = [
|
||||
{ type: [0], child: _data.child1, next: _data.child2 },
|
||||
{ type: [0, 1], child: _data.child2, next: _data.child3 },
|
||||
{ type: [0, 1, 2], child: _data.child3, next: _data.child4 },
|
||||
{ type: [0, 1, 2, 3], child: _data.child4, next: true },
|
||||
];
|
||||
|
||||
for (const check of higherChildChecks) {
|
||||
if (Array.isArray(check.child) && check.next == null) {
|
||||
if (check.type.includes(body.type)) {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
}
|
||||
|
||||
|
|
@ -1958,6 +2042,7 @@ export class EmployeeTempPositionController extends Controller {
|
|||
},
|
||||
relations: [
|
||||
"positions",
|
||||
"positions.posType",
|
||||
"orgRevision",
|
||||
"orgRoot",
|
||||
"orgChild1",
|
||||
|
|
@ -1993,6 +2078,7 @@ export class EmployeeTempPositionController extends Controller {
|
|||
profile.posTypeId = position?.posTypeId ?? _null;
|
||||
profile.position = position?.positionName ?? _null;
|
||||
profile.employeeOc = Org ?? _null;
|
||||
profile.positionEmployeeGroupId = position?.posType?.posTypeName ?? _null;
|
||||
profile.positionEmployeePositionId = position?.positionName ?? _null;
|
||||
await this.profileRepository.save(profile);
|
||||
}
|
||||
|
|
@ -2029,22 +2115,22 @@ export class EmployeeTempPositionController extends Controller {
|
|||
if (!dataMaster) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||
}
|
||||
if (dataMaster.current_holderId != null) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: {
|
||||
id: dataMaster.current_holderId,
|
||||
},
|
||||
});
|
||||
const _null: any = null;
|
||||
if (profile != null) {
|
||||
profile.posLevelId = _null;
|
||||
profile.posTypeId = _null;
|
||||
profile.position = _null;
|
||||
profile.employeeOc = _null;
|
||||
profile.positionEmployeePositionId = _null;
|
||||
await this.profileRepository.save(profile);
|
||||
}
|
||||
}
|
||||
// if (dataMaster.current_holderId != null) {
|
||||
// const profile = await this.profileRepository.findOne({
|
||||
// where: {
|
||||
// id: dataMaster.current_holderId,
|
||||
// },
|
||||
// });
|
||||
// const _null: any = null;
|
||||
// if (profile != null) {
|
||||
// profile.posLevelId = _null;
|
||||
// profile.posTypeId = _null;
|
||||
// profile.position = _null;
|
||||
// profile.employeeOc = _null;
|
||||
// profile.positionEmployeePositionId = _null;
|
||||
// await this.profileRepository.save(profile);
|
||||
// }
|
||||
// }
|
||||
|
||||
await this.employeeTempPosMasterRepository.update(id, {
|
||||
isSit: false,
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ export class ExRetirementController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถขอ Token ได้");
|
||||
}
|
||||
|
||||
const scope = requestBody.type === "officer" ? "getOfficerRetireData" : "";
|
||||
// const scope = requestBody.type === "officer" ? "getOfficerRetireData" : "";
|
||||
const scope = "getOfficerRetireData";
|
||||
const startRecord = requestBody.page !== 1 ? (requestBody.page - 1) * 25 : 0;
|
||||
|
||||
const formData = new FormData();
|
||||
|
|
@ -78,6 +79,7 @@ export class ExRetirementController extends Controller {
|
|||
formData.append("citizenID", requestBody.citizenID);
|
||||
formData.append("firstNameTH", requestBody.firstNameTH);
|
||||
formData.append("lastNameTH", requestBody.lastNameTH);
|
||||
formData.append("officerTypeID", requestBody.type === "officer" ? "1" : "2");
|
||||
|
||||
const res = await axios.post(API_URL_BANGKOK + "/getData", formData, {
|
||||
headers: {
|
||||
|
|
@ -96,6 +98,48 @@ export class ExRetirementController extends Controller {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Get("/document/{documentId}")
|
||||
async getDocument(@Path("documentId") officerDocumentID: string, @Request() req: any) {
|
||||
let retryCount = 0;
|
||||
const maxRetries = 2;
|
||||
while (retryCount < maxRetries) {
|
||||
try {
|
||||
const token = await getToken(clientId, clientSecret);
|
||||
if (!token) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถขอ Token ได้");
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("scope", "getOfficerRetireFile");
|
||||
formData.append("officerDocumentID", officerDocumentID);
|
||||
|
||||
const res = await axios.post(API_URL_BANGKOK + "/getData", formData, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
responseType: "arraybuffer",
|
||||
});
|
||||
|
||||
if (!req.res.headersSent && !req.res.destroyed) {
|
||||
// Set response headers
|
||||
req.res.setHeader("Content-Type", "application/pdf");
|
||||
req.res.setHeader("Content-Disposition", `inline; filename="${officerDocumentID}.pdf"`);
|
||||
req.res.setHeader("Content-Length", res.data.byteLength.toString());
|
||||
|
||||
req.res.end(Buffer.from(res.data));
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.response?.status === 500 && retryCount < maxRetries - 1) {
|
||||
TokenCache.delete(`${clientId}:${clientSecret}`);
|
||||
retryCount++;
|
||||
continue;
|
||||
}
|
||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถติดต่อ API ได้");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getToken(ClientID: string, ClientSecret: string): Promise<string> {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1218,6 +1218,7 @@ export class OrganizationController extends Controller {
|
|||
"orgRoot.SECTION_CODE",
|
||||
"orgRoot.JOB_CODE",
|
||||
"orgRoot.responsibility",
|
||||
"orgRoot.ancestorDNA",
|
||||
])
|
||||
.orderBy("orgRoot.orgRootOrder", "ASC")
|
||||
.getMany();
|
||||
|
|
@ -1246,6 +1247,7 @@ export class OrganizationController extends Controller {
|
|||
"orgChild1.SECTION_CODE",
|
||||
"orgChild1.JOB_CODE",
|
||||
"orgChild1.responsibility",
|
||||
"orgChild1.ancestorDNA",
|
||||
])
|
||||
.orderBy("orgChild1.orgChild1Order", "ASC")
|
||||
.getMany()
|
||||
|
|
@ -1275,6 +1277,7 @@ export class OrganizationController extends Controller {
|
|||
"orgChild2.JOB_CODE",
|
||||
"orgChild2.orgChild1Id",
|
||||
"orgChild2.responsibility",
|
||||
"orgChild2.ancestorDNA",
|
||||
])
|
||||
.orderBy("orgChild2.orgChild2Order", "ASC")
|
||||
.getMany()
|
||||
|
|
@ -1304,6 +1307,7 @@ export class OrganizationController extends Controller {
|
|||
"orgChild3.JOB_CODE",
|
||||
"orgChild3.orgChild2Id",
|
||||
"orgChild3.responsibility",
|
||||
"orgChild3.ancestorDNA",
|
||||
])
|
||||
.orderBy("orgChild3.orgChild3Order", "ASC")
|
||||
.getMany()
|
||||
|
|
@ -1333,6 +1337,7 @@ export class OrganizationController extends Controller {
|
|||
"orgChild4.JOB_CODE",
|
||||
"orgChild4.orgChild3Id",
|
||||
"orgChild4.responsibility",
|
||||
"orgChild4.ancestorDNA",
|
||||
])
|
||||
.orderBy("orgChild4.orgChild4Order", "ASC")
|
||||
.getMany()
|
||||
|
|
@ -1351,6 +1356,7 @@ export class OrganizationController extends Controller {
|
|||
orgCode: orgRoot.orgRootCode + "00",
|
||||
orgTreeRank: orgRoot.orgRootRank,
|
||||
orgTreeRankSub: orgRoot.orgRootRankSub,
|
||||
orgRootDnaId: orgRoot.ancestorDNA,
|
||||
DEPARTMENT_CODE: orgRoot.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: orgRoot.DIVISION_CODE,
|
||||
SECTION_CODE: orgRoot.SECTION_CODE,
|
||||
|
|
@ -1466,6 +1472,8 @@ export class OrganizationController extends Controller {
|
|||
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
||||
orgTreeRank: orgChild1.orgChild1Rank,
|
||||
orgTreeRankSub: orgChild1.orgChild1RankSub,
|
||||
orgRootDnaId: orgRoot.ancestorDNA,
|
||||
orgChild1DnaId: orgChild1.ancestorDNA,
|
||||
DEPARTMENT_CODE: orgChild1.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: orgChild1.DIVISION_CODE,
|
||||
SECTION_CODE: orgChild1.SECTION_CODE,
|
||||
|
|
@ -1587,6 +1595,9 @@ export class OrganizationController extends Controller {
|
|||
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
|
||||
orgTreeRank: orgChild2.orgChild2Rank,
|
||||
orgTreeRankSub: orgChild2.orgChild2RankSub,
|
||||
orgRootDnaId: orgRoot.ancestorDNA,
|
||||
orgChild1DnaId: orgChild1.ancestorDNA,
|
||||
orgChild2DnaId: orgChild2.ancestorDNA,
|
||||
DEPARTMENT_CODE: orgChild2.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: orgChild2.DIVISION_CODE,
|
||||
SECTION_CODE: orgChild2.SECTION_CODE,
|
||||
|
|
@ -1709,6 +1720,10 @@ export class OrganizationController extends Controller {
|
|||
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
||||
orgTreeRank: orgChild3.orgChild3Rank,
|
||||
orgTreeRankSub: orgChild3.orgChild3RankSub,
|
||||
orgRootDnaId: orgRoot.ancestorDNA,
|
||||
orgChild1DnaId: orgChild1.ancestorDNA,
|
||||
orgChild2DnaId: orgChild2.ancestorDNA,
|
||||
orgChild3DnaId: orgChild3.ancestorDNA,
|
||||
DEPARTMENT_CODE: orgChild3.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: orgChild3.DIVISION_CODE,
|
||||
SECTION_CODE: orgChild3.SECTION_CODE,
|
||||
|
|
@ -1831,6 +1846,11 @@ export class OrganizationController extends Controller {
|
|||
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
|
||||
orgTreeRank: orgChild4.orgChild4Rank,
|
||||
orgTreeRankSub: orgChild4.orgChild4RankSub,
|
||||
orgRootDnaId: orgRoot.ancestorDNA,
|
||||
orgChild1DnaId: orgChild1.ancestorDNA,
|
||||
orgChild2DnaId: orgChild2.ancestorDNA,
|
||||
orgChild3DnaId: orgChild3.ancestorDNA,
|
||||
orgChild4DnaId: orgChild4.ancestorDNA,
|
||||
DEPARTMENT_CODE: orgChild4.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: orgChild4.DIVISION_CODE,
|
||||
SECTION_CODE: orgChild4.SECTION_CODE,
|
||||
|
|
@ -6108,7 +6128,7 @@ export class OrganizationController extends Controller {
|
|||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
let _data = {
|
||||
let _data:any = {
|
||||
root: null,
|
||||
child1: null,
|
||||
child2: null,
|
||||
|
|
@ -6121,6 +6141,62 @@ export class OrganizationController extends Controller {
|
|||
) {
|
||||
_data = await new permission().PermissionOrgList(request, system.trim().toUpperCase());
|
||||
}
|
||||
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
relations: ["permissionProfiles", "current_holders"],
|
||||
});
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ");
|
||||
}
|
||||
|
||||
let _privilege = await new permission().PermissionOrgList(request, system);
|
||||
const attrOwnership = _privilege.root === null ? true : false;
|
||||
|
||||
if (orgRevision.orgRevisionIsDraft && !orgRevision.orgRevisionIsCurrent && !attrOwnership) {
|
||||
if(Array.isArray(profile.permissionProfiles) && profile.permissionProfiles.length > 0){
|
||||
_data.root = profile.permissionProfiles.map((x) => x.orgRootId);
|
||||
}else{
|
||||
return new HttpSuccess({ remark: "", data: [] });
|
||||
}
|
||||
}
|
||||
|
||||
// กำหนดการเข้าถึงข้อมูลตามสถานะและสิทธิ์
|
||||
const isCurrentActive = !orgRevision.orgRevisionIsDraft && orgRevision.orgRevisionIsCurrent;
|
||||
if (isCurrentActive) {
|
||||
if(_privilege.privilege !== "OWNER"){
|
||||
if(_privilege.privilege == "NORMAL"){
|
||||
const holder = profile.current_holders.find(x => x.orgRevisionId === id);
|
||||
if (!holder) return;
|
||||
_data.root = [holder.orgRootId];
|
||||
_data.child1 = [holder.orgChild1Id];
|
||||
_data.child2 = [holder.orgChild2Id];
|
||||
_data.child3 = [holder.orgChild3Id];
|
||||
_data.child4 = [holder.orgChild4Id];
|
||||
}else if(_privilege.privilege == "CHILD"){
|
||||
const holder = profile.current_holders.find(x => x.orgRevisionId === id);
|
||||
if (!holder) return;
|
||||
_data.root = [holder.orgRootId];
|
||||
if (_privilege.root && _privilege.child1 === null) {
|
||||
} else if (_privilege.child1 && _privilege.child2 === null) {
|
||||
_data.child1 = [holder.orgChild1Id];
|
||||
} else if (_privilege.child2 && _privilege.child3 === null) {
|
||||
_data.child1 = [holder.orgChild1Id];
|
||||
_data.child2 = [holder.orgChild2Id];
|
||||
} else if (_privilege.child3 && _privilege.child4 === null) {
|
||||
_data.child1 = [holder.orgChild1Id];
|
||||
_data.child2 = [holder.orgChild2Id];
|
||||
_data.child3 = [holder.orgChild3Id];
|
||||
_data.child4 = [holder.orgChild4Id];
|
||||
}
|
||||
}else{
|
||||
_data.root = [profile.current_holders.find((x) => x.orgRevisionId === id)?.orgRootId];
|
||||
}
|
||||
} else {
|
||||
if (!attrOwnership) _data = _privilege;
|
||||
}
|
||||
}
|
||||
|
||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||
.createQueryBuilder("orgRoot")
|
||||
|
|
|
|||
|
|
@ -3704,7 +3704,9 @@ export class PositionController extends Controller {
|
|||
dataMaster.current_holderId = _null;
|
||||
}
|
||||
await this.posMasterRepository.save(dataMaster, { data: request });
|
||||
await CreatePosMasterHistoryOfficer(dataMaster.id, request);
|
||||
if (chkRevision?.orgRevisionIsCurrent) {
|
||||
await CreatePosMasterHistoryOfficer(dataMaster.id, request);
|
||||
}
|
||||
setLogDataDiff(request, { before, after: dataMaster });
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -29,16 +29,26 @@ export class ProfileAvatarController extends Controller {
|
|||
|
||||
@Get("profileId/{id}")
|
||||
async getProfile(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
let _workflow = await new permission().Workflow(req, id, "SYS_REGISTRY_OFFICER");
|
||||
if (_workflow == false)
|
||||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", id);
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
try {
|
||||
// let _workflow = await new permission().Workflow(req, id, "SYS_REGISTRY_OFFICER");
|
||||
// if (_workflow == false)
|
||||
// await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", id);
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
return new HttpSuccess(profile);
|
||||
return new HttpSuccess(profile);
|
||||
} catch (error) {
|
||||
console.error("Error in getProfile:", error);
|
||||
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
throw new HttpError(HttpStatus.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาดภายในระบบ");
|
||||
}
|
||||
}
|
||||
|
||||
@Get("profileId-admin/{id}")
|
||||
|
|
|
|||
|
|
@ -2886,8 +2886,8 @@ export class ProfileController extends Controller {
|
|||
} else if ((posMaster?.current_holder?.posLevel?.posLevelAuthority ?? null) == "GOVERNOR") {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
console.log(posMaster);
|
||||
console.log(posMaster.id);
|
||||
// console.log(posMaster);
|
||||
// console.log(posMaster.id);
|
||||
let condition: any = {
|
||||
orgRootId: posMaster.orgRootId,
|
||||
id: Not(posMaster.current_holderId || ""),
|
||||
|
|
@ -2917,9 +2917,9 @@ export class ProfileController extends Controller {
|
|||
condition.isDirector = true;
|
||||
conditionNow.isDirector = true;
|
||||
}
|
||||
console.log(condition);
|
||||
console.log("------------------");
|
||||
console.log(conditionNow);
|
||||
// console.log(condition);
|
||||
// console.log("------------------");
|
||||
// console.log(conditionNow);
|
||||
if (body.isAct == true) {
|
||||
const [lists, total] = await AppDataSource.getRepository(viewDirectorActing)
|
||||
.createQueryBuilder("viewDirectorActing")
|
||||
|
|
@ -2928,6 +2928,7 @@ export class ProfileController extends Controller {
|
|||
qb.orWhere(condition).orWhere(conditionNow);
|
||||
}),
|
||||
)
|
||||
.andWhere("viewDirectorActing.isProbation = :isProbation", { isProbation: false })
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
|
|
@ -2992,6 +2993,7 @@ export class ProfileController extends Controller {
|
|||
qb.orWhere(condition).orWhere(conditionNow);
|
||||
}),
|
||||
)
|
||||
.andWhere("viewDirector.isProbation = :isProbation", { isProbation: false })
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
|
|
@ -7365,40 +7367,45 @@ export class ProfileController extends Controller {
|
|||
nodeDnaId: null,
|
||||
type: profile.employeeClass,
|
||||
salary: profile.amount,
|
||||
posNo:
|
||||
root?.orgRootShortName && posMaster?.posMasterNo
|
||||
? `${root?.orgRootShortName} ${posMaster?.posMasterNo}`
|
||||
: "",
|
||||
posNo: null
|
||||
// root?.orgRootShortName && posMaster?.posMasterNo
|
||||
// ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}`
|
||||
// : "",
|
||||
};
|
||||
if (_profile.child4Id != null) {
|
||||
_profile.node = 4;
|
||||
_profile.nodeId = _profile.child4Id;
|
||||
_profile.nodeDnaId = _profile.child4DnaId;
|
||||
_profile.nodeShortName = _profile.child4ShortName;
|
||||
_profile.posNo = `${_profile.child4ShortName} ${_profile.posMasterNo}`;
|
||||
} else if (_profile.child3Id != null) {
|
||||
_profile.node = 3;
|
||||
_profile.nodeId = _profile.child3Id;
|
||||
_profile.nodeDnaId = _profile.child3DnaId;
|
||||
_profile.nodeShortName = _profile.child3ShortName;
|
||||
_profile.posNo = `${_profile.child3ShortName} ${_profile.posMasterNo}`;
|
||||
} else if (_profile.child2Id != null) {
|
||||
_profile.node = 2;
|
||||
_profile.nodeId = _profile.child2Id;
|
||||
_profile.nodeDnaId = _profile.child2DnaId;
|
||||
_profile.nodeShortName = _profile.child2ShortName;
|
||||
_profile.posNo = `${_profile.child2ShortName} ${_profile.posMasterNo}`;
|
||||
} else if (_profile.child1Id != null) {
|
||||
_profile.node = 1;
|
||||
_profile.nodeId = _profile.child1Id;
|
||||
_profile.nodeDnaId = _profile.child1DnaId;
|
||||
_profile.nodeShortName = _profile.child1ShortName;
|
||||
_profile.posNo = `${_profile.child1ShortName} ${_profile.posMasterNo}`;
|
||||
} else if (_profile.rootId != null) {
|
||||
_profile.node = 0;
|
||||
_profile.nodeId = _profile.rootId;
|
||||
_profile.nodeDnaId = _profile.rootDnaId;
|
||||
_profile.nodeShortName = _profile.rootShortName;
|
||||
_profile.posNo = `${_profile.rootShortName} ${_profile.posMasterNo}`;
|
||||
}
|
||||
return new HttpSuccess(_profile);
|
||||
}
|
||||
|
||||
// ขรก.
|
||||
let orgRevisionPublish: any = await this.orgRevisionRepo
|
||||
.createQueryBuilder("orgRevision")
|
||||
.where("orgRevision.orgRevisionIsDraft = false")
|
||||
|
|
@ -7529,10 +7536,10 @@ export class ProfileController extends Controller {
|
|||
nodeDnaId: null,
|
||||
salary: profile ? profile.amount : null,
|
||||
amountSpecial: profile ? profile.amountSpecial : null,
|
||||
posNo:
|
||||
root?.orgRootShortName && posMaster?.posMasterNo
|
||||
? `${root?.orgRootShortName} ${posMaster?.posMasterNo}`
|
||||
: "",
|
||||
posNo: null
|
||||
// root?.orgRootShortName && posMaster?.posMasterNo
|
||||
// ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}`
|
||||
// : "",
|
||||
};
|
||||
|
||||
if (_profile.child4Id != null) {
|
||||
|
|
@ -7540,26 +7547,31 @@ export class ProfileController extends Controller {
|
|||
_profile.nodeId = _profile.child4Id;
|
||||
_profile.nodeDnaId = _profile.child4DnaId;
|
||||
_profile.nodeShortName = _profile.child4ShortName;
|
||||
_profile.posNo = `${_profile.child4ShortName} ${posMaster?.posMasterNo}`;
|
||||
} else if (_profile.child3Id != null) {
|
||||
_profile.node = 3;
|
||||
_profile.nodeId = _profile.child3Id;
|
||||
_profile.nodeDnaId = _profile.child3DnaId;
|
||||
_profile.nodeShortName = _profile.child3ShortName;
|
||||
_profile.posNo = `${_profile.child3ShortName} ${posMaster?.posMasterNo}`;
|
||||
} else if (_profile.child2Id != null) {
|
||||
_profile.node = 2;
|
||||
_profile.nodeId = _profile.child2Id;
|
||||
_profile.nodeDnaId = _profile.child2DnaId;
|
||||
_profile.nodeShortName = _profile.child2ShortName;
|
||||
_profile.posNo = `${_profile.child2ShortName} ${posMaster?.posMasterNo}`;
|
||||
} else if (_profile.child1Id != null) {
|
||||
_profile.node = 1;
|
||||
_profile.nodeId = _profile.child1Id;
|
||||
_profile.nodeDnaId = _profile.child1DnaId;
|
||||
_profile.nodeShortName = _profile.child1ShortName;
|
||||
_profile.posNo = `${_profile.child1ShortName} ${posMaster?.posMasterNo}`;
|
||||
} else if (_profile.rootId != null) {
|
||||
_profile.node = 0;
|
||||
_profile.nodeId = _profile.rootId;
|
||||
_profile.nodeDnaId = _profile.rootDnaId;
|
||||
_profile.nodeShortName = _profile.rootShortName;
|
||||
_profile.posNo = `${_profile.rootShortName} ${posMaster?.posMasterNo}`;
|
||||
}
|
||||
return new HttpSuccess(_profile);
|
||||
}
|
||||
|
|
@ -9763,9 +9775,13 @@ export class ProfileController extends Controller {
|
|||
keyword?: string;
|
||||
},
|
||||
) {
|
||||
let conditionFullName =
|
||||
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
|
||||
const [findProfile, total] = await AppDataSource.getRepository(Profile)
|
||||
const orgRevisionActive = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
if (!orgRevisionActive) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
let query = AppDataSource.getRepository(Profile)
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
|
|
@ -9778,103 +9794,83 @@ export class ProfileController extends Controller {
|
|||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
.leftJoinAndSelect("current_holders.positions", "positions")
|
||||
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
||||
.where(`profile.position LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`profile.prefix LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`profile.firstName LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`profile.lastName LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`posLevel.posLevelName LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`posType.posTypeName LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(conditionFullName, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets(qb => {
|
||||
qb.where("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("posType.posTypeName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` });
|
||||
})
|
||||
)
|
||||
.andWhere("profile.isLeave = false")
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
.andWhere("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: orgRevisionActive.id });
|
||||
|
||||
const orgRevisionActive = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
const findRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
if (!findRevision) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
const [findProfile, total] = await query
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const mapDataProfile = await Promise.all(
|
||||
findProfile.map(async (item: Profile) => {
|
||||
const posMaster =
|
||||
item.current_holders == null ||
|
||||
item.current_holders.length == 0 ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id);
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id);
|
||||
const position =
|
||||
posMaster == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions == null ||
|
||||
item.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions == null ||
|
||||
item.current_holders?.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions.length ==
|
||||
0 ||
|
||||
item.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true) == null
|
||||
? null
|
||||
: item.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true);
|
||||
const posExecutive =
|
||||
position == null ||
|
||||
item.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
|
||||
null ||
|
||||
item.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
|
||||
?.posExecutiveName == null
|
||||
? null
|
||||
: item.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
|
||||
.posExecutiveName;
|
||||
|
||||
const shortName =
|
||||
item.current_holders.length == 0
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4 !=
|
||||
null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3 !=
|
||||
null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.orgChild2 != null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.orgChild1 != null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) !=
|
||||
null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.orgRoot != null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: null;
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import { AppDataSource } from "../database/data-source";
|
|||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { Brackets, Double, In, IsNull, Like, Not } from "typeorm";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import {
|
||||
|
|
@ -2039,9 +2040,13 @@ export class ProfileEmployeeController extends Controller {
|
|||
if (!result) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
await new permission().PermissionOrgUserDelete(request, "SYS_REGISTRY_EMP", result.id);
|
||||
await this.informationHistoryRepository.delete({ profileEmployeeId: id });
|
||||
await this.profileRepo.remove(result);
|
||||
try{
|
||||
await new permission().PermissionOrgUserDelete(request, "SYS_REGISTRY_EMP", result.id);
|
||||
await this.informationHistoryRepository.delete({ profileEmployeeId: id });
|
||||
await this.profileRepo.remove(result);
|
||||
} catch {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้ เนื่องจากข้อมูลนี้ถูกใช้งานในระบบอื่น");
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -3583,36 +3588,41 @@ export class ProfileEmployeeController extends Controller {
|
|||
nodeDnaId: null,
|
||||
salary: profile ? profile.amount : null,
|
||||
amountSpecial: profile ? profile.amountSpecial : null,
|
||||
posNo:
|
||||
root?.orgRootShortName && posMaster?.posMasterNo
|
||||
? `${root?.orgRootShortName} ${posMaster?.posMasterNo}`
|
||||
: "",
|
||||
posNo: null
|
||||
// root?.orgRootShortName && posMaster?.posMasterNo
|
||||
// ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}`
|
||||
// : "",
|
||||
};
|
||||
if (_profile.child4Id != null) {
|
||||
_profile.node = 4;
|
||||
_profile.nodeId = _profile.child4Id;
|
||||
_profile.nodeDnaId = _profile.child4DnaId;
|
||||
_profile.nodeShortName = _profile.child4ShortName;
|
||||
_profile.posNo = `${_profile.child4ShortName} ${_profile.posMasterNo}`;
|
||||
} else if (_profile.child3Id != null) {
|
||||
_profile.node = 3;
|
||||
_profile.nodeId = _profile.child3Id;
|
||||
_profile.nodeDnaId = _profile.child3DnaId;
|
||||
_profile.nodeShortName = _profile.child3ShortName;
|
||||
_profile.posNo = `${_profile.child3ShortName} ${_profile.posMasterNo}`;
|
||||
} else if (_profile.child2Id != null) {
|
||||
_profile.node = 2;
|
||||
_profile.nodeId = _profile.child2Id;
|
||||
_profile.nodeDnaId = _profile.child2DnaId;
|
||||
_profile.nodeShortName = _profile.child2ShortName;
|
||||
_profile.posNo = `${_profile.child2ShortName} ${_profile.posMasterNo}`;
|
||||
} else if (_profile.child1Id != null) {
|
||||
_profile.node = 1;
|
||||
_profile.nodeId = _profile.child1Id;
|
||||
_profile.nodeDnaId = _profile.child1DnaId;
|
||||
_profile.nodeShortName = _profile.child1ShortName;
|
||||
_profile.posNo = `${_profile.child1ShortName} ${_profile.posMasterNo}`;
|
||||
} else if (_profile.rootId != null) {
|
||||
_profile.node = 0;
|
||||
_profile.nodeId = _profile.rootId;
|
||||
_profile.nodeDnaId = _profile.rootDnaId;
|
||||
_profile.nodeShortName = _profile.rootShortName;
|
||||
_profile.posNo = `${_profile.rootShortName} ${_profile.posMasterNo}`;
|
||||
}
|
||||
return new HttpSuccess(_profile);
|
||||
}
|
||||
|
|
@ -4409,11 +4419,16 @@ export class ProfileEmployeeController extends Controller {
|
|||
page: number;
|
||||
pageSize: number;
|
||||
keyword?: string;
|
||||
type?: string;
|
||||
},
|
||||
) {
|
||||
let conditionFullName =
|
||||
"CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword";
|
||||
const [findProfile, total] = await AppDataSource.getRepository(ProfileEmployee)
|
||||
const orgRevisionActive = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
if (!orgRevisionActive) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
let query = AppDataSource.getRepository(ProfileEmployee)
|
||||
.createQueryBuilder("profileEmployee")
|
||||
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profileEmployee.posType", "posType")
|
||||
|
|
@ -4425,88 +4440,78 @@ export class ProfileEmployeeController extends Controller {
|
|||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
.leftJoinAndSelect("current_holders.positions", "positions")
|
||||
.where(`profileEmployee.position LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`profileEmployee.prefix LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`profileEmployee.firstName LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`profileEmployee.lastName LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`posLevel.posLevelName LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(`posType.posTypeName LIKE :keyword`, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.orWhere(conditionFullName, {
|
||||
keyword: `%${body.keyword}%`,
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets(qb => {
|
||||
qb.where("profileEmployee.position LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("posType.posTypeName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` });
|
||||
})
|
||||
)
|
||||
.andWhere("profileEmployee.isLeave = false")
|
||||
.andWhere("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: orgRevisionActive.id });
|
||||
|
||||
if (body.type) {
|
||||
const typeUpper = body.type.trim().toUpperCase();
|
||||
if (typeUpper === "EMPLOYEE") {
|
||||
query = query.andWhere("profileEmployee.employeeClass = 'PERM'");
|
||||
}
|
||||
else if (typeUpper === "TEMP"){
|
||||
query = query.andWhere("profileEmployee.employeeClass = 'TEMP'");
|
||||
}
|
||||
}
|
||||
|
||||
const [findProfile, total] = await query
|
||||
.orderBy("profileEmployee.citizenId", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const orgRevisionActive = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
const findRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
if (!findRevision) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
|
||||
const mapDataProfile = await Promise.all(
|
||||
findProfile.map(async (item: ProfileEmployee) => {
|
||||
const posMaster =
|
||||
item.current_holders == null ||
|
||||
item.current_holders.length == 0 ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id);
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id);
|
||||
const position =
|
||||
posMaster == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions == null ||
|
||||
item.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions == null ||
|
||||
item.current_holders?.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions.length ==
|
||||
0 ||
|
||||
item.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true) == null
|
||||
? null
|
||||
: item.current_holders
|
||||
.find((x) => x.orgRevisionId == findRevision.id)
|
||||
.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.positions?.find((position) => position.positionIsSelected == true);
|
||||
|
||||
const shortName =
|
||||
item.current_holders.length == 0
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4 !=
|
||||
null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3 !=
|
||||
null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.orgChild2 != null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.orgChild1 != null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) !=
|
||||
null &&
|
||||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
|
||||
?.orgRoot != null
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}`
|
||||
: null;
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ import axios from "axios";
|
|||
import { deleteUser } from "../keycloak";
|
||||
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
||||
import { getTopDegrees } from "../services/PositionService";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
@Route("api/v1/org/profile-temp")
|
||||
@Tags("ProfileEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -1027,8 +1028,13 @@ export class ProfileEmployeeTempController extends Controller {
|
|||
if (!result) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
await this.informationHistoryRepository.delete({ profileEmployeeId: id });
|
||||
await this.profileRepo.remove(result);
|
||||
|
||||
try{
|
||||
await this.informationHistoryRepository.delete({ profileEmployeeId: id });
|
||||
await this.profileRepo.remove(result);
|
||||
} catch {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้ เนื่องจากข้อมูลนี้ถูกใช้งานในระบบอื่น");
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,36 +149,16 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
orgRevisionIsCurrent: true,
|
||||
},
|
||||
});
|
||||
|
||||
// ค้นหา profile ก่อน
|
||||
const record = await this.profileEmployeeRepo.findOne({
|
||||
where: {
|
||||
id: profileEmployeeId,
|
||||
// profileSalary: {
|
||||
// commandCode: In([
|
||||
// "0",
|
||||
// "9",
|
||||
// "1",
|
||||
// "2",
|
||||
// "3",
|
||||
// "4",
|
||||
// "8",
|
||||
// "10",
|
||||
// "11",
|
||||
// "12",
|
||||
// "13",
|
||||
// "14",
|
||||
// "15",
|
||||
// "16",
|
||||
// ]),
|
||||
// }
|
||||
},
|
||||
relations: ["posType", "posLevel"/*, "profileSalary"*/],
|
||||
// order: {
|
||||
// profileSalary: {
|
||||
// order: "DESC",
|
||||
// createdAt: "DESC"
|
||||
// }
|
||||
// }
|
||||
where: { id: profileEmployeeId },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล profile");
|
||||
}
|
||||
const posMaster = await this.posMasterRepo.findOne({
|
||||
where: {
|
||||
orgRevisionId: orgRevision?.id,
|
||||
|
|
@ -217,10 +197,10 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
orgShortName = posMaster.orgChild4?.orgChild4ShortName;
|
||||
}
|
||||
}
|
||||
let _OrgLeave:any = []
|
||||
let orgLeave:string = ""
|
||||
let posNoLeave:string = ""
|
||||
let _profileSalary:any = null;
|
||||
let _OrgLeave: any = [];
|
||||
let orgLeave: string = "";
|
||||
let posNoLeave: string = "";
|
||||
let _profileSalary: any = null;
|
||||
if (record?.isLeave /*&& record?.profileSalary.length > 0*/) {
|
||||
const profileSalary = await this.salaryRepo.find({
|
||||
select: [
|
||||
|
|
@ -230,7 +210,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
"orgChild3",
|
||||
"orgChild4",
|
||||
"posNoAbb",
|
||||
"posNo"
|
||||
"posNo",
|
||||
],
|
||||
where: {
|
||||
profileEmployeeId: profileEmployeeId,
|
||||
|
|
@ -253,8 +233,8 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
},
|
||||
order: {
|
||||
order: "DESC",
|
||||
createdAt: "DESC"
|
||||
}
|
||||
createdAt: "DESC",
|
||||
},
|
||||
});
|
||||
// _OrgLeave = [
|
||||
// profileSalary.length > 0 && profileSalary[0].orgChild4 ? profileSalary[0].orgChild4 : null,
|
||||
|
|
@ -264,15 +244,14 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
// profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null,
|
||||
// ];
|
||||
if (record.leaveType == "RETIRE") {
|
||||
_profileSalary = profileSalary.length > 1
|
||||
? profileSalary[1]
|
||||
: profileSalary.length > 0
|
||||
? profileSalary[0]
|
||||
: null;
|
||||
_profileSalary =
|
||||
profileSalary.length > 1
|
||||
? profileSalary[1]
|
||||
: profileSalary.length > 0
|
||||
? profileSalary[0]
|
||||
: null;
|
||||
} else {
|
||||
_profileSalary = profileSalary.length > 0
|
||||
? profileSalary[0]
|
||||
: null
|
||||
_profileSalary = profileSalary.length > 0 ? profileSalary[0] : null;
|
||||
}
|
||||
if (_profileSalary) {
|
||||
_OrgLeave = [
|
||||
|
|
@ -285,10 +264,9 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
} else {
|
||||
_OrgLeave = [];
|
||||
}
|
||||
orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n");
|
||||
posNoLeave = _profileSalary != null
|
||||
? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}`
|
||||
: ""
|
||||
orgLeave = _OrgLeave.filter((x: any) => x !== undefined && x !== null).join("\n");
|
||||
posNoLeave =
|
||||
_profileSalary != null ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : "";
|
||||
}
|
||||
const data = {
|
||||
org: record?.isLeave == false ? org : orgLeave, //สังกัด
|
||||
|
|
@ -297,9 +275,12 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
record?.posLevel == null
|
||||
? null
|
||||
: `${record?.posType?.posTypeShortName ?? ""} ${record?.posLevel?.posLevelName ?? ""}`, //ระดับ
|
||||
posMasterNo: record?.isLeave == false
|
||||
? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`
|
||||
: posNoLeave/*record && record?.profileSalary.length > 0
|
||||
posMasterNo:
|
||||
record?.isLeave == false
|
||||
? posMaster == null
|
||||
? null
|
||||
: `${orgShortName} ${posMaster.posMasterNo}`
|
||||
: posNoLeave /*record && record?.profileSalary.length > 0
|
||||
? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}`
|
||||
: null*/, //เลขที่ตำแหน่ง
|
||||
posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท
|
||||
|
|
@ -326,34 +307,16 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
orgRevisionIsCurrent: true,
|
||||
},
|
||||
});
|
||||
|
||||
// ค้นหา profile ก่อน
|
||||
const record = await this.profileEmployeeRepo.findOne({
|
||||
where: {
|
||||
id: profileEmployeeId,
|
||||
// profileSalary:{
|
||||
// commandCode: In([
|
||||
// "0",
|
||||
// "9",
|
||||
// "1",
|
||||
// "2",
|
||||
// "3",
|
||||
// "4",
|
||||
// "8",
|
||||
// "10",
|
||||
// "11",
|
||||
// "12",
|
||||
// "13",
|
||||
// "14",
|
||||
// "15",
|
||||
// "16",
|
||||
// ]),
|
||||
// }
|
||||
},
|
||||
relations: {
|
||||
posType: true,
|
||||
posLevel: true,
|
||||
// profileSalary: true
|
||||
},
|
||||
where: { id: profileEmployeeId },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล profile");
|
||||
}
|
||||
const posMaster = await this.posMasterRepo.findOne({
|
||||
where: {
|
||||
orgRevisionId: orgRevision?.id,
|
||||
|
|
@ -392,10 +355,10 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
orgShortName = posMaster.orgChild4?.orgChild4ShortName;
|
||||
}
|
||||
}
|
||||
let _OrgLeave:any = []
|
||||
let orgLeave:string = ""
|
||||
let posNoLeave:string = ""
|
||||
let _profileSalary:any = null;
|
||||
let _OrgLeave: any = [];
|
||||
let orgLeave: string = "";
|
||||
let posNoLeave: string = "";
|
||||
let _profileSalary: any = null;
|
||||
if (record?.isLeave /*&& record?.profileSalary.length > 0*/) {
|
||||
const profileSalary = await this.salaryRepo.find({
|
||||
select: [
|
||||
|
|
@ -405,7 +368,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
"orgChild3",
|
||||
"orgChild4",
|
||||
"posNoAbb",
|
||||
"posNo"
|
||||
"posNo",
|
||||
],
|
||||
where: {
|
||||
profileEmployeeId: profileEmployeeId,
|
||||
|
|
@ -428,8 +391,8 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
},
|
||||
order: {
|
||||
order: "DESC",
|
||||
createdAt: "DESC"
|
||||
}
|
||||
createdAt: "DESC",
|
||||
},
|
||||
});
|
||||
// _OrgLeave = [
|
||||
// profileSalary.length > 0 && profileSalary[0].orgChild4 ? profileSalary[0].orgChild4 : null,
|
||||
|
|
@ -439,15 +402,14 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
// profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null,
|
||||
// ];
|
||||
if (record.leaveType == "RETIRE") {
|
||||
_profileSalary = profileSalary.length > 1
|
||||
? profileSalary[1]
|
||||
: profileSalary.length > 0
|
||||
? profileSalary[0]
|
||||
: null;
|
||||
_profileSalary =
|
||||
profileSalary.length > 1
|
||||
? profileSalary[1]
|
||||
: profileSalary.length > 0
|
||||
? profileSalary[0]
|
||||
: null;
|
||||
} else {
|
||||
_profileSalary = profileSalary.length > 0
|
||||
? profileSalary[0]
|
||||
: null;
|
||||
_profileSalary = profileSalary.length > 0 ? profileSalary[0] : null;
|
||||
}
|
||||
if (_profileSalary) {
|
||||
_OrgLeave = [
|
||||
|
|
@ -460,23 +422,23 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
} else {
|
||||
_OrgLeave = [];
|
||||
}
|
||||
orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n");
|
||||
posNoLeave = _profileSalary != null
|
||||
? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}`
|
||||
: ""
|
||||
orgLeave = _OrgLeave.filter((x: any) => x !== undefined && x !== null).join("\n");
|
||||
posNoLeave =
|
||||
_profileSalary != null ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : "";
|
||||
}
|
||||
const data = {
|
||||
org: record?.isLeave == false ? org : orgLeave, //สังกัด
|
||||
position: record?.position, //ตำแหน่ง
|
||||
posLevel: record?.posLevel == null && record?.posType == null
|
||||
? null
|
||||
: `${record?.posType.posTypeShortName} ${record?.posLevel.posLevelName}`, //ระดับ
|
||||
posMasterNo:
|
||||
record?.isLeave == false
|
||||
? posMaster == null
|
||||
? null
|
||||
posLevel:
|
||||
record?.posLevel == null && record?.posType == null
|
||||
? null
|
||||
: `${record?.posType.posTypeShortName} ${record?.posLevel.posLevelName}`, //ระดับ
|
||||
posMasterNo:
|
||||
record?.isLeave == false
|
||||
? posMaster == null
|
||||
? null
|
||||
: `${orgShortName} ${posMaster.posMasterNo}`
|
||||
: posNoLeave/*record && record.profileSalary.length > 0
|
||||
: posNoLeave /*record && record.profileSalary.length > 0
|
||||
? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}`
|
||||
: null*/, //เลขที่ตำแหน่ง
|
||||
posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท
|
||||
|
|
@ -490,7 +452,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
govAgeAbsent: record?.govAgeAbsent ?? null, // ขาดราชการ
|
||||
govAgePlus: record?.govAgePlus, // อายุราชการเกื้อกูล
|
||||
dateRetireLaw: record?.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย
|
||||
isLeave: record?.isLeave
|
||||
isLeave: record?.isLeave,
|
||||
};
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11052,6 +11052,12 @@ export class ReportController extends Controller {
|
|||
acc[key] = { ...curr, total: 1 };
|
||||
} else {
|
||||
acc[key].total += 1;
|
||||
acc[key].total += 1;
|
||||
const combinedPositions = new Set([
|
||||
...acc[key].positions.split(", "),
|
||||
...curr.positions.split(", "),
|
||||
]);
|
||||
acc[key].positions = Array.from(combinedPositions).join(", ");
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
|
@ -11151,17 +11157,24 @@ export class ReportController extends Controller {
|
|||
.orderBy("posType.posTypeRank", "ASC")
|
||||
.addOrderBy("posLevel.posLevelRank", "ASC")
|
||||
.getMany();
|
||||
|
||||
|
||||
const _posMaster = posMaster.map((x) => ({
|
||||
type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","),
|
||||
typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""),
|
||||
typeShortNameAndRank: [
|
||||
...new Set(
|
||||
x.positions.map(
|
||||
(y) => `${y.posType.posTypeShortName} ${y.posLevel.posLevelRank}`
|
||||
)
|
||||
),
|
||||
].join(", "),
|
||||
level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","),
|
||||
levelRank: [
|
||||
...new Set(
|
||||
x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`),
|
||||
),
|
||||
].join(""),
|
||||
positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""),
|
||||
positions: [...new Set(x.positions.map((y) => y.positionName))].join(", "),
|
||||
}));
|
||||
|
||||
const groupedData = _posMaster.reduce((acc: any, curr: any) => {
|
||||
|
|
@ -11170,14 +11183,21 @@ export class ReportController extends Controller {
|
|||
acc[key] = { ...curr, total: 1 };
|
||||
} else {
|
||||
acc[key].total += 1;
|
||||
const combinedPositions = new Set([
|
||||
...acc[key].positions.split(", "),
|
||||
...curr.positions.split(", "),
|
||||
]);
|
||||
acc[key].positions = Array.from(combinedPositions).join(", ");
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// console.log("groupedData>>>",groupedData);
|
||||
|
||||
let result = Object.values(groupedData)
|
||||
.map((x: any) => ({
|
||||
type: x.type,
|
||||
typeRank: parseInt(x.typeRank),
|
||||
typeShortNameAndRank: x.typeShortNameAndRank,
|
||||
level: x.level,
|
||||
levelRank: parseInt(x.levelRank),
|
||||
|
||||
|
|
@ -11208,9 +11228,10 @@ export class ReportController extends Controller {
|
|||
if (x.type !== tmpType && tmpType != "") {
|
||||
_total = total - x.total;
|
||||
_reslut.push({
|
||||
type: "",
|
||||
type: "รวม",
|
||||
typeRank: "",
|
||||
level: "รวม",
|
||||
typeShortNameAndRank: "",
|
||||
level: "",
|
||||
levelRank: "",
|
||||
total: _total,
|
||||
remark: "",
|
||||
|
|
@ -11226,25 +11247,27 @@ export class ReportController extends Controller {
|
|||
});
|
||||
|
||||
_reslut.push({
|
||||
type: "",
|
||||
type: "รวม",
|
||||
typeRank: "",
|
||||
level: "รวม",
|
||||
typeShortNameAndRank: "",
|
||||
level: "",
|
||||
levelRank: "",
|
||||
total: total,
|
||||
remark: "",
|
||||
});
|
||||
_reslut.push({
|
||||
type: "",
|
||||
type: "รวมทั้งสิ้น",
|
||||
typeRank: "",
|
||||
level: "รวมทั้งสิ้น",
|
||||
typeShortNameAndRank: "",
|
||||
level: "",
|
||||
levelRank: "",
|
||||
total: allTotal,
|
||||
remark: "",
|
||||
});
|
||||
|
||||
return new HttpSuccess({
|
||||
template: "report4",
|
||||
reportName: "report4",
|
||||
template: "report5",
|
||||
reportName: "report5",
|
||||
data: {
|
||||
dateCurrent: Extension.ToThaiShortDate(new Date()),
|
||||
rootName: orgRootData ? orgRootData.orgRootName : "-",
|
||||
|
|
|
|||
|
|
@ -758,11 +758,21 @@ export class KeycloakController extends Controller {
|
|||
}
|
||||
|
||||
@Get("user/role/{id}")
|
||||
async getRoleUser(@Path("id") id: string) {
|
||||
async getRoleUser(@Request() req: RequestWithUser,@Path("id") id: string) {
|
||||
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { keycloak: id },
|
||||
relations: ["roleKeycloaks"],
|
||||
});
|
||||
|
||||
if (
|
||||
req.user.sub === id &&
|
||||
req.user.role.some(x => x === 'ADMIN') &&
|
||||
!req.user.role.some(x => x === 'SUPER_ADMIN')
|
||||
) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่มีสิทธิ์เข้าถึงข้อมูลนี้");
|
||||
}
|
||||
|
||||
if (!profile) {
|
||||
const profileEmp = await this.profileEmpRepo.findOne({
|
||||
where: { keycloak: id, employeeClass: "PERM" },
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ import { ApiName } from "./ApiName";
|
|||
@Entity("apiHistory")
|
||||
export class ApiHistory extends EntityBase {
|
||||
@Column({
|
||||
type: 'longtext',
|
||||
nullable: true,
|
||||
comment: "header",
|
||||
length: 255,
|
||||
default: null,
|
||||
default: null,
|
||||
})
|
||||
headerApi: string;
|
||||
|
||||
@Column({
|
||||
type: 'longtext',
|
||||
nullable: true,
|
||||
comment: "token",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
tokenApi: string;
|
||||
|
|
|
|||
|
|
@ -14,13 +14,61 @@ export class ApiKey extends EntityBase {
|
|||
name: string;
|
||||
|
||||
@Column({
|
||||
type: 'longtext',
|
||||
nullable: true,
|
||||
comment: "keyApi",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
keyApi: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "accessType",
|
||||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
accessType: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "dnaRootId",
|
||||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
dnaRootId: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "dnaChild1Id",
|
||||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
dnaChild1Id: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "dnaChild2Id",
|
||||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
dnaChild2Id: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "dnaChild3Id",
|
||||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
dnaChild3Id: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "dnaChild4Id",
|
||||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
dnaChild4Id: string;
|
||||
|
||||
@ManyToMany(() => ApiName, (apiName) => apiName.apiKeys)
|
||||
apiNames: ApiName[];
|
||||
|
||||
|
|
@ -34,4 +82,22 @@ export class CreateApiKey {
|
|||
|
||||
@Column()
|
||||
apiId: string[];
|
||||
|
||||
@Column()
|
||||
accessType?: string;
|
||||
|
||||
@Column()
|
||||
dnaRootId?: string;
|
||||
|
||||
@Column()
|
||||
dnaChild1Id?: string;
|
||||
|
||||
@Column()
|
||||
dnaChild2Id?: string;
|
||||
|
||||
@Column()
|
||||
dnaChild3Id?: string;
|
||||
|
||||
@Column()
|
||||
dnaChild4Id?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,13 @@ export class AuthRole extends EntityBase {
|
|||
})
|
||||
roleDescription: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ข้อมูลที่ role admin สามารถเห็นได้",
|
||||
default: null,
|
||||
})
|
||||
isAdminVisibled: boolean;
|
||||
|
||||
@OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForRole)
|
||||
authRoles: AuthRoleAttr[];
|
||||
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ export class ProfileTraining extends EntityBase {
|
|||
topic: string;
|
||||
|
||||
@Column({
|
||||
type: 'longtext',
|
||||
nullable: true,
|
||||
length: 200,
|
||||
comment: "สถานที่ฝึกอบรม/ดูงาน ",
|
||||
comment: "สถานที่ฝึกอบรม/ดูงาน",
|
||||
default: null,
|
||||
})
|
||||
place: string;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import { ViewColumn, ViewEntity } from "typeorm";
|
|||
profile.lastName AS lastName,
|
||||
profile.citizenId AS citizenId,
|
||||
profile.position AS position,
|
||||
profile.keycloak AS keycloakId,
|
||||
profile.isProbation AS isProbation,
|
||||
CONCAT(
|
||||
CASE
|
||||
WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName
|
||||
|
|
@ -31,6 +33,21 @@ import { ViewColumn, ViewEntity } from "typeorm";
|
|||
posMaster.orgChild3Id AS orgChild3Id,
|
||||
posMaster.orgChild4Id AS orgChild4Id,
|
||||
CONCAT(posMaster.id, profile.id) AS \`key\`,
|
||||
(
|
||||
SELECT hrms_organization.acting.actFullNameKeycloakId
|
||||
FROM hrms_organization.view_director_acting acting
|
||||
WHERE ((hrms_organization.acting.Id = hrms_organization.posMaster.current_holderId)
|
||||
AND (hrms_organization.acting.orgRootId = hrms_organization.posMaster.orgRootId)
|
||||
AND ((hrms_organization.acting.orgChild1Id = hrms_organization.posMaster.orgChild1Id)
|
||||
OR (hrms_organization.acting.orgChild1Id IS NULL))
|
||||
AND ((hrms_organization.acting.orgChild2Id = hrms_organization.posMaster.orgChild2Id)
|
||||
OR (hrms_organization.acting.orgChild2Id IS NULL))
|
||||
AND ((hrms_organization.acting.orgChild3Id = hrms_organization.posMaster.orgChild3Id)
|
||||
OR (hrms_organization.acting.orgChild3Id IS NULL))
|
||||
AND ((hrms_organization.acting.orgChild4Id = hrms_organization.posMaster.orgChild4Id)
|
||||
OR (hrms_organization.acting.orgChild4Id IS NULL)))
|
||||
LIMIT 1
|
||||
) AS actFullNameKeycloakId,
|
||||
(
|
||||
SELECT actFullNameId
|
||||
FROM view_director_acting AS acting
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { ViewColumn, ViewEntity } from "typeorm";
|
|||
\`profileChild\`.\`lastName\` AS \`lastName\`,
|
||||
\`profileChild\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`profileChild\`.\`position\` AS \`position\`,
|
||||
\`profile\`.\`isProbation\` AS \`isProbation\`,
|
||||
CONCAT((CASE
|
||||
WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\`
|
||||
WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\`
|
||||
|
|
@ -29,6 +30,10 @@ import { ViewColumn, ViewEntity } from "typeorm";
|
|||
\`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`,
|
||||
\`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`,
|
||||
\`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`,
|
||||
CONCAT(\`hrms_organization\`.\`posMaster\`.\`id\`,
|
||||
\`profileChild\`.\`id\`) AS \`key\`,
|
||||
\`hrms_organization\`.\`profile\`.\`id\` AS \`actFullNameId\`,
|
||||
\`hrms_organization\`.\`profile\`.\`keycloak\` AS \`actFullNameKeycloakId\`,
|
||||
CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`,
|
||||
\`profile\`.\`id\` AS \`actFullNameId\`,
|
||||
CONCAT(\`profile\`.\`prefix\`,
|
||||
|
|
@ -71,6 +76,8 @@ export class viewDirectorActing {
|
|||
@ViewColumn()
|
||||
position: string;
|
||||
@ViewColumn()
|
||||
isProbation: string;
|
||||
@ViewColumn()
|
||||
posNo: string;
|
||||
@ViewColumn()
|
||||
posLevel: string;
|
||||
|
|
|
|||
24
src/interfaces/date-serializer.ts
Normal file
24
src/interfaces/date-serializer.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Custom Date serializer for local timezone
|
||||
export class DateSerializer {
|
||||
static toLocalTime(date: Date): string | null {
|
||||
if (!date) return null;
|
||||
|
||||
// Convert UTC date to Thailand timezone (+07:00)
|
||||
const offset = 7 * 60; // Thailand is UTC+7
|
||||
const localTime = new Date(date.getTime() + offset * 60 * 1000);
|
||||
|
||||
// Format as ISO string but replace Z with +07:00
|
||||
const isoString = localTime.toISOString();
|
||||
return isoString.replace("Z", "+07:00");
|
||||
}
|
||||
|
||||
static setupDateSerialization() {
|
||||
// Override Date.prototype.toJSON to use local time
|
||||
Date.prototype.toJSON = function () {
|
||||
const offset = 7 * 60; // Thailand timezone offset in minutes
|
||||
const localTime = new Date(this.getTime() + offset * 60 * 1000);
|
||||
const isoString = localTime.toISOString();
|
||||
return isoString.replace("Z", "+07:00");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -69,6 +69,12 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
|||
if (req.url.startsWith("/api/v1/org/profile/")) system = "registry";
|
||||
if (req.url.startsWith("/api/v1/org/profile-employee/")) system = "registry";
|
||||
if (req.url.startsWith("/api/v1/org/profile-temp/")) system = "registry";
|
||||
|
||||
if (req.url.startsWith("/api/v1/org/commandType/admin")) system = "admin";
|
||||
if (req.url.startsWith("/api/v1/org/commandSys/")) system = "admin";
|
||||
if (req.url.startsWith("/api/v1/org/commandSalary/")) system = "admin";
|
||||
if (req.url.startsWith("/api/v1/org/apiKey/")) system = "admin";
|
||||
if (req.url.startsWith("/api/v1/org/api-manage/")) system = "admin";
|
||||
|
||||
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
|
||||
const profileByKeycloak = await repoProfile.findOne({
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class Update2107202611411754401420685 implements MigrationInterface {
|
||||
name = 'Update2107202611411754401420685'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`posNo\` varchar(255) NULL COMMENT 'เลขที่ตำแหน่ง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`birthDateOld\` datetime NULL COMMENT 'วันเกิดเดิม โดยจะบันทึกเมื่อมีการแก้ไขข้อมูลส่วนตัว'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`birthDateOld\` datetime NULL COMMENT 'วันเกิดเดิม โดยจะบันทึกเมื่อมีการแก้ไขข้อมูลส่วนตัว'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileTraining\` CHANGE \`isEntry\` \`isEntry\` tinyint NOT NULL COMMENT 'ข้อมูลจาก Entry' DEFAULT 0`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaStateOperator\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaStateOperator\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaWorkflow\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaWorkflow\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaState\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaState\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD CONSTRAINT \`FK_f1ded3e1f83ab2437f739a14f38\` FOREIGN KEY (\`profileSalaryId\`) REFERENCES \`profileSalary\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP FOREIGN KEY \`FK_f1ded3e1f83ab2437f739a14f38\``);
|
||||
await queryRunner.query(`ALTER TABLE \`metaState\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaState\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaWorkflow\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaWorkflow\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaStateOperator\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string'`);
|
||||
await queryRunner.query(`ALTER TABLE \`metaStateOperator\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileTraining\` CHANGE \`isEntry\` \`isEntry\` tinyint NOT NULL DEFAULT '0'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`birthDateOld\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`birthDateOld\``);
|
||||
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`posNo\``);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,20 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateRegistryFixLengthPrefix1756357065498 implements MigrationInterface {
|
||||
name = 'UpdateRegistryFixLengthPrefix1756357065498'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`prefix\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`prefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ เช่น นาย นาง นางสาว'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`prefix\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`prefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ เช่น นาย นาง นางสาว'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`prefix\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`prefix\` varchar(20) NULL COMMENT 'คำนำหน้าชื่อ เช่น นาย นาง นางสาว'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`prefix\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`prefix\` varchar(20) NULL COMMENT 'คำนำหน้าชื่อ เช่น นาย นาง นางสาว'`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateRegistrymployereAddFieldEmployeeClass1756364862810 implements MigrationInterface {
|
||||
name = 'UpdateRegistrymployereAddFieldEmployeeClass1756364862810'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`employeeClass\` varchar(40) NULL COMMENT 'ประเภทลูกจ้าง (perm->ลูกจ้างประจำ temp->ลูกจ้างชั่วคราว)'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`employeeClass\``);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateDataTypeFieldsRegistryAndRegistryEmpployee1757484721787 implements MigrationInterface {
|
||||
name = 'UpdateDataTypeFieldsRegistryAndRegistryEmpployee1757484721787'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`degrees\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`degrees\` text NULL COMMENT 'วุฒิการศึกษา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`educationLevels\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`educationLevels\` text NULL COMMENT 'ระดับศึกษา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`fields\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`fields\` text NULL COMMENT 'สาขาวิชา/ทาง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`degrees\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`degrees\` text NULL COMMENT 'วุฒิการศึกษา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`educationLevels\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`educationLevels\` text NULL COMMENT 'ระดับศึกษา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`fields\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`fields\` text NULL COMMENT 'สาขาวิชา/ทาง'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`fields\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`fields\` varchar(255) NULL COMMENT 'สาขาวิชา/ทาง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`educationLevels\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`educationLevels\` varchar(255) NULL COMMENT 'ระดับศึกษา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` DROP COLUMN \`degrees\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registryEmployee\` ADD \`degrees\` varchar(255) NULL COMMENT 'วุฒิการศึกษา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`fields\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`fields\` varchar(255) NULL COMMENT 'สาขาวิชา/ทาง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`educationLevels\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`educationLevels\` varchar(255) NULL COMMENT 'ระดับศึกษา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` DROP COLUMN \`degrees\``);
|
||||
await queryRunner.query(`ALTER TABLE \`registry\` ADD \`degrees\` varchar(255) NULL COMMENT 'วุฒิการศึกษา'`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableApiKeyAddAccessType1761330464755 implements MigrationInterface {
|
||||
name = 'UpdateTableApiKeyAddAccessType1761330464755'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`accessType\` varchar(40) NULL COMMENT 'accessType'`);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`dnaRootId\` varchar(40) NULL COMMENT 'dnaRootId'`);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`dnaChild1Id\` varchar(40) NULL COMMENT 'dnaChild1Id'`);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`dnaChild2Id\` varchar(40) NULL COMMENT 'dnaChild2Id'`);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`dnaChild3Id\` varchar(40) NULL COMMENT 'dnaChild3Id'`);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`dnaChild4Id\` varchar(40) NULL COMMENT 'dnaChild4Id'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`dnaChild4Id\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`dnaChild3Id\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`dnaChild2Id\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`dnaChild1Id\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`dnaRootId\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`accessType\``);
|
||||
}
|
||||
|
||||
}
|
||||
17
src/migration/1762159481993-update_size_keyapi_field.ts
Normal file
17
src/migration/1762159481993-update_size_keyapi_field.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateSizeKeyapiField1762159481993 implements MigrationInterface {
|
||||
name = 'UpdateSizeKeyapiField1762159481993'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`keyApi\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`keyApi\` longtext NULL COMMENT 'keyApi'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`keyApi\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`keyApi\` varchar(255) NULL COMMENT 'keyApi'`);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
16
src/migration/1762159824907-update_size_place_field.ts
Normal file
16
src/migration/1762159824907-update_size_place_field.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateSizePlaceField1762159824907 implements MigrationInterface {
|
||||
name = 'UpdateSizePlaceField1762159824907'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP COLUMN \`place\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD \`place\` longtext NULL COMMENT 'สถานที่ฝึกอบรม/ดูงาน'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP COLUMN \`place\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD \`place\` varchar(200) NULL COMMENT 'สถานที่ฝึกอบรม/ดูงาน '`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddFieldIsAdminVisibledTableAuthRole1762165716863 implements MigrationInterface {
|
||||
name = 'AddFieldIsAdminVisibledTableAuthRole1762165716863'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`authRole\` ADD \`isAdminVisibled\` tinyint NULL COMMENT 'ข้อมูลที่ role admin สามารถเห็นได้'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`authRole\` DROP COLUMN \`isAdminVisibled\``);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateSizeHeaderApiAndTokenApiFieldApiHistoryTable1762243747843 implements MigrationInterface {
|
||||
name = 'UpdateSizeHeaderApiAndTokenApiFieldApiHistoryTable1762243747843'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`headerApi\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`headerApi\` longtext NULL COMMENT 'header'`);
|
||||
await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`tokenApi\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`tokenApi\` longtext NULL COMMENT 'token'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`tokenApi\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`tokenApi\` varchar(255) NULL COMMENT 'token'`);
|
||||
await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`headerApi\``);
|
||||
await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`headerApi\` varchar(255) NULL COMMENT 'header'`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,292 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateViewDirectiorAndViewDirectiorActing1762489522691 implements MigrationInterface {
|
||||
name = 'UpdateViewDirectiorAndViewDirectiorActing1762489522691'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW", "view_director_acting", "hrms_organization"]);
|
||||
await queryRunner.query(`DROP VIEW IF EXISTS \`view_director_acting\``);
|
||||
// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_director", "SELECT \n profile.id AS Id,\n profile.prefix AS prefix,\n profile.firstName AS firstName,\n profile.lastName AS lastName,\n profile.citizenId AS citizenId,\n profile.position AS position,\n CONCAT(\n CASE \n WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName\n WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName\n WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName\n WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName\n ELSE orgChild4.orgChild4ShortName\n END,\n posMaster.posMasterNo\n ) AS posNo,\n posMaster.isDirector AS isDirector,\n posLevel.posLevelName AS posLevel,\n posType.posTypeName AS posType,\n posExecutive.posExecutiveName AS posExecutiveName,\n orgRoot.isDeputy AS isDeputy,\n orgChild1.isOfficer AS isOfficer,\n posMaster.orgRevisionId AS orgRevisionId,\n posMaster.orgRootId AS orgRootId,\n posMaster.orgChild1Id AS orgChild1Id,\n posMaster.orgChild2Id AS orgChild2Id,\n posMaster.orgChild3Id AS orgChild3Id,\n posMaster.orgChild4Id AS orgChild4Id,\n CONCAT(posMaster.id, profile.id) AS `key`,\n (\n SELECT hrms_organization.acting.actFullNameKeycloakId\n FROM hrms_organization.view_director_acting acting\n WHERE ((hrms_organization.acting.Id = hrms_organization.posMaster.current_holderId)\n AND (hrms_organization.acting.orgRootId = hrms_organization.posMaster.orgRootId)\n AND ((hrms_organization.acting.orgChild1Id = hrms_organization.posMaster.orgChild1Id)\n OR (hrms_organization.acting.orgChild1Id IS NULL))\n AND ((hrms_organization.acting.orgChild2Id = hrms_organization.posMaster.orgChild2Id)\n OR (hrms_organization.acting.orgChild2Id IS NULL))\n AND ((hrms_organization.acting.orgChild3Id = hrms_organization.posMaster.orgChild3Id)\n OR (hrms_organization.acting.orgChild3Id IS NULL))\n AND ((hrms_organization.acting.orgChild4Id = hrms_organization.posMaster.orgChild4Id)\n OR (hrms_organization.acting.orgChild4Id IS NULL)))\n LIMIT 1\n ) AS actFullNameKeycloakId,\n (\n SELECT actFullNameId \n FROM view_director_acting AS acting\n WHERE acting.Id = posMaster.current_holderId \n AND acting.orgRootId = posMaster.orgRootId \n AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)\n AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)\n AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)\n AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)\n LIMIT 1\n ) AS actFullNameId,\n (\n SELECT actFullName \n FROM view_director_acting AS acting\n WHERE acting.Id = posMaster.current_holderId \n AND acting.orgRootId = posMaster.orgRootId \n AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)\n AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)\n AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)\n AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)\n LIMIT 1\n ) AS actFullName\n FROM\n posMaster\n JOIN profile ON posMaster.current_holderId = profile.id\n LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id\n LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id\n LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id\n LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id\n LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id\n JOIN posLevel ON profile.posLevelId = posLevel.id\n JOIN posType ON profile.posTypeId = posType.id\n LEFT JOIN position ON posMaster.id = position.posMasterId\n LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id\n INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id\n WHERE\n (position.positionIsSelected = TRUE)\n AND (orgRevision.orgRevisionIsCurrent = TRUE\n AND orgRevision.orgRevisionIsDraft = FALSE)"]);
|
||||
await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT
|
||||
\`profileChild\`.\`id\` AS \`Id\`,
|
||||
\`profileChild\`.\`prefix\` AS \`prefix\`,
|
||||
\`profileChild\`.\`firstName\` AS \`firstName\`,
|
||||
\`profileChild\`.\`lastName\` AS \`lastName\`,
|
||||
\`profileChild\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`profileChild\`.\`position\` AS \`position\`,
|
||||
\`profile\`.\`isProbation\` AS \`isProbation\`,
|
||||
CONCAT((CASE
|
||||
WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\`
|
||||
WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\`
|
||||
WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\`
|
||||
WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\`
|
||||
ELSE \`orgChild4Child\`.\`orgChild4ShortName\`
|
||||
END),
|
||||
\`posMaster\`.\`posMasterNo\`) AS \`posNo\`,
|
||||
\`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`,
|
||||
\`posMaster\`.\`isDirector\` AS \`isDirector\`,
|
||||
\`posLevel\`.\`posLevelName\` AS \`posLevel\`,
|
||||
\`posType\`.\`posTypeName\` AS \`posType\`,
|
||||
\`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`,
|
||||
\`orgRoot\`.\`isDeputy\` AS \`isDeputy\`,
|
||||
\`orgChild1\`.\`isOfficer\` AS \`isOfficer\`,
|
||||
\`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`,
|
||||
\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
|
||||
\`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`,
|
||||
\`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`,
|
||||
\`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`,
|
||||
\`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`,
|
||||
CONCAT(\`hrms_organization\`.\`profile\`.\`keycloak\`) AS \`actFullNameKeycloakId\`,
|
||||
CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`,
|
||||
\`profile\`.\`id\` AS \`actFullNameId\`,
|
||||
CONCAT(\`profile\`.\`prefix\`,
|
||||
\`profile\`.\`firstName\`,
|
||||
' ',
|
||||
\`profile\`.\`lastName\`) AS \`actFullName\`
|
||||
FROM
|
||||
(((((((((((((((\`posMasterAct\`
|
||||
JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`)))
|
||||
JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`)))
|
||||
LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`)))
|
||||
JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`)))
|
||||
JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`)))
|
||||
JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`)))
|
||||
LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`)))
|
||||
JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`)))
|
||||
LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`)))
|
||||
LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`)))
|
||||
WHERE
|
||||
(\`position\`.\`positionIsSelected\` = TRUE)`);
|
||||
|
||||
await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW", "view_director", "hrms_organization"]);
|
||||
await queryRunner.query(`DROP VIEW IF EXISTS \`view_director\``);
|
||||
// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_employee_pos_master", "SELECT \n employeePosMaster.id,\n employeePosMaster.posMasterNoPrefix,\n employeePosMaster.posMasterNo,\n employeePosMaster.posMasterNoSuffix,\n employeePosMaster.orgRevisionId,\n employeePosMaster.orgRootId,\n employeePosMaster.orgChild1Id,\n employeePosMaster.orgChild2Id,\n employeePosMaster.orgChild3Id,\n employeePosMaster.orgChild4Id,\n employeePosMaster.current_holderId,\n profileEmployee.id as profileId,\n profileEmployee.prefix,\n profileEmployee.firstName,\n profileEmployee.lastName,\n profileEmployee.citizenId,\n profileEmployee.position,\n profileEmployee.amount,\n profileEmployee.dateRetire,\n profileEmployee.birthDate,\n profileEmployee.salaryLevel,\n profileEmployee.group,\n orgRoot.id as rootId,\n orgRoot.orgRootShortName,\n orgRoot.orgRootOrder,\n orgRoot.orgRootName,\n orgChild1.id as child1Id,\n orgChild1.orgChild1ShortName,\n orgChild1.orgChild1Order,\n orgChild1.orgChild1Name,\n orgChild2.id as child2Id,\n orgChild2.orgChild2ShortName,\n orgChild2.orgChild2Order,\n orgChild2.orgChild2Name,\n orgChild3.id as child3Id,\n orgChild3.orgChild3ShortName,\n orgChild3.orgChild3Order,\n orgChild3.orgChild3Name,\n orgChild4.id as child4Id,\n orgChild4.orgChild4ShortName,\n orgChild4.orgChild4Order,\n orgChild4.orgChild4Name,\n position.id as positionId,\n position.positionIsSelected,\n position.posExecutiveId as positionPosExecutiveId,\n position.isSpecial,\n posExecutive.id as posExecutiveId,\n posExecutive.posExecutiveName,\n profileDiscipline.id as profileDisciplineId,\n profileDiscipline.date as disCriplineDate,\n profileLeave.id as profileLeaveId,\n profileAssessment.id as profileAssessmentId,\n profileAssessment.pointSum,\n employeePosLevel.id as posLevelId,\n employeePosLevel.posLevelName,\n\temployeePosType.id as posTypeId,\n employeePosType.posTypeName,\n employeePosType.posTypeShortName\n FROM \n employeePosMaster\n LEFT JOIN \n profileEmployee ON employeePosMaster.current_holderId = profileEmployee.id \n LEFT JOIN \n orgRoot ON employeePosMaster.orgRootId = orgRoot.id\n LEFT JOIN \n orgChild1 ON employeePosMaster.orgChild1Id = orgChild1.id\n LEFT JOIN \n orgChild2 ON employeePosMaster.orgChild2Id = orgChild2.id\n LEFT JOIN \n orgChild3 ON employeePosMaster.orgChild3Id = orgChild3.id\n LEFT JOIN \n orgChild4 ON employeePosMaster.orgChild4Id = orgChild4.id\n LEFT JOIN \n position ON employeePosMaster.id = position.posMasterId\n LEFT JOIN \n posExecutive ON position.posExecutiveId = posExecutive.id\n LEFT JOIN (\n SELECT *\n FROM profileDisciplineEmployee pd1\n WHERE pd1.date = (\n SELECT MAX(pd2.date)\n FROM profileDisciplineEmployee pd2\n WHERE pd2.profileId = pd1.profileId\n )\n ) AS profileDiscipline ON profileDiscipline.profileId = profileEmployee.id\n LEFT JOIN (\n SELECT pl1.*\n FROM profileLeave pl1\n INNER JOIN (\n SELECT profileId, MAX(createdAt) AS maxDate\n FROM profileLeave\n GROUP BY profileId\n ) pl2 ON pl1.profileId = pl2.profileId\n AND pl1.createdAt = pl2.maxDate\n ) AS profileLeave ON profileLeave.profileId = employeePosMaster.current_holderId\n LEFT JOIN (\n SELECT pa1.*\n FROM profileAssessment pa1\n INNER JOIN (\n SELECT profileId, MAX(createdAt) AS maxDate\n FROM profileAssessment\n GROUP BY profileId\n ) pa2 ON pa1.profileId = pa2.profileId\n AND pa1.createdAt = pa2.maxDate\n ) AS profileAssessment \n ON profileAssessment.profileId = profileEmployee.id\n LEFT JOIN \n employeePosLevel ON profileEmployee.posLevelId = employeePosLevel.id\n LEFT JOIN \n employeePosType ON profileEmployee.posTypeId = employeePosType.id\n WHERE \t\n employeePosMaster.current_holderId IS NOT NULL\n ORDER BY \n profileEmployee.citizenId ASC"]);
|
||||
await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT
|
||||
profile.id AS Id,
|
||||
profile.prefix AS prefix,
|
||||
profile.firstName AS firstName,
|
||||
profile.lastName AS lastName,
|
||||
profile.citizenId AS citizenId,
|
||||
profile.position AS position,
|
||||
profile.keycloak AS keycloakId,
|
||||
profile.isProbation AS isProbation,
|
||||
CONCAT(
|
||||
CASE
|
||||
WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName
|
||||
WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName
|
||||
WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName
|
||||
WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName
|
||||
ELSE orgChild4.orgChild4ShortName
|
||||
END,
|
||||
posMaster.posMasterNo
|
||||
) AS posNo,
|
||||
posMaster.isDirector AS isDirector,
|
||||
posLevel.posLevelName AS posLevel,
|
||||
posType.posTypeName AS posType,
|
||||
posExecutive.posExecutiveName AS posExecutiveName,
|
||||
orgRoot.isDeputy AS isDeputy,
|
||||
orgChild1.isOfficer AS isOfficer,
|
||||
posMaster.orgRevisionId AS orgRevisionId,
|
||||
posMaster.orgRootId AS orgRootId,
|
||||
posMaster.orgChild1Id AS orgChild1Id,
|
||||
posMaster.orgChild2Id AS orgChild2Id,
|
||||
posMaster.orgChild3Id AS orgChild3Id,
|
||||
posMaster.orgChild4Id AS orgChild4Id,
|
||||
CONCAT(posMaster.id, profile.id) AS \`key\`,
|
||||
(
|
||||
SELECT hrms_organization.acting.actFullNameKeycloakId
|
||||
FROM hrms_organization.view_director_acting acting
|
||||
WHERE ((hrms_organization.acting.Id = hrms_organization.posMaster.current_holderId)
|
||||
AND (hrms_organization.acting.orgRootId = hrms_organization.posMaster.orgRootId)
|
||||
AND ((hrms_organization.acting.orgChild1Id = hrms_organization.posMaster.orgChild1Id)
|
||||
OR (hrms_organization.acting.orgChild1Id IS NULL))
|
||||
AND ((hrms_organization.acting.orgChild2Id = hrms_organization.posMaster.orgChild2Id)
|
||||
OR (hrms_organization.acting.orgChild2Id IS NULL))
|
||||
AND ((hrms_organization.acting.orgChild3Id = hrms_organization.posMaster.orgChild3Id)
|
||||
OR (hrms_organization.acting.orgChild3Id IS NULL))
|
||||
AND ((hrms_organization.acting.orgChild4Id = hrms_organization.posMaster.orgChild4Id)
|
||||
OR (hrms_organization.acting.orgChild4Id IS NULL)))
|
||||
LIMIT 1
|
||||
) AS actFullNameKeycloakId,
|
||||
(
|
||||
SELECT actFullNameId
|
||||
FROM view_director_acting AS acting
|
||||
WHERE acting.Id = posMaster.current_holderId
|
||||
AND acting.orgRootId = posMaster.orgRootId
|
||||
AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)
|
||||
AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)
|
||||
AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)
|
||||
AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)
|
||||
LIMIT 1
|
||||
) AS actFullNameId,
|
||||
(
|
||||
SELECT actFullName
|
||||
FROM view_director_acting AS acting
|
||||
WHERE acting.Id = posMaster.current_holderId
|
||||
AND acting.orgRootId = posMaster.orgRootId
|
||||
AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)
|
||||
AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)
|
||||
AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)
|
||||
AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)
|
||||
LIMIT 1
|
||||
) AS actFullName
|
||||
FROM
|
||||
posMaster
|
||||
JOIN profile ON posMaster.current_holderId = profile.id
|
||||
LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id
|
||||
LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id
|
||||
LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id
|
||||
LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id
|
||||
LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id
|
||||
JOIN posLevel ON profile.posLevelId = posLevel.id
|
||||
JOIN posType ON profile.posTypeId = posType.id
|
||||
LEFT JOIN position ON posMaster.id = position.posMasterId
|
||||
LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id
|
||||
INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id
|
||||
WHERE
|
||||
(position.positionIsSelected = TRUE)
|
||||
AND (orgRevision.orgRevisionIsCurrent = TRUE
|
||||
AND orgRevision.orgRevisionIsDraft = FALSE)`);
|
||||
|
||||
await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_current_tenure_employee", "WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileEmployeeId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileEmployeeId,\n NULL AS orderNumber\n FROM resultData"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW", "view_director_acting", "hrms_organization"]);
|
||||
await queryRunner.query(`DROP VIEW IF EXISTS \`view_director_acting\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT
|
||||
\`profileChild\`.\`id\` AS \`Id\`,
|
||||
\`profileChild\`.\`prefix\` AS \`prefix\`,
|
||||
\`profileChild\`.\`firstName\` AS \`firstName\`,
|
||||
\`profileChild\`.\`lastName\` AS \`lastName\`,
|
||||
\`profileChild\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`profileChild\`.\`position\` AS \`position\`,
|
||||
CONCAT((CASE
|
||||
WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\`
|
||||
WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\`
|
||||
WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\`
|
||||
WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\`
|
||||
ELSE \`orgChild4Child\`.\`orgChild4ShortName\`
|
||||
END),
|
||||
\`posMaster\`.\`posMasterNo\`) AS \`posNo\`,
|
||||
\`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`,
|
||||
\`posMaster\`.\`isDirector\` AS \`isDirector\`,
|
||||
\`posLevel\`.\`posLevelName\` AS \`posLevel\`,
|
||||
\`posType\`.\`posTypeName\` AS \`posType\`,
|
||||
\`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`,
|
||||
\`orgRoot\`.\`isDeputy\` AS \`isDeputy\`,
|
||||
\`orgChild1\`.\`isOfficer\` AS \`isOfficer\`,
|
||||
\`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`,
|
||||
\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
|
||||
\`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`,
|
||||
\`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`,
|
||||
\`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`,
|
||||
\`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`,
|
||||
CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`,
|
||||
\`profile\`.\`id\` AS \`actFullNameId\`,
|
||||
CONCAT(\`profile\`.\`prefix\`,
|
||||
\`profile\`.\`firstName\`,
|
||||
' ',
|
||||
\`profile\`.\`lastName\`) AS \`actFullName\`
|
||||
FROM
|
||||
(((((((((((((((\`posMasterAct\`
|
||||
JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`)))
|
||||
JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`)))
|
||||
LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`)))
|
||||
JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`)))
|
||||
JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`)))
|
||||
JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`)))
|
||||
LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`)))
|
||||
LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`)))
|
||||
JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`)))
|
||||
LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`)))
|
||||
LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`)))
|
||||
WHERE
|
||||
(\`position\`.\`positionIsSelected\` = TRUE)`);
|
||||
|
||||
// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_director_acting", "SELECT \n `profileChild`.`id` AS `Id`,\n `profileChild`.`prefix` AS `prefix`,\n `profileChild`.`firstName` AS `firstName`,\n `profileChild`.`lastName` AS `lastName`,\n `profileChild`.`citizenId` AS `citizenId`,\n `profileChild`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`posMaster`.`orgChild1Id` IS NULL) THEN `orgRootChild`.`orgRootShortName`\n WHEN (`posMaster`.`orgChild2Id` IS NULL) THEN `orgChild1Child`.`orgChild1ShortName`\n WHEN (`posMaster`.`orgChild3Id` IS NULL) THEN `orgChild2Child`.`orgChild2ShortName`\n WHEN (`posMaster`.`orgChild4Id` IS NULL) THEN `orgChild3Child`.`orgChild3ShortName`\n ELSE `orgChild4Child`.`orgChild4ShortName`\n END),\n `posMaster`.`posMasterNo`) AS `posNo`,\n `posMasterChild`.`isDirector` AS `isDirectorChild`,\n `posMaster`.`isDirector` AS `isDirector`,\n `posLevel`.`posLevelName` AS `posLevel`,\n `posType`.`posTypeName` AS `posType`,\n `posExecutive`.`posExecutiveName` AS `posExecutiveName`,\n `orgRoot`.`isDeputy` AS `isDeputy`,\n `orgChild1`.`isOfficer` AS `isOfficer`,\n `posMaster`.`orgRevisionId` AS `orgRevisionId`,\n `posMaster`.`orgRootId` AS `orgRootId`,\n `posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`posMaster`.`id`, `profileChild`.`id`) AS `key`,\n `profile`.`id` AS `actFullNameId`,\n CONCAT(`profile`.`prefix`,\n `profile`.`firstName`,\n ' ',\n `profile`.`lastName`) AS `actFullName`\n FROM\n (((((((((((((((`posMasterAct`\n JOIN `posMaster` `posMasterChild` ON ((`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`)))\n JOIN `profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`)))\n LEFT JOIN `orgRoot` `orgRootChild` ON ((`posMasterChild`.`orgRootId` = `orgRootChild`.`id`)))\n LEFT JOIN `orgChild1` `orgChild1Child` ON ((`posMasterChild`.`orgChild1Id` = `orgChild1Child`.`id`)))\n LEFT JOIN `orgChild2` `orgChild2Child` ON ((`posMasterChild`.`orgChild2Id` = `orgChild2Child`.`id`)))\n LEFT JOIN `orgChild3` `orgChild3Child` ON ((`posMasterChild`.`orgChild3Id` = `orgChild3Child`.`id`)))\n LEFT JOIN `orgChild4` `orgChild4Child` ON ((`posMasterChild`.`orgChild4Id` = `orgChild4Child`.`id`)))\n JOIN `posLevel` ON ((`profileChild`.`posLevelId` = `posLevel`.`id`)))\n JOIN `posType` ON ((`profileChild`.`posTypeId` = `posType`.`id`)))\n JOIN `posMaster` ON ((`posMasterAct`.`posMasterId` = `posMaster`.`id`)))\n LEFT JOIN `orgRoot` ON ((`posMaster`.`orgRootId` = `orgRoot`.`id`)))\n LEFT JOIN `orgChild1` ON ((`posMaster`.`orgChild1Id` = `orgChild1`.`id`)))\n JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`)))\n LEFT JOIN `position` ON ((`posMasterChild`.`id` = `position`.`posMasterId`)))\n LEFT JOIN `posExecutive` ON ((`position`.`posExecutiveId` = `posExecutive`.`id`)))\n WHERE\n (`position`.`positionIsSelected` = TRUE)"]);
|
||||
await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW", "view_director", "hrms_organization"]);
|
||||
await queryRunner.query(`DROP VIEW IF EXISTS \`view_director\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT
|
||||
profile.id AS Id,
|
||||
profile.prefix AS prefix,
|
||||
profile.firstName AS firstName,
|
||||
profile.lastName AS lastName,
|
||||
profile.citizenId AS citizenId,
|
||||
profile.position AS position,
|
||||
CONCAT(
|
||||
CASE
|
||||
WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName
|
||||
WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName
|
||||
WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName
|
||||
WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName
|
||||
ELSE orgChild4.orgChild4ShortName
|
||||
END,
|
||||
posMaster.posMasterNo
|
||||
) AS posNo,
|
||||
posMaster.isDirector AS isDirector,
|
||||
posLevel.posLevelName AS posLevel,
|
||||
posType.posTypeName AS posType,
|
||||
posExecutive.posExecutiveName AS posExecutiveName,
|
||||
orgRoot.isDeputy AS isDeputy,
|
||||
orgChild1.isOfficer AS isOfficer,
|
||||
posMaster.orgRevisionId AS orgRevisionId,
|
||||
posMaster.orgRootId AS orgRootId,
|
||||
posMaster.orgChild1Id AS orgChild1Id,
|
||||
posMaster.orgChild2Id AS orgChild2Id,
|
||||
posMaster.orgChild3Id AS orgChild3Id,
|
||||
posMaster.orgChild4Id AS orgChild4Id,
|
||||
CONCAT(posMaster.id, profile.id) AS \`key\`,
|
||||
(
|
||||
SELECT actFullNameId
|
||||
FROM view_director_acting AS acting
|
||||
WHERE acting.Id = posMaster.current_holderId
|
||||
AND acting.orgRootId = posMaster.orgRootId
|
||||
AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)
|
||||
AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)
|
||||
AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)
|
||||
AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)
|
||||
LIMIT 1
|
||||
) AS actFullNameId,
|
||||
(
|
||||
SELECT actFullName
|
||||
FROM view_director_acting AS acting
|
||||
WHERE acting.Id = posMaster.current_holderId
|
||||
AND acting.orgRootId = posMaster.orgRootId
|
||||
AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)
|
||||
AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)
|
||||
AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)
|
||||
AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)
|
||||
LIMIT 1
|
||||
) AS actFullName
|
||||
FROM
|
||||
posMaster
|
||||
JOIN profile ON posMaster.current_holderId = profile.id
|
||||
LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id
|
||||
LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id
|
||||
LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id
|
||||
LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id
|
||||
LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id
|
||||
JOIN posLevel ON profile.posLevelId = posLevel.id
|
||||
JOIN posType ON profile.posTypeId = posType.id
|
||||
LEFT JOIN position ON posMaster.id = position.posMasterId
|
||||
LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id
|
||||
INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id
|
||||
WHERE
|
||||
(position.positionIsSelected = TRUE)
|
||||
AND (orgRevision.orgRevisionIsCurrent = TRUE
|
||||
AND orgRevision.orgRevisionIsDraft = FALSE)`);
|
||||
|
||||
// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_director", "SELECT \n profile.id AS Id,\n profile.prefix AS prefix,\n profile.firstName AS firstName,\n profile.lastName AS lastName,\n profile.citizenId AS citizenId,\n profile.position AS position,\n CONCAT(\n CASE \n WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName\n WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName\n WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName\n WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName\n ELSE orgChild4.orgChild4ShortName\n END,\n posMaster.posMasterNo\n ) AS posNo,\n posMaster.isDirector AS isDirector,\n posLevel.posLevelName AS posLevel,\n posType.posTypeName AS posType,\n posExecutive.posExecutiveName AS posExecutiveName,\n orgRoot.isDeputy AS isDeputy,\n orgChild1.isOfficer AS isOfficer,\n posMaster.orgRevisionId AS orgRevisionId,\n posMaster.orgRootId AS orgRootId,\n posMaster.orgChild1Id AS orgChild1Id,\n posMaster.orgChild2Id AS orgChild2Id,\n posMaster.orgChild3Id AS orgChild3Id,\n posMaster.orgChild4Id AS orgChild4Id,\n CONCAT(posMaster.id, profile.id) AS `key`,\n (\n SELECT actFullNameId \n FROM view_director_acting AS acting\n WHERE acting.Id = posMaster.current_holderId \n AND acting.orgRootId = posMaster.orgRootId \n AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)\n AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)\n AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)\n AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)\n LIMIT 1\n ) AS actFullNameId,\n (\n SELECT actFullName \n FROM view_director_acting AS acting\n WHERE acting.Id = posMaster.current_holderId \n AND acting.orgRootId = posMaster.orgRootId \n AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)\n AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)\n AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)\n AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)\n LIMIT 1\n ) AS actFullName\n FROM\n posMaster\n JOIN profile ON posMaster.current_holderId = profile.id\n LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id\n LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id\n LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id\n LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id\n LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id\n JOIN posLevel ON profile.posLevelId = posLevel.id\n JOIN posType ON profile.posTypeId = posType.id\n LEFT JOIN position ON posMaster.id = position.posMasterId\n LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id\n INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id\n WHERE\n (position.positionIsSelected = TRUE)\n AND (orgRevision.orgRevisionIsCurrent = TRUE\n AND orgRevision.orgRevisionIsDraft = FALSE)"]);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue