Merge branch 'develop' of github.com:Frappet/hrms-api-org into develop
This commit is contained in:
commit
6638ec29c0
4 changed files with 44 additions and 30 deletions
32
src/app.ts
32
src/app.ts
|
|
@ -12,10 +12,9 @@ import { RegisterRoutes } from "./routes";
|
|||
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",
|
||||
});
|
||||
|
|
@ -38,14 +37,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);
|
||||
|
||||
|
|
@ -85,6 +84,19 @@ async function main() {
|
|||
}
|
||||
});
|
||||
|
||||
const cronTime_Tenure = "0 0 * * *";
|
||||
cron.schedule(cronTime_Tenure, async () => {
|
||||
try {
|
||||
const profileSalaryController = new ProfileSalaryController();
|
||||
await profileSalaryController.cronjobTenurePositionOfficer();
|
||||
await profileSalaryController.cronjobTenureLevelOfficer();
|
||||
await profileSalaryController.cronjobTenurePositionEmployee();
|
||||
await profileSalaryController.cronjobTenureLevelEmployee();
|
||||
} catch (error) {
|
||||
console.error("Error executing function from controller:", error);
|
||||
}
|
||||
});
|
||||
|
||||
// app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
||||
// app.listen(
|
||||
// APP_PORT,
|
||||
|
|
@ -126,7 +138,7 @@ async function main() {
|
|||
});
|
||||
});
|
||||
|
||||
// ตั้งค่า Express routes
|
||||
// ตั้งค่า Express routes
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello from Express!');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export class ProfileSalaryController extends Controller {
|
|||
await this.positionEmployeeRepo.clear();
|
||||
const profile = await this.profileEmployeeRepo.find();
|
||||
for await (const x of profile) {
|
||||
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [x.id]);
|
||||
const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?)", [x.id]);
|
||||
const _position = position.length > 0 ? position[0] : [];
|
||||
const mapPosition =
|
||||
_position.length > 1
|
||||
|
|
@ -176,7 +176,7 @@ export class ProfileSalaryController extends Controller {
|
|||
await this.levelEmployeeRepo.clear();
|
||||
const profile = await this.profileEmployeeRepo.find({ relations: ["posLevel"] });
|
||||
for await (const x of profile) {
|
||||
const positionLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?)", [x.id]);
|
||||
const positionLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [x.id]);
|
||||
const _positionLevel = positionLevel.length > 0 ? positionLevel[0] : [];
|
||||
const mapPositionLevel =
|
||||
_positionLevel.length > 1
|
||||
|
|
|
|||
|
|
@ -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 } });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
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