Merge branch 'develop' into adiDev
This commit is contained in:
commit
26ef28f5cf
12 changed files with 1658 additions and 81 deletions
72
.github/workflows/release.yaml
vendored
72
.github/workflows/release.yaml
vendored
|
|
@ -67,40 +67,40 @@ jobs:
|
|||
docker compose pull
|
||||
docker compose up -d
|
||||
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
|
||||
# - name: Notify Discord Success
|
||||
# if: success()
|
||||
# run: |
|
||||
# curl -H "Content-Type: application/json" \
|
||||
# -X POST \
|
||||
# -d '{
|
||||
# "embeds": [{
|
||||
# "title": "✅ Deployment Success!",
|
||||
# "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
|
||||
# "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 Success
|
||||
if: success()
|
||||
run: |
|
||||
curl -H "Content-Type: application/json" \
|
||||
-X POST \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "✅ Deployment Success!",
|
||||
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
|
||||
"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()
|
||||
# run: |
|
||||
# curl -H "Content-Type: application/json" \
|
||||
# -X POST \
|
||||
# -d '{
|
||||
# "embeds": [{
|
||||
# "title": "❌ Deployment Failed!",
|
||||
# "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 }}
|
||||
- name: Notify Discord Failure
|
||||
if: failure()
|
||||
run: |
|
||||
curl -H "Content-Type: application/json" \
|
||||
-X POST \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "❌ Deployment Failed!",
|
||||
"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 }}
|
||||
|
|
|
|||
230
package-lock.json
generated
230
package-lock.json
generated
|
|
@ -29,6 +29,7 @@
|
|||
"querystring": "^0.2.1",
|
||||
"redis": "^3.1.2",
|
||||
"reflect-metadata": "^0.2.1",
|
||||
"socket.io": "^4.8.1",
|
||||
"swagger-ui-express": "^5.0.0",
|
||||
"tsoa": "^6.0.1",
|
||||
"typeorm": "^0.3.19",
|
||||
|
|
@ -347,6 +348,12 @@
|
|||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/@socket.io/component-emitter": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz",
|
||||
"integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@sqltools/formatter": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.5.tgz",
|
||||
|
|
@ -468,7 +475,6 @@
|
|||
"version": "2.8.17",
|
||||
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz",
|
||||
"integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
|
|
@ -873,6 +879,15 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"node_modules/base64id": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
||||
"integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^4.5.0 || >= 5.9"
|
||||
}
|
||||
},
|
||||
"node_modules/bignumber.js": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
|
||||
|
|
@ -1626,6 +1641,88 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io": {
|
||||
"version": "6.6.4",
|
||||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.4.tgz",
|
||||
"integrity": "sha512-ZCkIjSYNDyGn0R6ewHDtXgns/Zre/NT6Agvq1/WobF7JXgFff4SeDroKiCO3fNJreU9YG429Sc81o4w5ok/W5g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/node": ">=10.0.0",
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "2.0.0",
|
||||
"cookie": "~0.7.2",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.1",
|
||||
"engine.io-parser": "~5.2.1",
|
||||
"ws": "~8.17.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io-parser": {
|
||||
"version": "5.2.3",
|
||||
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz",
|
||||
"integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/cookie": {
|
||||
"version": "0.7.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
||||
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/engine.io/node_modules/ws": {
|
||||
"version": "8.17.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
|
||||
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/es-abstract": {
|
||||
"version": "1.22.3",
|
||||
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.22.3.tgz",
|
||||
|
|
@ -4153,6 +4250,137 @@
|
|||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io": {
|
||||
"version": "4.8.1",
|
||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.1.tgz",
|
||||
"integrity": "sha512-oZ7iUCxph8WYRHHcjBEc9unw3adt5CmSNlppj/5Q4k2RIrhl8Z5yY2Xr4j9zj0+wzVZ0bxmYoGSzKJnRl6A4yg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "~2.0.0",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.2",
|
||||
"engine.io": "~6.6.0",
|
||||
"socket.io-adapter": "~2.5.2",
|
||||
"socket.io-parser": "~4.2.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-adapter": {
|
||||
"version": "2.5.5",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz",
|
||||
"integrity": "sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "~4.3.4",
|
||||
"ws": "~8.17.1"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-adapter/node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-adapter/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/socket.io-adapter/node_modules/ws": {
|
||||
"version": "8.17.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
|
||||
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-parser": {
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz",
|
||||
"integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@socket.io/component-emitter": "~3.1.0",
|
||||
"debug": "~4.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-parser/node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-parser/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/socket.io/node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
"querystring": "^0.2.1",
|
||||
"redis": "^3.1.2",
|
||||
"reflect-metadata": "^0.2.1",
|
||||
"socket.io": "^4.8.1",
|
||||
"swagger-ui-express": "^5.0.0",
|
||||
"tsoa": "^6.0.1",
|
||||
"typeorm": "^0.3.19",
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ import logMiddleware from "./middlewares/logs";
|
|||
import { CommandController } from "./controllers/CommandController";
|
||||
import { ProfileSalaryController } from "./controllers/ProfileSalaryController";
|
||||
|
||||
// import { initWebSocket } from "./services/webSocket";
|
||||
import { initWebSocket } from "./services/webSocket";
|
||||
|
||||
async function main() {
|
||||
await AppDataSource.initialize();
|
||||
|
||||
// initWebSocket();
|
||||
initWebSocket();
|
||||
|
||||
const app = express();
|
||||
|
||||
|
|
|
|||
|
|
@ -3065,6 +3065,9 @@ export class CommandController extends Controller {
|
|||
commandCode?: string | null;
|
||||
commandName?: string | null;
|
||||
remark: string | null;
|
||||
positionTypeNew?: string | null;
|
||||
positionLevelNew?: string | null;
|
||||
positionNameNew?: string | null;
|
||||
}[];
|
||||
},
|
||||
) {
|
||||
|
|
@ -3145,6 +3148,9 @@ export class CommandController extends Controller {
|
|||
profile.leaveRemark = _null;
|
||||
profile.leaveDate = _null;
|
||||
profile.leaveType = _null;
|
||||
profile.position = item.positionNameNew ?? _null;
|
||||
profile.posTypeId = item.positionTypeNew ?? _null;
|
||||
profile.posLevelId = item.positionLevelNew ?? _null
|
||||
}
|
||||
let userKeycloakId;
|
||||
const checkUser = await getUserByUsername(profile.citizenId);
|
||||
|
|
|
|||
|
|
@ -5626,6 +5626,9 @@ export class OrganizationController extends Controller {
|
|||
|
||||
const data = await this.orgRootRepository.find({
|
||||
where: { orgRevisionId: orgRevisionActive.id },
|
||||
order: {
|
||||
orgRootOrder: "ASC",
|
||||
},
|
||||
});
|
||||
return new HttpSuccess(data.map((x) => x.id));
|
||||
}
|
||||
|
|
@ -5647,6 +5650,9 @@ export class OrganizationController extends Controller {
|
|||
|
||||
const data = await this.orgRootRepository.find({
|
||||
where: { orgRevisionId: orgRevisionActive.id },
|
||||
order: {
|
||||
orgRootOrder: "ASC",
|
||||
},
|
||||
});
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
|
@ -5686,6 +5692,7 @@ export class OrganizationController extends Controller {
|
|||
"orgChild1s.orgChild2s.orgChild3s.orgChild4s",
|
||||
],
|
||||
order: {
|
||||
orgRootOrder: "ASC",
|
||||
orgChild1s: {
|
||||
orgChild1Order: "ASC",
|
||||
orgChild2s: {
|
||||
|
|
|
|||
|
|
@ -198,4 +198,22 @@ export class ProfileAssistanceController extends Controller {
|
|||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Post("status")
|
||||
public async editStatusProfileAssistance(
|
||||
@Body() body: { status: string; refId: string },
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
const record = await this.profileAssistanceRepo.findOneBy({ refId: body.refId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
record.status = body.status.trim().toLocaleUpperCase();
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdatedAt = new Date();
|
||||
|
||||
this.profileAssistanceRepo.save(record);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,13 @@ export class ProfileAssistance extends EntityBase {
|
|||
})
|
||||
profileId: string;
|
||||
|
||||
@Column({
|
||||
comment: "สถานะ",
|
||||
default: "PENDING",
|
||||
length: 20,
|
||||
})
|
||||
status: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "หน่วยงานที่ให้ช่วยราชการ",
|
||||
|
|
|
|||
|
|
@ -464,10 +464,20 @@ export type LogSequence = {
|
|||
};
|
||||
|
||||
export function setLogDataDiff(req: RequestWithUser, data: DataDiff) {
|
||||
req.app.locals.logData.dataDiff = {
|
||||
before: JSON.stringify(data.before),
|
||||
after: JSON.stringify(data.after),
|
||||
};
|
||||
// Check if data.before and data.after are valid objects
|
||||
if (
|
||||
data.before &&
|
||||
typeof data.before === "object" &&
|
||||
data.after &&
|
||||
typeof data.after === "object"
|
||||
) {
|
||||
req.app.locals.logData.dataDiff = {
|
||||
before: JSON.stringify(data.before),
|
||||
after: JSON.stringify(data.after),
|
||||
};
|
||||
} else {
|
||||
console.error("Invalid data provided: both before and after must be valid objects.");
|
||||
}
|
||||
}
|
||||
|
||||
export function addLogSequence(req: RequestWithUser, data: LogSequence) {
|
||||
|
|
|
|||
1242
src/migration/1743480298636-update_01042512464.ts
Normal file
1242
src/migration/1743480298636-update_01042512464.ts
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -24,6 +24,7 @@ import { Position } from "../entities/Position";
|
|||
import { In, Not } from "typeorm";
|
||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import { PermissionOrg } from "../entities/PermissionOrg";
|
||||
import { sendWebSocket } from "./webSocket";
|
||||
|
||||
export let sendToQueue: (payload: any) => void;
|
||||
export let sendToQueueOrg: (payload: any) => void;
|
||||
|
|
@ -122,6 +123,15 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
relations: ["commandType", "commandRecives"],
|
||||
});
|
||||
if (!command) return true;
|
||||
sendWebSocket(
|
||||
"send-command-notification",
|
||||
{
|
||||
success: true,
|
||||
message: `ระบบทำการออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543}`,
|
||||
payload: command,
|
||||
},
|
||||
{ userId: user.sub },
|
||||
).catch(console.error);
|
||||
const path = commandTypePath(command.commandType.code);
|
||||
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||
return await new CallAPI()
|
||||
|
|
@ -156,11 +166,30 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
console.log("[AMQ] Excecute Command Success");
|
||||
Object.assign(command, { status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt });
|
||||
const result = await repo.save(command).catch((e) => console.log(e));
|
||||
if (result) return true;
|
||||
return false;
|
||||
|
||||
sendWebSocket(
|
||||
"send-command-notification",
|
||||
{
|
||||
success: true,
|
||||
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} เสร็จสิ้น`,
|
||||
payload: command,
|
||||
},
|
||||
{ userId: user.sub },
|
||||
).catch(console.error);
|
||||
|
||||
return !!result;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
sendWebSocket(
|
||||
"send-command-notification",
|
||||
{
|
||||
success: false,
|
||||
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} ผิดพลาด`,
|
||||
payload: command,
|
||||
},
|
||||
{ userId: user.sub },
|
||||
).catch(console.error);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,72 @@
|
|||
// import { WebSocketServer } from "ws";
|
||||
import { Server } from "socket.io";
|
||||
|
||||
// let wss: WebSocketServer;
|
||||
let io: Server;
|
||||
|
||||
// export function initWebSocket() {
|
||||
// wss = new WebSocketServer({ port: 13002, path: "/api/v1/org-socket" });
|
||||
export function initWebSocket() {
|
||||
if (io) return;
|
||||
|
||||
// // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
|
||||
// wss.on("upgrade", (request: any, socket: any, head: any) => {
|
||||
// console.log("🔹 Handling upgrade request...");
|
||||
// wss.handleUpgrade(request, socket, head, (ws: any) => {
|
||||
// console.log("🔹 WebSocket connection established");
|
||||
// wss.emit("connection", ws, request);
|
||||
// });
|
||||
// });
|
||||
io = new Server({ cors: { origin: "*" }, path: "/api/v1/org-socket" });
|
||||
|
||||
// wss.on("connection", (ws: any) => {
|
||||
// console.log("✅ Client connected to WebSocket");
|
||||
io.use(async (socket, next) => {
|
||||
const token = socket.handshake.auth.token;
|
||||
|
||||
// ws.on("close", () => {
|
||||
// console.log("❌ Client disconnected");
|
||||
// });
|
||||
const res = await fetch(`${process.env.AUTH_REALM_URL}/protocol/openid-connect/userinfo`, {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
}).catch((e) => console.error(e));
|
||||
|
||||
// ws.on("error", (error: any) => {
|
||||
// console.error("WebSocket error:", error);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
if (res?.ok) {
|
||||
socket.data.user = await res.json();
|
||||
}
|
||||
|
||||
// export async function sendWebSocket(data: any) {
|
||||
// if (!wss) initWebSocket();
|
||||
// wss.clients.forEach((client: any) => {
|
||||
// if (client.readyState === WebSocket.OPEN) {
|
||||
// const message = JSON.stringify(data);
|
||||
// console.log("📤 Sending data to client:", message);
|
||||
// client.send(message, (err: any) => {
|
||||
// if (err) {
|
||||
// console.error("❌ Error sending message:", err);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
next();
|
||||
});
|
||||
|
||||
io.on("connection", (ws) => {
|
||||
console.log("✅ Client connected to WebSocket");
|
||||
|
||||
ws.on("close", () => {
|
||||
console.log("❌ Client disconnected");
|
||||
});
|
||||
|
||||
ws.on("error", (error: any) => {
|
||||
console.error("WebSocket error:", error);
|
||||
});
|
||||
});
|
||||
|
||||
io.listen(13002);
|
||||
}
|
||||
|
||||
export async function sendWebSocket(
|
||||
event: string,
|
||||
data: any,
|
||||
opts?: {
|
||||
roles?: string | string[];
|
||||
userId?: string | string[];
|
||||
},
|
||||
) {
|
||||
if (!io) initWebSocket();
|
||||
|
||||
for (let [id, session] of io.of("/").sockets) {
|
||||
const user: {
|
||||
sub: string;
|
||||
name: string;
|
||||
given_name: string;
|
||||
family_name: string;
|
||||
preferred_username: string;
|
||||
email: string;
|
||||
role: string[];
|
||||
} = session.data.user;
|
||||
|
||||
if (!user) continue;
|
||||
|
||||
if (typeof opts?.roles === "string") opts.roles = [opts.roles];
|
||||
if (typeof opts?.userId === "string") opts.userId = [opts.userId];
|
||||
|
||||
if (
|
||||
user.role?.some((v) => opts?.roles?.includes(v)) ||
|
||||
opts?.userId?.some((v) => user.sub === v)
|
||||
) {
|
||||
io.to(id).emit(event, JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue