Merge branch 'develop' of github.com:Frappet/hrms-api-org into develop
This commit is contained in:
commit
67f820d283
3 changed files with 44 additions and 43 deletions
49
src/app.ts
49
src/app.ts
|
|
@ -12,14 +12,15 @@ import { RegisterRoutes } from "./routes";
|
||||||
import { OrganizationController } from "./controllers/OrganizationController";
|
import { OrganizationController } from "./controllers/OrganizationController";
|
||||||
import logMiddleware from "./middlewares/logs";
|
import logMiddleware from "./middlewares/logs";
|
||||||
import { CommandController } from "./controllers/CommandController";
|
import { CommandController } from "./controllers/CommandController";
|
||||||
// import { WebSocketServer } from "ws";
|
import { WebSocketServer } from "ws";
|
||||||
// import http from "http";
|
import http from "http";
|
||||||
// export const wss = new WebSocketServer({ noServer: true });
|
export const wss = new WebSocketServer({ noServer: true });
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await AppDataSource.initialize();
|
await AppDataSource.initialize();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
const server = http.createServer(app);
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
|
|
@ -70,8 +71,25 @@ async function main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
|
||||||
|
server.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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
wss.on("connection", (ws:any) => {
|
||||||
|
console.log("✅ Client connected to WebSocket");
|
||||||
|
|
||||||
|
ws.on("close", () => {
|
||||||
|
console.log("❌ Client disconnected");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
// app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
||||||
app.listen(
|
server.listen(
|
||||||
APP_PORT,
|
APP_PORT,
|
||||||
APP_HOST,
|
APP_HOST,
|
||||||
() => (
|
() => (
|
||||||
|
|
@ -90,29 +108,12 @@ async function main() {
|
||||||
|
|
||||||
runMessageQueue();
|
runMessageQueue();
|
||||||
|
|
||||||
// // สร้างเซิร์ฟเวอร์ HTTP
|
// สร้างเซิร์ฟเวอร์ HTTP
|
||||||
// const server = http.createServer(app);
|
|
||||||
|
|
||||||
// // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
|
|
||||||
// server.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);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// wss.on("connection", (ws:any) => {
|
// เริ่มเซิร์ฟเวอร์ที่พอร์ตปัจจุบัน
|
||||||
// console.log("✅ Client connected to WebSocket");
|
|
||||||
|
|
||||||
// ws.on("close", () => {
|
|
||||||
// console.log("❌ Client disconnected");
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // เริ่มเซิร์ฟเวอร์ที่พอร์ต 5000
|
|
||||||
// server.listen(APP_PORT, () => {
|
// server.listen(APP_PORT, () => {
|
||||||
// console.log("✅ HTTP Server is listening on port 5000");
|
// console.log("[APP] HTTP Server is listening on current port");
|
||||||
// });
|
// });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -402,7 +402,7 @@ export class ProfileController extends Controller {
|
||||||
*
|
*
|
||||||
* @param {string} id Id โปรไฟล์
|
* @param {string} id Id โปรไฟล์
|
||||||
*/
|
*/
|
||||||
@Get("kk1/{id}")
|
@Get("kk1old/{id}")
|
||||||
public async getKk1(@Path() id: string, @Request() req: RequestWithUser) {
|
public async getKk1(@Path() id: string, @Request() req: RequestWithUser) {
|
||||||
const profiles = await this.profileRepo.findOne({
|
const profiles = await this.profileRepo.findOne({
|
||||||
relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"],
|
relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"],
|
||||||
|
|
@ -874,7 +874,7 @@ export class ProfileController extends Controller {
|
||||||
*
|
*
|
||||||
* @param {string} id Id โปรไฟล์
|
* @param {string} id Id โปรไฟล์
|
||||||
*/
|
*/
|
||||||
@Get("kk1new/{id}")
|
@Get("kk1/{id}")
|
||||||
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
|
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
|
||||||
const profiles = await this.profileRepo.findOne({
|
const profiles = await this.profileRepo.findOne({
|
||||||
relations: ["currentSubDistrict", "currentDistrict", "currentProvince","registrationSubDistrict", "registrationDistrict", "registrationProvince", "profileAvatars"],
|
relations: ["currentSubDistrict", "currentDistrict", "currentProvince","registrationSubDistrict", "registrationDistrict", "registrationProvince", "profileAvatars"],
|
||||||
|
|
@ -1014,10 +1014,10 @@ export class ProfileController extends Controller {
|
||||||
? cert_raw.slice(-2).map((item) => ({
|
? cert_raw.slice(-2).map((item) => ({
|
||||||
certificateType: item.certificateType ?? null,
|
certificateType: item.certificateType ?? null,
|
||||||
issuer: item.issuer ?? null,
|
issuer: item.issuer ?? null,
|
||||||
certificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null,
|
certificateNo: item.certificateNo?Extension.ToThaiNumber(item.certificateNo):null,
|
||||||
issueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null,
|
issueDate: item.issueDate?Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)):null,
|
||||||
expireDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate)) ?? null,
|
expireDate: item.expireDate?Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate)):null,
|
||||||
issueToExpireDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? "" + item.expireDate?" - " + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate)): null,
|
issueToExpireDate: item.issueDate?Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)):"" + item.expireDate?" - " + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate)): null,
|
||||||
}))
|
}))
|
||||||
: [
|
: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ import { Profile } from "../entities/Profile";
|
||||||
import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer";
|
import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer";
|
||||||
import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee";
|
import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee";
|
||||||
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
|
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
|
||||||
// import { WebSocket } from "ws";
|
import { WebSocket } from "ws";
|
||||||
// import { wss } from "../app";
|
import { wss } from "../app";
|
||||||
|
|
||||||
@Route("api/v1/org/report")
|
@Route("api/v1/org/report")
|
||||||
@Tags("Report")
|
@Tags("Report")
|
||||||
|
|
@ -3565,17 +3565,17 @@ export class ReportController extends Controller {
|
||||||
}
|
}
|
||||||
// console.log(">>",data);
|
// console.log(">>",data);
|
||||||
|
|
||||||
// wss.clients.forEach((client: any) => {
|
wss.clients.forEach((client: any) => {
|
||||||
// if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
// const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } });
|
const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } });
|
||||||
// console.log("📤 Sending data to client:", message);
|
console.log("📤 Sending data to client:", message);
|
||||||
// client.send(message, (err:any) => {
|
client.send(message, (err:any) => {
|
||||||
// if (err) {
|
if (err) {
|
||||||
// console.error("❌ Error sending message:", err);
|
console.error("❌ Error sending message:", err);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
|
|
||||||
return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } });
|
return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue