Merge branch 'develop' of github.com:Frappet/hrms-api-org into develop
# Conflicts: # src/controllers/ReportController.ts
This commit is contained in:
commit
747b8e807a
4 changed files with 35 additions and 16 deletions
25
src/app.ts
25
src/app.ts
|
|
@ -13,18 +13,17 @@ import { OrganizationController } from "./controllers/OrganizationController";
|
|||
import logMiddleware from "./middlewares/logs";
|
||||
import { CommandController } from "./controllers/CommandController";
|
||||
import { ProfileSalaryController } from "./controllers/ProfileSalaryController";
|
||||
|
||||
import { WebSocketServer } from "ws";
|
||||
import http from "http";
|
||||
export const wss = new WebSocketServer({ noServer: true,
|
||||
path: "/api/v1/org/socket",
|
||||
path: "/api/vi/org/socket",
|
||||
});
|
||||
|
||||
async function main() {
|
||||
await AppDataSource.initialize();
|
||||
|
||||
|
||||
const app = express();
|
||||
// สร้างเซิร์ฟเวอร์ HTTP
|
||||
const server = http.createServer(app);
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
|
|
@ -64,7 +63,7 @@ async function main() {
|
|||
console.error("Error executing function from controller:", error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const cronTime_Oct = "0 0 1 10 *";
|
||||
cron.schedule(cronTime_Oct, async () => {
|
||||
try {
|
||||
|
|
@ -74,7 +73,7 @@ async function main() {
|
|||
console.error("Error executing function from controller:", error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const cronTime_Tenure = "0 0 * * *";
|
||||
cron.schedule(cronTime_Tenure, async () => {
|
||||
try {
|
||||
|
|
@ -108,7 +107,9 @@ async function main() {
|
|||
|
||||
runMessageQueue();
|
||||
|
||||
// การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
|
||||
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) => {
|
||||
|
|
@ -129,17 +130,11 @@ async function main() {
|
|||
});
|
||||
});
|
||||
|
||||
// ตั้งค่า Express routes
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello from Express!');
|
||||
});
|
||||
|
||||
server.listen(APP_PORT, APP_HOST, () => {
|
||||
console.log(`[APP] Application is running on: http://${APP_HOST}:${APP_PORT}`);
|
||||
console.log(`[APP] Swagger on: http://${APP_HOST}:${APP_PORT}/api-docs`);
|
||||
console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`);
|
||||
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`);
|
||||
console.log("[APP] HTTP Server is listening on current port");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -84,11 +84,11 @@ export class PermissionController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
}
|
||||
}
|
||||
|
||||
const getDetail = await this.authRoleRepo.findOne({
|
||||
select: ["id", "roleName", "roleDescription"],
|
||||
where: { id: posMaster.authRoleId },
|
||||
});
|
||||
|
||||
if (!getDetail) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +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 { sendWebSocket } from "../services/webSocket";
|
||||
|
||||
@Route("api/v1/org/report")
|
||||
@Tags("Report")
|
||||
|
|
@ -1367,6 +1368,7 @@ export class ReportController extends Controller {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpSuccess({ template: "report1", reportName: "report1", data: { data } });
|
||||
}
|
||||
|
||||
|
|
@ -3535,7 +3537,13 @@ export class ReportController extends Controller {
|
|||
}
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
// const metaData = { template: "report2", reportName: "report2", data: { data } };
|
||||
// sendWebSocket(metaData)
|
||||
|
||||
>>>>>>> b24a900198a2e83d621975fe9d657157de8ffccf
|
||||
return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } });
|
||||
}
|
||||
|
||||
|
|
|
|||
16
src/services/webSocket.ts
Normal file
16
src/services/webSocket.ts
Normal file
|
|
@ -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);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
Loading…
Add table
Add a link
Reference in a new issue