Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Suphonchai Phoonsawat 2024-12-10 10:05:46 +07:00
commit c5d0d4a941
28 changed files with 496 additions and 219 deletions

View file

@ -1,5 +1,5 @@
name: release-test name: release
run-name: release-test ${{ github.actor }} run-name: release ${{ github.actor }}
on: on:
push: push:
tags: tags:
@ -9,11 +9,11 @@ env:
REGISTRY: docker.frappet.com REGISTRY: docker.frappet.com
IMAGE_NAME: ehr/bma-ehr-org-service IMAGE_NAME: ehr/bma-ehr-org-service
DEPLOY_HOST: frappet.com DEPLOY_HOST: frappet.com
# COMPOSE_PATH: /home/frappet/docker/bma-ehr
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-org COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-org
jobs: jobs:
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357 # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
release-test: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -52,6 +52,7 @@ jobs:
with: with:
context: . context: .
platforms: linux/amd64 platforms: linux/amd64
file: docker/Dockerfile
push: true push: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
- name: Remote Deployment - name: Remote Deployment
@ -66,21 +67,40 @@ jobs:
docker compose pull docker compose pull
docker compose up -d docker compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success echo "${{ steps.gen_ver.outputs.image_ver }}"> success
- uses: snow-actions/line-notify@v1.1.0 - name: Notify Discord Success
if: success() if: success()
with: run: |
access_token: ${{ secrets.TOKEN_LINE }} curl -H "Content-Type: application/json" \
message: | -X POST \
-Success✅✅✅ -d '{
Image: ${{env.IMAGE_NAME}} "embeds": [{
Version: ${{ steps.gen_ver.outputs.IMAGE_VER }} "title": "✅ Deployment Success!",
By: ${{github.actor}} "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
- uses: snow-actions/line-notify@v1.1.0 "color": 3066993,
"footer": {
"text": "Release Notification",
"icon_url": "https://example.com/success-icon.png"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
${{ secrets.DISCORD_WEBHOOK }}
- name: Notify Discord Failure
if: failure() if: failure()
with: run: |
access_token: ${{ secrets.TOKEN_LINE }} curl -H "Content-Type: application/json" \
message: | -X POST \
-Failure❌❌❌ -d '{
Image: ${{env.IMAGE_NAME}} "embeds": [{
Version: ${{ steps.gen_ver.outputs.IMAGE_VER }} "title": "❌ Deployment Failed!",
By: ${{github.actor}} "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
"color": 15158332,
"footer": {
"text": "Release Notification",
"icon_url": "https://example.com/failure-icon.png"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
${{ secrets.DISCORD_WEBHOOK }}

View file

@ -1,35 +0,0 @@
FROM node:18-alpine as builder
# Create app directory
WORKDIR /app
# Install app dependencies
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:18-alpine
ENV NODE_ENV production
USER node
# Create app directory
WORKDIR /app
# Install app dependencies
COPY package*.json ./
# COPY .env ./
RUN npm ci --production
COPY --from=builder /app/dist ./dist
# COPY entrypoint.sh /usr/local/bin/entrypoint.sh
# RUN chmod u+x /usr/local/bin/entrypoint.sh
# ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD [ "node", "dist/app.js" ]

34
docker/Dockerfile Normal file
View file

@ -0,0 +1,34 @@
# Build Stage
FROM node:lts-alpine AS build-stage
# Create app directory
WORKDIR /app
# Install app dependencies
COPY package*.json ./
RUN npm ci
# Copy source files and build the app
COPY . .
RUN npm run build
# Production Stage
FROM node:lts-alpine
ENV NODE_ENV production
USER node
# Create app directory
WORKDIR /app
# Copy built app from build stage
COPY --from=build-stage /app/dist ./dist
# Install only production dependencies
COPY package*.json ./
RUN npm ci --production
# Define the entrypoint and default command
# If you have a custom entrypoint script
CMD [ "node", "dist/app.js" ]

View file

@ -128,4 +128,56 @@ export class ApiKeyController extends Controller {
}); });
return new HttpSuccess(apiName); return new HttpSuccess(apiName);
} }
/**
* API Api Key
*
* @summary Api Key (ADMIN)
*
*/
@Post("history")
async getHistory(
@Body()
requestBody: {
startDate: Date;
endDate: Date;
apiNameId: string | null;
},
@Request() request: RequestWithUser,
) {
if (requestBody.apiNameId) {
const apiName = await this.apiNameRepository.findOne({
where: { id: requestBody.apiNameId },
});
if (!apiName)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรายการ Web Service นี้ในระบบ");
}
const apiHistory = await AppDataSource.getRepository(ApiHistory)
.createQueryBuilder("apiHistory")
.leftJoinAndSelect("apiHistory.apiKey", "apiKey")
.leftJoinAndSelect("apiHistory.apiName", "apiName")
.andWhere(requestBody.apiNameId ? `apiHistory.apiNameId = :apiNameId` : "1=1", {
apiNameId: requestBody.apiNameId,
})
.andWhere(
`apiHistory.createdAt >= DATE(:startDate) AND apiHistory.createdAt <= DATE(:endDate)`,
{
startDate: new Date(requestBody.startDate),
endDate: new Date(
requestBody.endDate.setDate(new Date(requestBody.endDate).getDate() + 1),
),
},
)
.orderBy("apiHistory.createdAt", "DESC")
.getMany();
const result = apiHistory.map((x) => ({
id: x.id,
apiName: x.apiName.name,
apiKey: x.apiKey.name,
createdAt: x.createdAt,
ipApi: x.ipApi,
}));
return new HttpSuccess(result);
}
} }

View file

@ -1615,19 +1615,23 @@ export class CommandController extends Controller {
persons: { persons: {
refId: string; refId: string;
profileId?: string | null; profileId?: string | null;
citizenId: string | null; citizenId?: string | null;
prefix: string | null; prefix?: string | null;
firstName: string | null; firstName?: string | null;
lastName: string | null; lastName?: string | null;
remarkVertical?: string | null; remarkVertical?: string | null;
remarkHorizontal?: string | null; remarkHorizontal?: string | null;
rootId?: string | null; rootId?: string | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
}[]; }[];
}, },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
let command = new Command(); let command = new Command();
let commandCode = null; let commandCode:string = "";
let null_: any = null; let null_: any = null;
if ( if (
requestBody.commandId != undefined && requestBody.commandId != undefined &&
@ -1707,30 +1711,40 @@ export class CommandController extends Controller {
commandRecive = Object.assign(new CommandRecive(), item); commandRecive = Object.assign(new CommandRecive(), item);
commandRecive.order = order; commandRecive.order = order;
let salaryData = null_; let salaryData = null_;
if (item.profileId) {
salaryData = await this.profileRepository.findOne({ const excludedCommands = ["C-PM-33", "C-PM-34", "C-PM-35", "C-PM-36", "C-PM-37"];
where: { if (!excludedCommands.includes(commandCode)) {
id: item.profileId, if (item.profileId) {
}, salaryData = await this.profileRepository.findOne({
});
let null_: any = 0;
if (!salaryData) {
salaryData = await this.profileEmployeeRepository.findOne({
where: { where: {
id: item.profileId, id: item.profileId,
}, },
}); });
let null_: any = 0;
if (!salaryData) {
salaryData = await this.profileEmployeeRepository.findOne({
where: {
id: item.profileId,
},
});
}
commandRecive.amount = salaryData ? salaryData.amount : null_;
commandRecive.positionSalaryAmount = salaryData
? salaryData.positionSalaryAmount
: null_;
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
} else {
commandRecive.amount = null_;
commandRecive.positionSalaryAmount = null_;
commandRecive.mouthSalaryAmount = null_;
} }
commandRecive.amount = salaryData ? salaryData.amount : null_;
commandRecive.positionSalaryAmount = salaryData
? salaryData.positionSalaryAmount
: null_;
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
} else { } else {
commandRecive.amount = null_; commandRecive.amount = item.amount ?? null_;
commandRecive.positionSalaryAmount = null_; commandRecive.amountSpecial = item.amountSpecial ?? null_;
commandRecive.mouthSalaryAmount = null_; commandRecive.positionSalaryAmount = item.positionSalaryAmount ?? null_;
commandRecive.mouthSalaryAmount = item.mouthSalaryAmount ?? null_;
} }
commandRecive.remarkVertical = commandRecive.remarkVertical =
item.remarkVertical == null ? null_ : item.remarkVertical; item.remarkVertical == null ? null_ : item.remarkVertical;
commandRecive.remarkHorizontal = commandRecive.remarkHorizontal =
@ -1898,6 +1912,7 @@ export class CommandController extends Controller {
profileId: string; profileId: string;
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo: string | null; posNo: string | null;
@ -1917,7 +1932,7 @@ export class CommandController extends Controller {
) { ) {
await Promise.all( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileRepository.findOneBy({ id: item.profileId }); const profile:any = await this.profileRepository.findOneBy({ id: item.profileId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
} }
@ -2002,6 +2017,8 @@ export class CommandController extends Controller {
profile.posLevelId = positionNew.posLevelId; profile.posLevelId = positionNew.posLevelId;
profile.posTypeId = positionNew.posTypeId; profile.posTypeId = positionNew.posTypeId;
profile.position = positionNew.positionName; profile.position = positionNew.positionName;
profile.amount = item.amount ?? null;
profile.amountSpecial = item.amountSpecial ?? null;
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
await this.positionRepository.save(positionNew); await this.positionRepository.save(positionNew);
} }
@ -2020,6 +2037,7 @@ export class CommandController extends Controller {
profileId: string; profileId: string;
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo: string | null; posNo: string | null;
@ -2036,7 +2054,7 @@ export class CommandController extends Controller {
) { ) {
await Promise.all( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOneBy({ id: item.profileId }); const profile:any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
@ -2131,7 +2149,8 @@ export class CommandController extends Controller {
profile.position = positionNew.positionName; profile.position = positionNew.positionName;
profile.employeeOc = posMaster?.orgRoot?.orgRootName ?? null; profile.employeeOc = posMaster?.orgRoot?.orgRootName ?? null;
profile.positionEmployeePositionId = positionNew.positionName; profile.positionEmployeePositionId = positionNew.positionName;
profile.amount = item.amount ?? null;
profile.amountSpecial = item.amountSpecial ?? null;
await this.profileEmployeeRepository.save(profile); await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew); await this.employeePositionRepository.save(positionNew);
} }
@ -2150,6 +2169,7 @@ export class CommandController extends Controller {
profileId: string; profileId: string;
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo: string | null; posNo: string | null;
@ -2215,7 +2235,6 @@ export class CommandController extends Controller {
profile.lastUpdateUserId = req.user.sub; profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name; profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date(); profile.lastUpdatedAt = new Date();
// profile.dateStart = new Date();
if (item.isLeave == true) { if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER"); await removeProfileInOrganize(profile.id, "OFFICER");
} }
@ -2236,21 +2255,28 @@ export class CommandController extends Controller {
const returnWork = await checkReturnCommandType(String(item.commandId)); const returnWork = await checkReturnCommandType(String(item.commandId));
//คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user //คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user
if (returnWork && item.isGovernment) { if (returnWork && item.isGovernment) {
/*if (profile.keycloak != null) { let userKeycloakId;
const enableActive = await enableStatus(profile.keycloak, true); userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
if (!enableActive) throw new Error("Failed. Cannot change enable status."); firstName: profile.firstName,
} else {*/ lastName: profile.lastName,
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { });
firstName: profile.firstName, // กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่ และหากยังไม่สามารถลบได้ให้แสดง Error
lastName: profile.lastName, if (profile.keycloak != null && userKeycloakId && userKeycloakId.errorMessage === "User exists with same username") {
}); const delUserKeycloak = await deleteUser(profile.keycloak);
// if (typeof userKeycloakId !== "string") { if(delUserKeycloak) {
// throw new Error(userKeycloakId.errorMessage); userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
// } firstName: profile.firstName,
const list = await getRoles(); lastName: profile.lastName,
if (!Array.isArray(list)) });
throw new Error("Failed. Cannot get role(s) data from the server."); }
const result = await addUserRoles( else {
throw new HttpError(HttpStatus.BAD_REQUEST, "พบข้อผิดพลาด ไม่สามารถจัดการผู้ใช้งานได้");
}
}
const list = await getRoles();
let result = false;
if (Array.isArray(list) && userKeycloakId) {
result = await addUserRoles(
userKeycloakId, userKeycloakId,
list list
.filter((v) => v.name === "USER") .filter((v) => v.name === "USER")
@ -2259,10 +2285,11 @@ export class CommandController extends Controller {
name: x.name, name: x.name,
})), })),
); );
// if (!result) throw new Error("Failed. Cannot set user's role."); }
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : ""; profile.amount = item.amount ?? _null;
/*}*/ profile.amountSpecial = item.amountSpecial ?? _null;
profile.isActive = true; profile.isActive = true;
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
} }
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
@ -2378,6 +2405,7 @@ export class CommandController extends Controller {
profileId: string; profileId: string;
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo: string | null; posNo: string | null;
@ -2398,7 +2426,7 @@ export class CommandController extends Controller {
) { ) {
await Promise.all( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({ const profile:any = await this.profileRepository.findOne({
where: { id: item.profileId }, where: { id: item.profileId },
relations: ["roleKeycloaks"], relations: ["roleKeycloaks"],
}); });
@ -2441,6 +2469,8 @@ export class CommandController extends Controller {
profile.posLevelId = _null; profile.posLevelId = _null;
profile.leaveReason = item.leaveReason ?? _null; profile.leaveReason = item.leaveReason ?? _null;
profile.dateLeave = item.dateLeave ?? _null; profile.dateLeave = item.dateLeave ?? _null;
profile.amount = item.amount ?? _null;
profile.amountSpecial = item.amountSpecial ?? _null;
await this.profileRepository.save(profile, { data: req }); await this.profileRepository.save(profile, { data: req });
} }
Object.assign(data, { ...item, ...meta }); Object.assign(data, { ...item, ...meta });
@ -3082,6 +3112,8 @@ export class CommandController extends Controller {
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
profile.email = item.bodyProfile.email; profile.email = item.bodyProfile.email;
profile.dateStart = item.bodyProfile.dateStart; profile.dateStart = item.bodyProfile.dateStart;
profile.amount = item.bodyProfile.amount ?? null;
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
setLogDataDiff(req, { before, after: profile }); setLogDataDiff(req, { before, after: profile });
} }
@ -3125,13 +3157,17 @@ export class CommandController extends Controller {
where: { profileId: profile.id }, where: { profileId: profile.id },
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const profileSal = new ProfileSalary(); const profileSal: any = new ProfileSalary();
Object.assign(profileSal, { ...item.bodySalarys, ...meta }); Object.assign(profileSal, { ...item.bodySalarys, ...meta });
const salaryHistory = new ProfileSalaryHistory(); const salaryHistory = new ProfileSalaryHistory();
Object.assign(salaryHistory, { ...profileSal, id: undefined }); Object.assign(salaryHistory, { ...profileSal, id: undefined });
profileSal.order = dest_item == null ? 1 : dest_item.order + 1; profileSal.order = dest_item == null ? 1 : dest_item.order + 1;
profileSal.profileId = profile.id; profileSal.profileId = profile.id;
profileSal.dateGovernment = meta.createdAt; profileSal.dateGovernment = meta.createdAt;
profileSal.amount = item.bodySalarys.amount ?? null;
profileSal.amountSpecial = item.bodySalarys.amountSpecial ?? null;
profileSal.positionSalaryAmount = item.bodySalarys.positionSalaryAmount ?? null;
profileSal.mouthSalaryAmount = item.bodySalarys.mouthSalaryAmount ?? null;
await this.salaryRepo.save(profileSal, { data: req }); await this.salaryRepo.save(profileSal, { data: req });
setLogDataDiff(req, { before, after: profileSal }); setLogDataDiff(req, { before, after: profileSal });
salaryHistory.profileSalaryId = profileSal.id; salaryHistory.profileSalaryId = profileSal.id;
@ -3279,6 +3315,7 @@ export class CommandController extends Controller {
commandYear: number; commandYear: number;
templateDoc: string | null; templateDoc: string | null;
amount: Double | null; amount: Double | null;
amountSpecial: Double | null;
positionSalaryAmount: Double | null; positionSalaryAmount: Double | null;
mouthSalaryAmount: Double | null; mouthSalaryAmount: Double | null;
}[]; }[];
@ -3308,6 +3345,7 @@ export class CommandController extends Controller {
profileEmployeeId: profile.id, profileEmployeeId: profile.id,
date: new Date(), date: new Date(),
amount: item.amount, amount: item.amount,
amountSpecial: item.amountSpecial,
commandId: item.commandId, commandId: item.commandId,
positionSalaryAmount: item.positionSalaryAmount, positionSalaryAmount: item.positionSalaryAmount,
mouthSalaryAmount: item.mouthSalaryAmount, mouthSalaryAmount: item.mouthSalaryAmount,
@ -3426,9 +3464,8 @@ export class CommandController extends Controller {
const _null: any = null; const _null: any = null;
profile.employeeWage = item.amount == null ? _null : item.amount.toString(); profile.employeeWage = item.amount == null ? _null : item.amount.toString();
profile.dateStart = new Date(); profile.dateStart = new Date();
// profile.amount = item.amount == null ? _null : item.amount.toString(); //เผื่อไว้ profile.amount = item.amount == null ? _null : item.amount;
// profile.positionSalaryAmount = item.positionSalaryAmount == null ? _null : item.positionSalaryAmount.toString(); profile.amountSpecial = item.amountSpecial == null ? _null : item.amountSpecial;
// profile.mouthSalaryAmount = item.mouthSalaryAmount == null ? _null : item.mouthSalaryAmount.toString();
await this.profileEmployeeRepository.save(profile); await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew); await this.employeePositionRepository.save(positionNew);

View file

@ -199,7 +199,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: item.dateStart, dateStart: item.dateStart,
govAgeAbsent: item.govAgeAbsent, govAgeAbsent: item.govAgeAbsent,
govAgePlus: item.govAgePlus, govAgePlus: item.govAgePlus,
birthDate: item.birthDate, birthDate: item.birthDate ?? new Date(),
reasonSameDate: item.reasonSameDate, reasonSameDate: item.reasonSameDate,
ethnicity: item.ethnicity, ethnicity: item.ethnicity,
telephoneNumber: item.telephoneNumber, telephoneNumber: item.telephoneNumber,
@ -495,7 +495,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart, dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent, govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus, govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate, reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber, telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality, nationality: profile.nationality,
@ -732,7 +732,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart, dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent, govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus, govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate, reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber, telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality, nationality: profile.nationality,
@ -1028,7 +1028,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart, dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent, govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus, govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate, reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber, telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality, nationality: profile.nationality,
@ -1295,7 +1295,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart, dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent, govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus, govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate, reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber, telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality, nationality: profile.nationality,
@ -1621,7 +1621,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart, dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent, govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus, govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate, reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber, telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality, nationality: profile.nationality,
@ -1888,7 +1888,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart, dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent, govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus, govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate, reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber, telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality, nationality: profile.nationality,
@ -2072,7 +2072,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart, dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent, govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus, govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate, reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber, telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality, nationality: profile.nationality,
@ -2209,7 +2209,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart, dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent, govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus, govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate, reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber, telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality, nationality: profile.nationality,
@ -2316,7 +2316,7 @@ export class OrganizationDotnetController extends Controller {
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
citizenId: profile.citizenId, citizenId: profile.citizenId,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
position: profile.position, position: profile.position,
rootId: root == null ? null : root.id, rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName, root: root == null ? null : root.orgRootName,
@ -2417,7 +2417,7 @@ export class OrganizationDotnetController extends Controller {
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
citizenId: profile.citizenId, citizenId: profile.citizenId,
birthDate: profile.birthDate, birthDate: profile.birthDate ?? new Date(),
position: profile.position, position: profile.position,
posMaster: posMaster == null ? null : posMaster.posMasterNo, posMaster: posMaster == null ? null : posMaster.posMasterNo,
posMasterNo: posMaster == null ? null : posMaster.posMasterNo, posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
@ -2589,7 +2589,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: item.dateStart, dateStart: item.dateStart,
govAgeAbsent: item.govAgeAbsent, govAgeAbsent: item.govAgeAbsent,
govAgePlus: item.govAgePlus, govAgePlus: item.govAgePlus,
birthDate: item.birthDate, birthDate: item.birthDate ?? new Date(),
reasonSameDate: item.reasonSameDate, reasonSameDate: item.reasonSameDate,
ethnicity: item.ethnicity, ethnicity: item.ethnicity,
telephoneNumber: item.telephoneNumber, telephoneNumber: item.telephoneNumber,

View file

@ -163,10 +163,11 @@ export class OrganizationUnauthorizeController extends Controller {
: item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive : item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName; .posExecutiveName;
const amount = // const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0 // item.current_holder == null || item.current_holder.profileSalary.length == 0
? null // ? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount; // : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date( let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
); );
@ -380,10 +381,11 @@ export class OrganizationUnauthorizeController extends Controller {
orgShortName = item.orgChild4?.orgChild4ShortName; orgShortName = item.orgChild4?.orgChild4ShortName;
} }
const amount = // const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0 // item.current_holder == null || item.current_holder.profileSalary.length == 0
? null // ? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount; // : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date( let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
); );

View file

@ -106,22 +106,15 @@ export class PermissionOrgController extends Controller {
} else if (searchField == "position") { } else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword"; queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") { } else if (searchField == "posNo") {
queryLike = `CONCAT( queryLike = `
IFNULL(orgChild4.orgChild4ShortName, ''), CASE
IFNULL(current_holders.posMasterNo , '') WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
) LIKE :keyword OR CONCAT( WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
IFNULL(orgChild3.orgChild3ShortName, ''), WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
IFNULL(current_holders.posMasterNo , '') WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
) LIKE :keyword OR CONCAT( ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
IFNULL(orgChild2.orgChild2ShortName, ''), END LIKE :keyword
IFNULL(current_holders.posMasterNo , '') `;
) LIKE :keyword OR CONCAT(
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
} }
const findRevision = await this.orgRevisionRepository.findOne({ const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },

View file

@ -3757,22 +3757,15 @@ export class ProfileController extends Controller {
} else if (searchField == "position") { } else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword"; queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") { } else if (searchField == "posNo") {
queryLike = `CONCAT( queryLike = `
IFNULL(orgChild4.orgChild4ShortName, ''), CASE
IFNULL(current_holders.posMasterNo , '') WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
) LIKE :keyword OR CONCAT( WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
IFNULL(orgChild3.orgChild3ShortName, ''), WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
IFNULL(current_holders.posMasterNo , '') WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
) LIKE :keyword OR CONCAT( ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
IFNULL(orgChild2.orgChild2ShortName, ''), END LIKE :keyword
IFNULL(current_holders.posMasterNo , '') `;
) LIKE :keyword OR CONCAT(
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
} }
let nodeCondition = "1=1"; let nodeCondition = "1=1";
let nodeAll = ""; let nodeAll = "";
@ -4116,22 +4109,15 @@ export class ProfileController extends Controller {
} else if (searchField == "position") { } else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword"; queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") { } else if (searchField == "posNo") {
queryLike = `CONCAT( queryLike = `
IFNULL(orgChild4.orgChild4ShortName, ''), CASE
IFNULL(current_holders.posMasterNo , '') WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
) LIKE :keyword OR CONCAT( WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
IFNULL(orgChild3.orgChild3ShortName, ''), WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
IFNULL(current_holders.posMasterNo , '') WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
) LIKE :keyword OR CONCAT( ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
IFNULL(orgChild2.orgChild2ShortName, ''), END LIKE :keyword
IFNULL(current_holders.posMasterNo , '') `;
) LIKE :keyword OR CONCAT(
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
} }
let nodeCondition = "1=1"; let nodeCondition = "1=1";
let nodeAll = ""; let nodeAll = "";
@ -4249,20 +4235,22 @@ export class ProfileController extends Controller {
: `profile.dateLeave IS NOT NULL` : `profile.dateLeave IS NOT NULL`
: "1=1", : "1=1",
) )
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.andWhere(nodeCondition, { .andWhere(nodeCondition, {
nodeId: nodeId, nodeId: nodeId,
}) })
// .andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
// orgRevisionId: findRevision.id, .andWhere(
// }) new Brackets((qb) => {
qb.orWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
})
)
.orderBy("current_holders.posMasterNo", "ASC") .orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
@ -6039,7 +6027,12 @@ export class ProfileController extends Controller {
switch (body.fieldName) { switch (body.fieldName) {
case "citizenId": case "citizenId":
[findProfile, total] = await this.profileRepo.findAndCount({ [findProfile, total] = await this.profileRepo.findAndCount({
where: { citizenId: Like(`%${body.keyword}%`) }, where: {
citizenId: Like(`%${body.keyword}%`),
current_holders:{
orgRevisionId:revision?.id
}
},
relations: [ relations: [
"posType", "posType",
"posLevel", "posLevel",
@ -6066,7 +6059,8 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` }) .where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id })
.andWhere("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` })
.skip(skip) .skip(skip)
.take(take) .take(take)
.getManyAndCount(); .getManyAndCount();
@ -6074,7 +6068,12 @@ export class ProfileController extends Controller {
case "position": case "position":
[findProfile, total] = await this.profileRepo.findAndCount({ [findProfile, total] = await this.profileRepo.findAndCount({
where: { position: Like(`%${body.keyword}%`) }, where: {
position: Like(`%${body.keyword}%`),
current_holders:{
orgRevisionId:revision?.id
}
},
relations: [ relations: [
"posType", "posType",
"posLevel", "posLevel",
@ -6122,6 +6121,9 @@ export class ProfileController extends Controller {
where: { where: {
posType: { posType: {
posTypeName:Like(`%${body.keyword}%`) posTypeName:Like(`%${body.keyword}%`)
},
current_holders:{
orgRevisionId:revision?.id
} }
}, },
relations: [ relations: [
@ -6145,6 +6147,9 @@ export class ProfileController extends Controller {
where: { where: {
posLevel: { posLevel: {
posLevelName:Like(`%${body.keyword}%`) posLevelName:Like(`%${body.keyword}%`)
},
current_holders:{
orgRevisionId:revision?.id
} }
}, },
relations: [ relations: [
@ -6167,6 +6172,7 @@ export class ProfileController extends Controller {
[findProfile, total] = await this.profileRepo.findAndCount({ [findProfile, total] = await this.profileRepo.findAndCount({
where: { where: {
current_holders:{ current_holders:{
orgRevisionId:revision?.id,
orgRoot:{ orgRoot:{
orgRootName:Like(`%${body.keyword}%`) orgRootName:Like(`%${body.keyword}%`)
} }
@ -6189,6 +6195,11 @@ export class ProfileController extends Controller {
default: default:
[findProfile, total] = await this.profileRepo.findAndCount({ [findProfile, total] = await this.profileRepo.findAndCount({
where:{
current_holders:{
orgRevisionId:revision?.id
}
},
relations: [ relations: [
"posType", "posType",
"posLevel", "posLevel",
@ -7236,10 +7247,11 @@ export class ProfileController extends Controller {
: item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive : item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName; .posExecutiveName;
const amount = // const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0 // item.current_holder == null || item.current_holder.profileSalary.length == 0
? null // ? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount; // : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date( let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
); );

View file

@ -1385,22 +1385,15 @@ export class ProfileEmployeeController extends Controller {
} else if (searchField == "position") { } else if (searchField == "position") {
queryLike = "profileEmployee.position LIKE :keyword"; queryLike = "profileEmployee.position LIKE :keyword";
} else if (searchField == "posNo") { } else if (searchField == "posNo") {
queryLike = `CONCAT( queryLike = `
IFNULL(orgChild4.orgChild4ShortName, ''), CASE
IFNULL(current_holders.posMasterNo , '') WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
) LIKE :keyword OR CONCAT( WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
IFNULL(orgChild3.orgChild3ShortName, ''), WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
IFNULL(current_holders.posMasterNo , '') WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
) LIKE :keyword OR CONCAT( ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
IFNULL(orgChild2.orgChild2ShortName, ''), END LIKE :keyword
IFNULL(current_holders.posMasterNo , '') `;
) LIKE :keyword OR CONCAT(
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
} }
let nodeCondition = "1=1"; let nodeCondition = "1=1";
let nodeAll = ""; let nodeAll = "";
@ -2957,10 +2950,11 @@ export class ProfileEmployeeController extends Controller {
orgShortName = item.orgChild4?.orgChild4ShortName; orgShortName = item.orgChild4?.orgChild4ShortName;
} }
const amount = // const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0 // item.current_holder == null || item.current_holder.profileSalary.length == 0
? null // ? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount; // : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date( let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
); );

View file

@ -2699,10 +2699,11 @@ export class ProfileEmployeeTempController extends Controller {
orgShortName = item.orgChild4?.orgChild4ShortName; orgShortName = item.orgChild4?.orgChild4ShortName;
} }
const amount = // const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0 // item.current_holder == null || item.current_holder.profileSalary.length == 0
? null // ? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount; // : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date( let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
); );

View file

@ -122,7 +122,7 @@ export class ProfileSalaryController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}; };
const _null:any = null;
Object.assign(data, { ...body, ...meta }); Object.assign(data, { ...body, ...meta });
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
@ -131,6 +131,11 @@ export class ProfileSalaryController extends Controller {
history.profileSalaryId = data.id; history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req }); await this.salaryHistoryRepo.save(history, { data: req });
profile.amount = body?.amount??_null;
profile.positionSalaryAmount = body?.positionSalaryAmount??_null;
profile.mouthSalaryAmount = body.mouthSalaryAmount??_null;
await this.profileRepo.save(profile, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -173,6 +178,7 @@ export class ProfileSalaryController extends Controller {
let null_:any = null; let null_:any = null;
profile.amount = body.amount ?? null_; profile.amount = body.amount ?? null_;
profile.amountSpecial = body.amountSpecial ?? null_;
profile.positionSalaryAmount = body.positionSalaryAmount ?? null_; profile.positionSalaryAmount = body.positionSalaryAmount ?? null_;
profile.mouthSalaryAmount = body.mouthSalaryAmount ?? null_; profile.mouthSalaryAmount = body.mouthSalaryAmount ?? null_;
await this.profileRepo.save(profile); await this.profileRepo.save(profile);

View file

@ -137,12 +137,17 @@ export class ProfileSalaryEmployeeController extends Controller {
Object.assign(data, { ...body, ...meta }); Object.assign(data, { ...body, ...meta });
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
const _null:any = null;
await this.salaryRepo.save(data, { data: req }); await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data }); setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id; history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req }); await this.salaryHistoryRepo.save(history, { data: req });
profile.amount = body?.amount??_null;
profile.positionSalaryAmount = body?.positionSalaryAmount??_null;
profile.mouthSalaryAmount = body.mouthSalaryAmount??_null;
await this.profileRepo.save(profile, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -189,6 +194,7 @@ export class ProfileSalaryEmployeeController extends Controller {
let null_:any = null; let null_:any = null;
profile.amount = body.amount ?? null_; profile.amount = body.amount ?? null_;
profile.amountSpecial = body.amountSpecial ?? null_;
profile.positionSalaryAmount = body.positionSalaryAmount ?? null_; profile.positionSalaryAmount = body.positionSalaryAmount ?? null_;
profile.mouthSalaryAmount = body.mouthSalaryAmount ?? null_; profile.mouthSalaryAmount = body.mouthSalaryAmount ?? null_;
await this.profileRepo.save(profile); await this.profileRepo.save(profile);

View file

@ -41,7 +41,7 @@ export const AppDataSource = new DataSource({
password: process.env.DB_PASSWORD, password: process.env.DB_PASSWORD,
connectorPackage: "mysql2", connectorPackage: "mysql2",
synchronize: false, synchronize: false,
logging: ["query", "error"], logging: true,
entities: entities:
process.env.NODE_ENV !== "production" process.env.NODE_ENV !== "production"
? ["src/entities/**/*.ts"] ? ["src/entities/**/*.ts"]

View file

@ -1,6 +1,7 @@
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { ApiKey } from "./ApiKey"; import { ApiKey } from "./ApiKey";
import { ApiName } from "./ApiName";
@Entity("apiHistory") @Entity("apiHistory")
export class ApiHistory extends EntityBase { export class ApiHistory extends EntityBase {
@ -63,4 +64,16 @@ export class ApiHistory extends EntityBase {
@ManyToOne(() => ApiKey, (apiKey) => apiKey.apiHistorys) @ManyToOne(() => ApiKey, (apiKey) => apiKey.apiHistorys)
@JoinColumn({ name: "apiKeyId" }) @JoinColumn({ name: "apiKeyId" })
apiKey: ApiKey; apiKey: ApiKey;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง ApiName",
default: null,
})
apiNameId: string;
@ManyToOne(() => ApiName, (apiName) => apiName.apiHistorys)
@JoinColumn({ name: "apiNameId" })
apiName: ApiName;
} }

View file

@ -1,6 +1,7 @@
import { Entity, Column, ManyToMany, JoinTable } from "typeorm"; import { Entity, Column, ManyToMany, JoinTable, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { ApiKey } from "./ApiKey"; import { ApiKey } from "./ApiKey";
import { ApiHistory } from "./ApiHistory";
@Entity("apiName") @Entity("apiName")
export class ApiName extends EntityBase { export class ApiName extends EntityBase {
@ -31,4 +32,7 @@ export class ApiName extends EntityBase {
@ManyToMany(() => ApiKey, (apiKey) => apiKey.apiNames) @ManyToMany(() => ApiKey, (apiKey) => apiKey.apiNames)
@JoinTable() @JoinTable()
apiKeys: ApiKey[]; apiKeys: ApiKey[];
@OneToMany(() => ApiHistory, (v) => v.apiName)
apiHistorys: ApiHistory[];
} }

View file

@ -67,6 +67,14 @@ export class CommandRecive extends EntityBase {
}) })
amount: Double; amount: Double;
@Column({
comment: "เงินพิเศษ",
default: 0,
nullable: true,
type: "double",
})
amountSpecial: Double;
@Column({ @Column({
comment: "เงินประจำตำแหน่ง", comment: "เงินประจำตำแหน่ง",
default: 0, default: 0,

View file

@ -80,6 +80,12 @@ export class CommandType extends EntityBase {
}) })
isAttachment: boolean; isAttachment: boolean;
@Column({
comment: "สถานะแก้ไขเงินเดือน",
default: true,
})
isSalary: boolean;
@Column({ @Column({
nullable: true, nullable: true,
comment: "คำอธิบาย", comment: "คำอธิบาย",
@ -119,6 +125,9 @@ export class CreateCommandType {
@Column() @Column()
isAttachment: boolean; isAttachment: boolean;
@Column()
isSalary?: boolean | null;
} }
export type UpdateCommandType = Partial<CreateCommandType>; export type UpdateCommandType = Partial<CreateCommandType>;

View file

@ -339,6 +339,14 @@ export class Profile extends EntityBase {
}) })
amount: Double; amount: Double;
@Column({
comment: "เงินพิเศษ",
default: 0,
nullable: true,
type: "double",
})
amountSpecial: Double;
@Column({ @Column({
comment: "เงินประจำตำแหน่ง", comment: "เงินประจำตำแหน่ง",
default: 0, default: 0,
@ -778,6 +786,8 @@ export class CreateProfileAllFields {
currentDistrictId: string | null; currentDistrictId: string | null;
currentSubDistrictId: string | null; currentSubDistrictId: string | null;
currentZipCode: string | null; currentZipCode: string | null;
amount?: Double | null;
amountSpecial?: Double | null;
} }
export type UpdateProfile = { export type UpdateProfile = {

View file

@ -592,6 +592,14 @@ export class ProfileEmployee extends EntityBase {
}) })
amount: Double; amount: Double;
@Column({
comment: "เงินพิเศษ",
default: 0,
nullable: true,
type: "double",
})
amountSpecial: Double;
@Column({ @Column({
comment: "เงินประจำตำแหน่ง", comment: "เงินประจำตำแหน่ง",
default: 0, default: 0,

View file

@ -95,6 +95,14 @@ export class ProfileSalary extends EntityBase {
}) })
amount: Double; amount: Double;
@Column({
comment: "เงินพิเศษ",
default: 0,
nullable: true,
type: "double",
})
amountSpecial: Double;
@Column({ @Column({
comment: "เงินประจำตำแหน่ง", comment: "เงินประจำตำแหน่ง",
default: 0, default: 0,
@ -184,6 +192,7 @@ export class CreateProfileSalary {
profileId: string; profileId: string;
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo: string | null; posNo: string | null;
@ -204,6 +213,7 @@ export class CreateProfileSalaryEmployee {
profileEmployeeId: string | null; profileEmployeeId: string | null;
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
commandId?: string | null; commandId?: string | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
@ -221,6 +231,7 @@ export class CreateProfileSalaryEmployee {
export class UpdateProfileSalaryEmployee { export class UpdateProfileSalaryEmployee {
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo: string | null; posNo: string | null;
@ -237,6 +248,7 @@ export class UpdateProfileSalaryEmployee {
export type UpdateProfileSalary = { export type UpdateProfileSalary = {
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo?: string | null; posNo?: string | null;

View file

@ -83,6 +83,14 @@ export class ProfileSalaryHistory extends EntityBase {
}) })
amount: Double; amount: Double;
@Column({
comment: "เงินพิเศษ",
default: 0,
nullable: true,
type: "double",
})
amountSpecial: Double;
@Column({ @Column({
comment: "เงินประจำตำแหน่ง", comment: "เงินประจำตำแหน่ง",
default: 0, default: 0,
@ -149,6 +157,7 @@ export class CreateProfileSalaryHistory {
profileId: string; profileId: string;
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo: string | null; posNo: string | null;
@ -165,6 +174,7 @@ export class CreateProfileSalaryHistory {
export class UpdateProfileSalaryHistory { export class UpdateProfileSalaryHistory {
date?: Date | null; date?: Date | null;
amount?: Double | null; amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
posNo?: string | null; posNo?: string | null;

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateKeyapiAddKeynameId1733318856709 implements MigrationInterface {
name = 'UpdateKeyapiAddKeynameId1733318856709'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`apiNameId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ApiName'`);
await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD CONSTRAINT \`FK_0b7ae98d4f342bf920339ada78b\` FOREIGN KEY (\`apiNameId\`) REFERENCES \`apiName\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP FOREIGN KEY \`FK_0b7ae98d4f342bf920339ada78b\``);
await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`apiNameId\``);
}
}

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableProfileSalaryAddAmountSpecial1733463321778 implements MigrationInterface {
name = 'UpdateTableProfileSalaryAddAmountSpecial1733463321778'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`amountSpecial\``);
}
}

View file

@ -0,0 +1,22 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class Update3table_addAmountSpecial1733471256767 implements MigrationInterface {
name = 'Update3table_addAmountSpecial1733471256767'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`amountSpecial\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`amountSpecial\``);
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`amountSpecial\``);
await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`amountSpecial\``);
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`amountSpecial\``);
}
}

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableCommandTypeAddIsSalary1733482389096 implements MigrationInterface {
name = 'UpdateTableCommandTypeAddIsSalary1733482389096'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandType\` ADD \`isSalary\` tinyint NOT NULL COMMENT 'สถานะแก้ไขเงินเดือน' DEFAULT 1`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandType\` DROP COLUMN \`isSalary\``);
}
}

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableAddField1733798795372 implements MigrationInterface {
name = 'UpdateTableAddField1733798795372'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`amountSpecial\``);
}
}

View file

@ -98,6 +98,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
commandId: command.id, commandId: command.id,
templateDoc: command.positionDetail, templateDoc: command.positionDetail,
amount: x.amount, amount: x.amount,
amountSpecial: x.amountSpecial,
positionSalaryAmount: x.positionSalaryAmount, positionSalaryAmount: x.positionSalaryAmount,
mouthSalaryAmount: x.mouthSalaryAmount, mouthSalaryAmount: x.mouthSalaryAmount,
})), })),