Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-12-03 13:54:33 +07:00
commit e1d7f6966e
5 changed files with 72 additions and 70 deletions

View file

@ -52,6 +52,7 @@ jobs:
with:
context: .
platforms: linux/amd64
file: docker/Dockerfile
push: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
- name: Remote Deployment

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

@ -1615,10 +1615,10 @@ export class CommandController extends Controller {
persons: {
refId: string;
profileId?: string | null;
citizenId: string | null;
prefix: string | null;
firstName: string | null;
lastName: string | null;
citizenId?: string | null;
prefix?: string | null;
firstName?: string | null;
lastName?: string | null;
remarkVertical?: string | null;
remarkHorizontal?: string | null;
rootId?: string | null;
@ -2215,7 +2215,6 @@ export class CommandController extends Controller {
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date();
// profile.dateStart = new Date();
if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER");
}
@ -2236,21 +2235,25 @@ export class CommandController extends Controller {
const returnWork = await checkReturnCommandType(String(item.commandId));
//คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user
if (returnWork && item.isGovernment) {
/*if (profile.keycloak != null) {
const enableActive = await enableStatus(profile.keycloak, true);
if (!enableActive) throw new Error("Failed. Cannot change enable status.");
} else {*/
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
});
// if (typeof userKeycloakId !== "string") {
// throw new Error(userKeycloakId.errorMessage);
// }
const list = await getRoles();
if (!Array.isArray(list))
throw new Error("Failed. Cannot get role(s) data from the server.");
const result = await addUserRoles(
let userKeycloakId;
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
});
// กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่
if (profile.keycloak != null && userKeycloakId && userKeycloakId.error === "User exists with same username") {
const delUserKeycloak = await deleteUser(profile.keycloak);
if(delUserKeycloak) {
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
});
}
}
const list = await getRoles();
let result = false;
if (Array.isArray(list) && userKeycloakId) {
result = await addUserRoles(
userKeycloakId,
list
.filter((v) => v.name === "USER")
@ -2259,10 +2262,9 @@ export class CommandController extends Controller {
name: x.name,
})),
);
// if (!result) throw new Error("Failed. Cannot set user's role.");
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
/*}*/
}
profile.isActive = true;
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
}
await this.profileRepository.save(profile);

View file

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