Merge branch 'develop' into dev
* develop: test api-key delete comment add read me test update log fix #1948 , #1950 , #1951 revert fix and test test fix test #1945 fix check api-key update update clear user in org draft #1831
This commit is contained in:
commit
0ebcdbc284
14 changed files with 784 additions and 453 deletions
109
README.md
109
README.md
|
|
@ -1 +1,108 @@
|
|||
# bma-ehr-organization
|
||||
# hrms-api-org
|
||||
|
||||
ระบบ API สำหรับจัดการข้อมูลบุคลากรและโครงสร้างองค์กร (HRMS)
|
||||
|
||||
---
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- **RESTful API** (Express)
|
||||
- **ฐานข้อมูล MySQL** (TypeORM)
|
||||
- **Cronjob อัตโนมัติ** (node-cron)
|
||||
- **WebSocket** สำหรับ real-time
|
||||
- **RabbitMQ integration**
|
||||
- **Swagger UI** สำหรับ API docs
|
||||
- รองรับการ **import/export ข้อมูล**
|
||||
|
||||
---
|
||||
|
||||
## 🗂️ โครงสร้างโปรเจกต์หลัก
|
||||
|
||||
| Path | รายละเอียด |
|
||||
| ----------------------------------- | ------------------------------------- |
|
||||
| `src/controllers/` | API Controllers |
|
||||
| `src/entities/` | Entity สำหรับ TypeORM |
|
||||
| `src/services/` | Service logic (RabbitMQ, WebSocket) |
|
||||
| `src/database/data-source.ts` | ตั้งค่าเชื่อมต่อฐานข้อมูล |
|
||||
| `src/migration/` | ไฟล์ migration ของฐานข้อมูล |
|
||||
| `static/` | ไฟล์ static และ config |
|
||||
| `scripts/clean-migration-fk-idx.js` | สคริปต์ลบบรรทัด FK*/idx* ใน migration |
|
||||
|
||||
---
|
||||
|
||||
## 🚀 การใช้งานเบื้องต้น
|
||||
|
||||
1. **ติดตั้ง dependencies**
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
|
||||
2. **สร้างไฟล์ `.env`**
|
||||
|
||||
- กำหนดค่าฐานข้อมูลและ API_KEY ตามต้องการ
|
||||
|
||||
3. **Build และ Start**
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
npm start
|
||||
```
|
||||
|
||||
4. **ดู API docs**
|
||||
- เปิดที่ `http://localhost:3000/api-docs`
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ คำสั่งที่สำคัญ (npm scripts)
|
||||
|
||||
- `npm run dev` : รันแบบ development (hot reload)
|
||||
- `npm run build` : สร้างไฟล์สำหรับ production
|
||||
- `npm run migration:generate` : สร้าง migration ใหม่ เช่น
|
||||
|
||||
```sh
|
||||
npm run migration:generate src/migration/update_table_0811202s
|
||||
```
|
||||
|
||||
- `npm run migration:run` : รัน migration
|
||||
- `node scripts/clean-migration-fk-idx.js` : ลบบรรทัดที่มี `FK_` หรือ `idx_` ใน migration อัตโนมัติ (ควรรันหลัง gen migration ทุกครั้ง)
|
||||
|
||||
---
|
||||
|
||||
## 🐳 การ Build/Deploy ด้วย act (local GitHub Actions)
|
||||
|
||||
หากต้องการ build และ deploy ด้วย workflow release (เช่น ทดสอบ pipeline บนเครื่อง)
|
||||
ให้ใช้คำสั่งนี้:
|
||||
|
||||
```sh
|
||||
act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
|
||||
```
|
||||
|
||||
**อธิบาย option ที่ใช้:**
|
||||
|
||||
- `-W .github/workflows/release.yaml` : ระบุ workflow ที่จะรัน
|
||||
- `--input IMAGE_VER=latest` : กำหนด tag ของ docker image (เช่น latest)
|
||||
- `-s DOCKER_USER=...` : กำหนด secret สำหรับ docker registry
|
||||
- `-s DOCKER_PASS=...` : กำหนด secret สำหรับ docker registry
|
||||
- `-s SSH_PASSWORD=...` : กำหนด secret สำหรับ ssh deploy
|
||||
|
||||
> ⚠️ **หมายเหตุ:** สำหรับ production ห้ามใช้รหัสผ่านจริงใน public repo หรือแชร์ credentials
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ หมายเหตุเกี่ยวกับ Migration
|
||||
|
||||
- หลังจากใช้ `npm run migration:generate` แล้ว **ต้องลบบรรทัดที่มี `FK_` หรือ `idx_` ออกจากไฟล์ migration ทุกครั้ง** (ทั้งในฟังก์ชัน up/down)
|
||||
- สามารถใช้สคริปต์นี้ช่วยลบอัตโนมัติ:
|
||||
|
||||
```sh
|
||||
node scripts/clean-migration-fk-idx.js
|
||||
```
|
||||
|
||||
- สคริปต์นี้จะค้นหาและแทนที่บรรทัดที่มี `FK_` หรือ `idx_` ด้วย comment `// removed FK_/idx_ auto-cleanup` ในทุกไฟล์ migration
|
||||
|
||||
---
|
||||
|
||||
## 📄 License
|
||||
|
||||
Distributed under the ISC License.
|
||||
|
|
|
|||
37
scripts/clean-migration-fk-idx.js
Normal file
37
scripts/clean-migration-fk-idx.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Script: scripts/clean-migration-fk-idx.js
|
||||
// ลบบรรทัดที่มี FK_ หรือ idx_ ในไฟล์ migration ทั้งหมด และแทนที่ด้วย comment
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const MIGRATION_DIR = path.join(__dirname, "../src/migration");
|
||||
|
||||
function processFile(filePath) {
|
||||
const lines = fs.readFileSync(filePath, "utf8").split("\n");
|
||||
let changed = false;
|
||||
const newLines = lines.map((line) => {
|
||||
if (/FK_|idx_/.test(line)) {
|
||||
changed = true;
|
||||
return " // removed FK_/idx_ auto-cleanup";
|
||||
}
|
||||
return line;
|
||||
});
|
||||
if (changed) {
|
||||
fs.writeFileSync(filePath, newLines.join("\n"), "utf8");
|
||||
console.log("Cleaned:", filePath);
|
||||
}
|
||||
}
|
||||
|
||||
function walk(dir) {
|
||||
fs.readdirSync(dir).forEach((f) => {
|
||||
const fullPath = path.join(dir, f);
|
||||
if (fs.statSync(fullPath).isDirectory()) {
|
||||
walk(fullPath);
|
||||
} else if (f.endsWith(".ts")) {
|
||||
processFile(fullPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
walk(MIGRATION_DIR);
|
||||
console.log("Migration FK_/idx_ cleanup complete.");
|
||||
|
|
@ -4272,6 +4272,16 @@ export class CommandController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
|
||||
}
|
||||
|
||||
// const orgRevision = await this.orgRevisionRepo.findOne({
|
||||
// where: {
|
||||
// orgRevisionIsCurrent: true,
|
||||
// orgRevisionIsDraft: false,
|
||||
// },
|
||||
// });
|
||||
|
||||
// const orgRevisionRef =
|
||||
// profile?.current_holders?.find((x:any) => x.orgRevisionId == orgRevision?.id) ?? null;
|
||||
|
||||
//ลบตำแหน่งที่รักษาการแทน
|
||||
const code = _command?.commandType?.code;
|
||||
if (code && ["C-PM-13"].includes(code)) {
|
||||
|
|
@ -4300,6 +4310,9 @@ export class CommandController extends Controller {
|
|||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
if (item.isLeave != undefined && item.isLeave == true) {
|
||||
// if(orgRevisionRef){
|
||||
// await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE");
|
||||
// }
|
||||
await removeProfileInOrganize(profile.id, "OFFICER");
|
||||
}
|
||||
const clearProfile = await checkCommandType(String(item.commandId));
|
||||
|
|
@ -4628,8 +4641,8 @@ export class CommandController extends Controller {
|
|||
orgRevisionIsDraft: false,
|
||||
},
|
||||
});
|
||||
// const orgRevisionRef =
|
||||
// profile?.current_holders?.find((x) => x.orgRevisionId == orgRevision?.id) ?? null;
|
||||
const orgRevisionRef =
|
||||
profile?.current_holders?.find((x) => x.orgRevisionId == orgRevision?.id) ?? null;
|
||||
// const orgRootRef = orgRevisionRef?.orgRoot ?? null;
|
||||
// const orgChild1Ref = orgRevisionRef?.orgChild1 ?? null;
|
||||
// const orgChild2Ref = orgRevisionRef?.orgChild2 ?? null;
|
||||
|
|
@ -4770,6 +4783,9 @@ export class CommandController extends Controller {
|
|||
_profile.leaveDate = item.commandDateAffect ?? _null;
|
||||
_profile.leaveType = exceptClear.LeaveType ?? _null;
|
||||
} else {
|
||||
if(orgRevisionRef){
|
||||
await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE");
|
||||
}
|
||||
await removeProfileInOrganize(_profile.id, "OFFICER");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import { viewProfileEmployeeEvaluation } from "../entities/view/viewProfileEmplo
|
|||
import Extension from "../interfaces/extension";
|
||||
import { resetPassword } from "../keycloak";
|
||||
import { viewEmployeePosMaster } from "../entities/view/viewEmployeePosMaster";
|
||||
import { EmployeePosDict } from "../entities/EmployeePosDict";
|
||||
@Route("api/v1/org/unauthorize")
|
||||
@Tags("OrganizationUnauthorize")
|
||||
@Response(
|
||||
|
|
@ -37,6 +38,7 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
private viewProfileEmployeeEvaluationRepo = AppDataSource.getRepository(
|
||||
viewProfileEmployeeEvaluation,
|
||||
);
|
||||
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
|
||||
|
||||
@Post("user/reset-password")
|
||||
async forgetPassword(
|
||||
|
|
@ -1505,22 +1507,25 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. API Get Profile จาก keycloak id
|
||||
*
|
||||
* @summary 3. API Get Profile จาก keycloak id
|
||||
*
|
||||
* @param {string} keycloakId Id keycloak
|
||||
*/
|
||||
@Get("root/officer/{rootId}")
|
||||
async GetProfileByRootIdAsync(@Path() rootId: string) {
|
||||
const profiles = await this.profileRepo.find({
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
profileSalary: true,
|
||||
profileInsignias: true,
|
||||
},
|
||||
relations: [
|
||||
"posLevel",
|
||||
"posType",
|
||||
"profileSalary",
|
||||
"profileInsignias",
|
||||
"profileInsignias.insignia",
|
||||
"profileDisciplines",
|
||||
"profileAssessments",
|
||||
"current_holders",
|
||||
"current_holders.orgRevision",
|
||||
"current_holders.orgRoot",
|
||||
"current_holders.orgChild1",
|
||||
"current_holders.orgChild2",
|
||||
"current_holders.orgChild3",
|
||||
"current_holders.orgChild4",
|
||||
],
|
||||
where: { current_holders: { orgRootId: rootId } },
|
||||
order: {
|
||||
profileSalary: {
|
||||
|
|
@ -1531,55 +1536,267 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
},
|
||||
},
|
||||
});
|
||||
// if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const mapProfile = profiles.map((profile) => ({
|
||||
id: profile.id,
|
||||
avatar: profile.avatar,
|
||||
avatarName: profile.avatarName,
|
||||
rank: profile.rank,
|
||||
prefix: profile.prefix,
|
||||
firstName: profile.firstName,
|
||||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
position: profile.position,
|
||||
posLevelId: profile.posLevelId,
|
||||
email: profile.email,
|
||||
phone: profile.phone,
|
||||
keycloak: profile.keycloak,
|
||||
isProbation: profile.isProbation,
|
||||
isLeave: profile.isLeave,
|
||||
leaveReason: profile.leaveReason,
|
||||
dateRetire: profile.dateRetire,
|
||||
dateAppoint: profile.dateAppoint,
|
||||
dateRetireLaw: profile.dateRetireLaw,
|
||||
dateStart: profile.dateStart,
|
||||
govAgeAbsent: profile.govAgeAbsent,
|
||||
govAgePlus: profile.govAgePlus,
|
||||
birthDate: profile.birthDate,
|
||||
reasonSameDate: profile.reasonSameDate,
|
||||
telephoneNumber: profile.phone,
|
||||
nationality: profile.nationality,
|
||||
gender: profile.gender,
|
||||
relationship: profile.relationship,
|
||||
religion: profile.religion,
|
||||
bloodGroup: profile.bloodGroup,
|
||||
registrationAddress: profile.registrationAddress,
|
||||
registrationProvinceId: profile.registrationProvinceId,
|
||||
registrationDistrictId: profile.registrationDistrictId,
|
||||
registrationSubDistrictId: profile.registrationSubDistrictId,
|
||||
registrationZipCode: profile.registrationZipCode,
|
||||
currentAddress: profile.currentAddress,
|
||||
currentProvinceId: profile.currentProvinceId,
|
||||
currentSubDistrictId: profile.currentSubDistrictId,
|
||||
currentZipCode: profile.currentZipCode,
|
||||
dutyTimeId: profile.dutyTimeId,
|
||||
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
|
||||
posLevel: profile.posLevel ? profile.posLevel : null,
|
||||
posType: profile.posType ? profile.posType : null,
|
||||
profileSalary: profile.profileSalary,
|
||||
profileInsignia: profile.profileInsignias,
|
||||
}));
|
||||
const currentYear = new Date().getFullYear();
|
||||
const years = [currentYear, currentYear - 1, currentYear - 2, currentYear - 3, currentYear - 4];
|
||||
|
||||
// APR Averages
|
||||
const aprAverages: { [year: number]: number | null } = {};
|
||||
const aprSums: { [year: number]: number } = {};
|
||||
const aprCounts: { [year: number]: number } = {};
|
||||
|
||||
// OCT Averages
|
||||
const octAverages: { [year: number]: number | null } = {};
|
||||
const octSums: { [year: number]: number } = {};
|
||||
const octCounts: { [year: number]: number } = {};
|
||||
|
||||
years.forEach((year) => {
|
||||
aprAverages[year] = null;
|
||||
aprSums[year] = 0;
|
||||
aprCounts[year] = 0;
|
||||
|
||||
octAverages[year] = null;
|
||||
octSums[year] = 0;
|
||||
octCounts[year] = 0;
|
||||
});
|
||||
|
||||
profiles.forEach((profile) => {
|
||||
const assessments = profile.profileAssessments || [];
|
||||
|
||||
assessments.forEach((assessment) => {
|
||||
const year = Number(assessment.year);
|
||||
|
||||
if (years.includes(year)) {
|
||||
if (assessment.period === "APR") {
|
||||
aprSums[year] += assessment.pointSum;
|
||||
aprCounts[year] += 1;
|
||||
}
|
||||
|
||||
if (assessment.period === "OCT") {
|
||||
octSums[year] += assessment.pointSum;
|
||||
octCounts[year] += 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
years.forEach((year) => {
|
||||
aprAverages[year] = aprCounts[year] > 0 ? aprSums[year] / aprCounts[year] : null;
|
||||
octAverages[year] = octCounts[year] > 0 ? octSums[year] / octCounts[year] : null;
|
||||
});
|
||||
|
||||
const findRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
|
||||
const mapProfile = profiles.map((profile) => {
|
||||
const shortName =
|
||||
profile.current_holders.length == 0
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
|
||||
null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||
?.orgChild3 != null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||
?.orgChild2 != null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||
null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||
?.orgChild1 != null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||
null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||
?.orgRoot != null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: null;
|
||||
|
||||
return {
|
||||
id: profile.id,
|
||||
avatar: profile.avatar,
|
||||
avatarName: profile.avatarName,
|
||||
rank: profile.rank ?? "",
|
||||
prefix: profile.prefix ?? "",
|
||||
firstName: profile.firstName ?? "",
|
||||
lastName: profile.lastName ?? "",
|
||||
citizenId: profile.citizenId ?? "",
|
||||
position: profile.position ?? "",
|
||||
posLevelId: profile.posLevelId,
|
||||
posTypeId: profile.posTypeId,
|
||||
email: profile.email,
|
||||
phone: profile.phone,
|
||||
keycloak: profile.keycloak,
|
||||
isProbation: profile.isProbation,
|
||||
isLeave: profile.isLeave,
|
||||
leaveReason: profile.leaveReason,
|
||||
dateRetire: profile.dateRetire,
|
||||
dateAppoint: profile.dateAppoint,
|
||||
dateRetireLaw: profile.dateRetireLaw,
|
||||
dateStart: profile.dateStart,
|
||||
govAgeAbsent: profile.govAgeAbsent,
|
||||
govAgePlus: profile.govAgePlus,
|
||||
birthDate: profile.birthDate ?? new Date(),
|
||||
reasonSameDate: profile.reasonSameDate,
|
||||
telephoneNumber: profile.phone,
|
||||
nationality: profile.nationality,
|
||||
gender: profile.gender ?? "",
|
||||
relationship: profile.relationship ?? "",
|
||||
religion: profile.religion ?? "",
|
||||
bloodGroup: profile.bloodGroup ?? "",
|
||||
registrationAddress: profile.registrationAddress,
|
||||
registrationProvinceId: profile.registrationProvinceId,
|
||||
registrationDistrictId: profile.registrationDistrictId,
|
||||
registrationSubDistrictId: profile.registrationSubDistrictId,
|
||||
registrationZipCode: profile.registrationZipCode,
|
||||
currentAddress: profile.currentAddress,
|
||||
currentProvinceId: profile.currentProvinceId,
|
||||
currentSubDistrictId: profile.currentSubDistrictId,
|
||||
currentZipCode: profile.currentZipCode,
|
||||
dutyTimeId: profile.dutyTimeId,
|
||||
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
|
||||
posLevel: profile.posLevel?.posLevelName ?? "",
|
||||
posType: profile.posType?.posTypeName ?? "",
|
||||
profileSalary: profile.profileSalary,
|
||||
profileInsignia: profile.profileInsignias.map((x) => {
|
||||
return { ...x, insignia: x.insignia.name };
|
||||
}),
|
||||
amount: profile.amount,
|
||||
positionSalaryAmount: profile.positionSalaryAmount,
|
||||
mouthSalaryAmount: profile.mouthSalaryAmount,
|
||||
profileType: "OFFICER",
|
||||
root:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgRoot?.orgRootName ?? null,
|
||||
rootId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgRootId ?? null,
|
||||
rootDnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgRoot?.ancestorDNA ?? null,
|
||||
child1:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild1?.orgChild1Name ?? null,
|
||||
child1Id:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild1Id ?? null,
|
||||
child1DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild1?.ancestorDNA ?? null,
|
||||
child2:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild2?.orgChild2Name ?? null,
|
||||
child2Id:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild2Id ?? null,
|
||||
child2DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild2?.ancestorDNA ?? null,
|
||||
child3:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild3?.orgChild3Name ?? null,
|
||||
child3Id:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild3Id ?? null,
|
||||
child3DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild3?.ancestorDNA ?? null,
|
||||
child4:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild4?.orgChild4Name ?? null,
|
||||
child4Id:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild4Id ?? null,
|
||||
child4DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild4?.ancestorDNA ?? null,
|
||||
posNo: shortName ?? "",
|
||||
markDiscipline: profile.profileDisciplines.length > 0 ? true : false,
|
||||
markLeave: false,
|
||||
markRate: profile.profileAssessments.length > 0 ? true : false,
|
||||
markInsignia: profile.profileInsignias.length > 0 ? true : false,
|
||||
apr1: aprAverages[currentYear]
|
||||
? Extension.textPoint(aprAverages[currentYear] as number)
|
||||
: null,
|
||||
apr2: aprAverages[currentYear - 1]
|
||||
? Extension.textPoint(aprAverages[currentYear - 1] as number)
|
||||
: null,
|
||||
apr3: aprAverages[currentYear - 2]
|
||||
? Extension.textPoint(aprAverages[currentYear - 2] as number)
|
||||
: null,
|
||||
apr4: aprAverages[currentYear - 3]
|
||||
? Extension.textPoint(aprAverages[currentYear - 3] as number)
|
||||
: null,
|
||||
apr5: aprAverages[currentYear - 4]
|
||||
? Extension.textPoint(aprAverages[currentYear - 4] as number)
|
||||
: null,
|
||||
oct1: octAverages[currentYear]
|
||||
? Extension.textPoint(octAverages[currentYear] as number)
|
||||
: null,
|
||||
oct2: octAverages[currentYear - 1]
|
||||
? Extension.textPoint(octAverages[currentYear - 1] as number)
|
||||
: null,
|
||||
oct3: octAverages[currentYear - 2]
|
||||
? Extension.textPoint(octAverages[currentYear - 2] as number)
|
||||
: null,
|
||||
oct4: octAverages[currentYear - 3]
|
||||
? Extension.textPoint(octAverages[currentYear - 3] as number)
|
||||
: null,
|
||||
oct5: octAverages[currentYear - 4]
|
||||
? Extension.textPoint(octAverages[currentYear - 4] as number)
|
||||
: null,
|
||||
};
|
||||
});
|
||||
|
||||
return new HttpSuccess(mapProfile);
|
||||
}
|
||||
|
|
@ -1663,6 +1880,315 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
return new HttpSuccess(mapProfile);
|
||||
}
|
||||
|
||||
@Post("find/employee/position")
|
||||
async GetProfileByPositionEmpAsync(
|
||||
@Body()
|
||||
body: {
|
||||
empPosId: string[];
|
||||
rootId: string;
|
||||
},
|
||||
) {
|
||||
const findRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
const employeePosDict = await this.employeePosDictRepository.find({
|
||||
where: { id: In(body.empPosId) },
|
||||
});
|
||||
|
||||
const profiles = await this.profileEmpRepo.find({
|
||||
relations: [
|
||||
"posLevel",
|
||||
"posType",
|
||||
"profileSalary",
|
||||
"profileInsignias",
|
||||
"profileInsignias.insignia",
|
||||
"profileDisciplines",
|
||||
"profileAssessments",
|
||||
"current_holders",
|
||||
"current_holders.orgRevision",
|
||||
"current_holders.orgRoot",
|
||||
"current_holders.orgChild1",
|
||||
"current_holders.orgChild2",
|
||||
"current_holders.orgChild3",
|
||||
"current_holders.orgChild4",
|
||||
],
|
||||
where: employeePosDict.map((entry) => ({
|
||||
posLevelId: entry.posLevelId,
|
||||
posTypeId: entry.posTypeId,
|
||||
position: entry.posDictName,
|
||||
current_holders: { orgRootId: body.rootId },
|
||||
})),
|
||||
order: {
|
||||
profileSalary: {
|
||||
commandDateAffect: "DESC",
|
||||
},
|
||||
profileInsignias: {
|
||||
receiveDate: "DESC",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const currentYear = new Date().getFullYear();
|
||||
const years = [currentYear, currentYear - 1, currentYear - 2, currentYear - 3, currentYear - 4];
|
||||
|
||||
// APR Averages
|
||||
const aprAverages: { [year: number]: number | null } = {};
|
||||
const aprSums: { [year: number]: number } = {};
|
||||
const aprCounts: { [year: number]: number } = {};
|
||||
|
||||
// OCT Averages
|
||||
const octAverages: { [year: number]: number | null } = {};
|
||||
const octSums: { [year: number]: number } = {};
|
||||
const octCounts: { [year: number]: number } = {};
|
||||
|
||||
years.forEach((year) => {
|
||||
aprAverages[year] = null;
|
||||
aprSums[year] = 0;
|
||||
aprCounts[year] = 0;
|
||||
|
||||
octAverages[year] = null;
|
||||
octSums[year] = 0;
|
||||
octCounts[year] = 0;
|
||||
});
|
||||
|
||||
profiles.forEach((profile) => {
|
||||
const assessments = profile.profileAssessments || [];
|
||||
|
||||
assessments.forEach((assessment) => {
|
||||
const year = Number(assessment.year);
|
||||
|
||||
if (years.includes(year)) {
|
||||
if (assessment.period === "APR") {
|
||||
aprSums[year] += assessment.pointSum;
|
||||
aprCounts[year] += 1;
|
||||
}
|
||||
|
||||
if (assessment.period === "OCT") {
|
||||
octSums[year] += assessment.pointSum;
|
||||
octCounts[year] += 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
years.forEach((year) => {
|
||||
aprAverages[year] = aprCounts[year] > 0 ? aprSums[year] / aprCounts[year] : null;
|
||||
octAverages[year] = octCounts[year] > 0 ? octSums[year] / octCounts[year] : null;
|
||||
});
|
||||
|
||||
const mapProfile = profiles.map((profile) => {
|
||||
const shortName =
|
||||
profile.current_holders.length == 0
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
|
||||
null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||
?.orgChild3 != null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||
?.orgChild2 != null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||
null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||
?.orgChild1 != null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||
null &&
|
||||
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||
?.orgRoot != null
|
||||
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||
: null;
|
||||
return {
|
||||
id: profile.id,
|
||||
avatar: profile.avatar,
|
||||
avatarName: profile.avatarName,
|
||||
rank: profile.rank ?? "",
|
||||
prefix: profile.prefix ?? "",
|
||||
firstName: profile.firstName ?? "",
|
||||
lastName: profile.lastName ?? "",
|
||||
citizenId: profile.citizenId ?? "",
|
||||
position: profile.position ?? "",
|
||||
posLevelId: profile.posLevelId,
|
||||
email: profile.email,
|
||||
phone: profile.phone,
|
||||
keycloak: profile.keycloak,
|
||||
isProbation: profile.isProbation,
|
||||
isLeave: profile.isLeave,
|
||||
leaveReason: profile.leaveReason,
|
||||
dateRetire: profile.dateRetire,
|
||||
dateAppoint: profile.dateAppoint,
|
||||
dateRetireLaw: profile.dateRetireLaw,
|
||||
dateStart: profile.dateStart,
|
||||
govAgeAbsent: profile.govAgeAbsent,
|
||||
govAgePlus: profile.govAgePlus,
|
||||
birthDate: profile.birthDate ?? new Date(),
|
||||
reasonSameDate: profile.reasonSameDate,
|
||||
telephoneNumber: profile.phone,
|
||||
nationality: profile.nationality,
|
||||
gender: profile.gender ?? "",
|
||||
relationship: profile.relationship ?? "",
|
||||
religion: profile.religion ?? "",
|
||||
bloodGroup: profile.bloodGroup ?? "",
|
||||
registrationAddress: profile.registrationAddress,
|
||||
registrationProvinceId: profile.registrationProvinceId,
|
||||
registrationDistrictId: profile.registrationDistrictId,
|
||||
registrationSubDistrictId: profile.registrationSubDistrictId,
|
||||
registrationZipCode: profile.registrationZipCode,
|
||||
currentAddress: profile.currentAddress,
|
||||
currentProvinceId: profile.currentProvinceId,
|
||||
currentSubDistrictId: profile.currentSubDistrictId,
|
||||
currentZipCode: profile.currentZipCode,
|
||||
posLevel:
|
||||
(profile.posType == null || profile.posType?.posTypeShortName == null
|
||||
? ""
|
||||
: profile.posType?.posTypeShortName + " ") + (profile.posLevel?.posLevelName ?? ""),
|
||||
posType: profile.posType?.posTypeName ?? "",
|
||||
profileSalary: profile.profileSalary.map((x) => {
|
||||
return { ...x, date: x.commandDateAffect ?? new Date() };
|
||||
}),
|
||||
profileInsignia: profile.profileInsignias.map((x) => {
|
||||
return { ...x, insignia: x.insignia.name };
|
||||
}),
|
||||
amount: profile.amount,
|
||||
positionSalaryAmount: profile.positionSalaryAmount,
|
||||
mouthSalaryAmount: profile.mouthSalaryAmount,
|
||||
profileType: "EMPLOYEE",
|
||||
root:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgRoot?.orgRootName ?? null,
|
||||
rootId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgRootId ?? null,
|
||||
rootDnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgRoot?.ancestorDNA ?? null,
|
||||
child1:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild1?.orgChild1Name ?? null,
|
||||
child1Id:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild1Id ?? null,
|
||||
child1DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild1?.ancestorDNA ?? null,
|
||||
child2:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild2?.orgChild2Name ?? null,
|
||||
child2Id:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild2Id ?? null,
|
||||
child2DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild2?.ancestorDNA ?? null,
|
||||
child3:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild3?.orgChild3Name ?? null,
|
||||
child3Id:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild3Id ?? null,
|
||||
child3DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild3?.ancestorDNA ?? null,
|
||||
child4:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild4?.orgChild4Name ?? null,
|
||||
child4Id:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild4Id ?? null,
|
||||
child4DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.orgChild4?.ancestorDNA ?? null,
|
||||
posNo: shortName ?? "",
|
||||
markDiscipline: profile.profileDisciplines.length > 0 ? true : false,
|
||||
markLeave: false,
|
||||
markRate: profile.profileAssessments.length > 0 ? true : false,
|
||||
markInsignia: profile.profileInsignias.length > 0 ? true : false,
|
||||
apr1: aprAverages[currentYear]
|
||||
? Extension.textPoint(aprAverages[currentYear] as number)
|
||||
: null,
|
||||
apr2: aprAverages[currentYear - 1]
|
||||
? Extension.textPoint(aprAverages[currentYear - 1] as number)
|
||||
: null,
|
||||
apr3: aprAverages[currentYear - 2]
|
||||
? Extension.textPoint(aprAverages[currentYear - 2] as number)
|
||||
: null,
|
||||
apr4: aprAverages[currentYear - 3]
|
||||
? Extension.textPoint(aprAverages[currentYear - 3] as number)
|
||||
: null,
|
||||
apr5: aprAverages[currentYear - 4]
|
||||
? Extension.textPoint(aprAverages[currentYear - 4] as number)
|
||||
: null,
|
||||
oct1: octAverages[currentYear]
|
||||
? Extension.textPoint(octAverages[currentYear] as number)
|
||||
: null,
|
||||
oct2: octAverages[currentYear - 1]
|
||||
? Extension.textPoint(octAverages[currentYear - 1] as number)
|
||||
: null,
|
||||
oct3: octAverages[currentYear - 2]
|
||||
? Extension.textPoint(octAverages[currentYear - 2] as number)
|
||||
: null,
|
||||
oct4: octAverages[currentYear - 3]
|
||||
? Extension.textPoint(octAverages[currentYear - 3] as number)
|
||||
: null,
|
||||
oct5: octAverages[currentYear - 4]
|
||||
? Extension.textPoint(octAverages[currentYear - 4] as number)
|
||||
: null,
|
||||
};
|
||||
});
|
||||
|
||||
return new HttpSuccess(mapProfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ยืนยัน Email
|
||||
*
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
|||
import { ProfileAssistance } from "../entities/ProfileAssistance";
|
||||
import { CommandRecive } from "../entities/CommandRecive";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
import { getTopDegrees } from "../services/PositionService";
|
||||
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
|
||||
import { ProfileLeaveService } from "../services/ProfileLeaveService";
|
||||
|
||||
@Route("api/v1/org/profile")
|
||||
|
|
@ -10789,6 +10789,9 @@ export class ProfileController extends Controller {
|
|||
await this.profileRepo.save(profile, { data: request });
|
||||
setLogDataDiff(request, { before, after: profile });
|
||||
if (requestBody.isLeave == true) {
|
||||
if(orgRevisionRef){
|
||||
await CreatePosMasterHistoryOfficer(orgRevisionRef.id, request, "DELETE");
|
||||
}
|
||||
await removeProfileInOrganize(profile.id, "OFFICER");
|
||||
}
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -47,9 +47,7 @@ export const AppDataSource = new DataSource({
|
|||
logging: true,
|
||||
// timezone: "Z",
|
||||
entities:
|
||||
process.env.NODE_ENV !== "production"
|
||||
? ["src/entities/**/*.ts"]
|
||||
: ["dist/entities/**/*{.ts,.js}"],
|
||||
process.env.NODE_ENV !== "production" ? ["src/entities/*.ts"] : ["dist/entities/*{.ts,.js}"],
|
||||
migrations:
|
||||
process.env.NODE_ENV !== "production"
|
||||
? ["src/migration/**/*.ts"]
|
||||
|
|
|
|||
|
|
@ -259,7 +259,13 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
|
|||
.andWhere("orgRevision.orgRevisionIsCurrent = true")
|
||||
.getOne();
|
||||
|
||||
if (!currentRevision) {
|
||||
const draftRevision = await AppDataSource.getRepository(OrgRevision)
|
||||
.createQueryBuilder("orgRevision")
|
||||
.where("orgRevision.orgRevisionIsDraft = true")
|
||||
.andWhere("orgRevision.orgRevisionIsCurrent = false")
|
||||
.getOne();
|
||||
|
||||
if (!currentRevision && !draftRevision) {
|
||||
return;
|
||||
}
|
||||
if (type === "OFFICER") {
|
||||
|
|
@ -276,7 +282,20 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
|
|||
.where("id = :id", { id: findProfileInposMaster?.id })
|
||||
.execute();
|
||||
|
||||
if (!findProfileInposMaster) {
|
||||
const findProfileInposMasterDraft = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: draftRevision?.id })
|
||||
.andWhere("posMaster.next_holderId = :profileId", { profileId })
|
||||
.getOne();
|
||||
|
||||
await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder()
|
||||
.update(PosMaster)
|
||||
.set({ next_holderId: null })
|
||||
.where("id = :id", { id: findProfileInposMasterDraft?.id })
|
||||
.execute();
|
||||
|
||||
if (!findProfileInposMaster && !findProfileInposMasterDraft) {
|
||||
return;
|
||||
}
|
||||
const findPosition = await AppDataSource.getRepository(Position)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,14 @@ export async function expressAuthentication(
|
|||
securityName: string,
|
||||
_scopes?: string[],
|
||||
) {
|
||||
// API_KEY bypass logic (support api_key, x-api-key, apikey)
|
||||
const apiKeyHeader =
|
||||
request.headers["api-key"] || request.headers["x-api-key"] || request.headers["apikey"];
|
||||
if (apiKeyHeader !== undefined) {
|
||||
if (apiKeyHeader === process.env.API_KEY) {
|
||||
return { preferred_username: "api_key_bypass", apiKeyBypass: true };
|
||||
}
|
||||
}
|
||||
if (process.env.NODE_ENV !== "production" && process.env.AUTH_BYPASS) {
|
||||
return { preferred_username: "bypassed" };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
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\``);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
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'`);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
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 'สถานที่ฝึกอบรม/ดูงาน '`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
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\``);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
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'`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,292 +0,0 @@
|
|||
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