diff --git a/src/app.ts b/src/app.ts index ef51cf64..1fcfdb76 100644 --- a/src/app.ts +++ b/src/app.ts @@ -38,14 +38,14 @@ async function main() { app.use("/", express.static("static")); app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); - app.use((req, res, next) => { - console.log(`Request received at: ${req.url}`); - next(); - }); + // app.use((req, res, next) => { + // console.log(`Request received at: ${req.url}`); + // next(); + // }); - app.get('/api', (req, res) => { - res.send('API route is working!'); - }); + // app.get('/api', (req, res) => { + // res.send('API route is working!'); + // }); RegisterRoutes(app); @@ -139,18 +139,6 @@ async function main() { }); }); - wss.clients.forEach((client: any) => { - if (client.readyState === WebSocket.OPEN) { - const message = ""; - console.log("📤 Sending data to client:", message); - client.send(message, (err:any) => { - if (err) { - console.error("❌ Error sending message:", err); - } - }); - } - }); - // ā¸•ā¸ąāš‰ā¸‡ā¸„āšˆā¸˛ Express routes app.get('/', (req, res) => { res.send('Hello from Express!'); diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 8e2f2ad4..d1847536 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -31,9 +31,7 @@ import { Profile } from "../entities/Profile"; import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer"; import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; - -// import { WebSocket } from "ws"; -// import { wss } from "../app"; +import { sendWebSocket } from "../services/webSocket"; @Route("api/v1/org/report") @Tags("Report") @@ -3540,21 +3538,9 @@ export class ReportController extends Controller { } } } - // console.log(">>",data); - - // wss.clients.forEach((client: any) => { - // if (client.readyState === WebSocket.OPEN) { - // const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } }); - // console.log("📤 Sending data to client:", message); - // client.send(message, (err:any) => { - // if (err) { - // console.error("❌ Error sending message:", err); - // } - // }); - // } - // }); - - return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); + const metaData = { template: "report2", reportName: "report2", data: { data } }; + sendWebSocket(metaData) + // return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); } /** diff --git a/src/services/webSocket.ts b/src/services/webSocket.ts new file mode 100644 index 00000000..32ea70af --- /dev/null +++ b/src/services/webSocket.ts @@ -0,0 +1,16 @@ +import { WebSocket } from "ws"; +import { wss } from "../app"; + +export async function sendWebSocket(data:any){ + 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); + } + }); + } + }); +}