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 { 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 { ProfileSalaryController } from "./controllers/ProfileSalaryController";
|
||||||
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,
|
||||||
path: "/api/v1/org/socket",
|
path: "/api/v1/org/socket",
|
||||||
});
|
});
|
||||||
|
|
@ -38,14 +37,14 @@ async function main() {
|
||||||
app.use("/", express.static("static"));
|
app.use("/", express.static("static"));
|
||||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
// app.use((req, res, next) => {
|
||||||
console.log(`Request received at: ${req.url}`);
|
// console.log(`Request received at: ${req.url}`);
|
||||||
next();
|
// next();
|
||||||
});
|
// });
|
||||||
|
|
||||||
app.get('/api', (req, res) => {
|
// app.get('/api', (req, res) => {
|
||||||
res.send('API route is working!');
|
// res.send('API route is working!');
|
||||||
});
|
// });
|
||||||
|
|
||||||
RegisterRoutes(app);
|
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, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
||||||
// app.listen(
|
// app.listen(
|
||||||
// APP_PORT,
|
// APP_PORT,
|
||||||
|
|
@ -126,7 +138,7 @@ async function main() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ตั้งค่า Express routes
|
// ตั้งค่า Express routes
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send('Hello from Express!');
|
res.send('Hello from Express!');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ export class ProfileSalaryController extends Controller {
|
||||||
await this.positionEmployeeRepo.clear();
|
await this.positionEmployeeRepo.clear();
|
||||||
const profile = await this.profileEmployeeRepo.find();
|
const profile = await this.profileEmployeeRepo.find();
|
||||||
for await (const x of profile) {
|
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 _position = position.length > 0 ? position[0] : [];
|
||||||
const mapPosition =
|
const mapPosition =
|
||||||
_position.length > 1
|
_position.length > 1
|
||||||
|
|
@ -176,7 +176,7 @@ export class ProfileSalaryController extends Controller {
|
||||||
await this.levelEmployeeRepo.clear();
|
await this.levelEmployeeRepo.clear();
|
||||||
const profile = await this.profileEmployeeRepo.find({ relations: ["posLevel"] });
|
const profile = await this.profileEmployeeRepo.find({ relations: ["posLevel"] });
|
||||||
for await (const x of profile) {
|
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 _positionLevel = positionLevel.length > 0 ? positionLevel[0] : [];
|
||||||
const mapPositionLevel =
|
const mapPositionLevel =
|
||||||
_positionLevel.length > 1
|
_positionLevel.length > 1
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,7 @@ 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 { sendWebSocket } from "../services/webSocket";
|
||||||
// import { WebSocket } from "ws";
|
|
||||||
// import { wss } from "../app";
|
|
||||||
|
|
||||||
@Route("api/v1/org/report")
|
@Route("api/v1/org/report")
|
||||||
@Tags("Report")
|
@Tags("Report")
|
||||||
|
|
@ -3540,21 +3538,9 @@ export class ReportController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log(">>",data);
|
const metaData = { template: "report2", reportName: "report2", data: { data } };
|
||||||
|
// sendWebSocket(metaData)
|
||||||
// wss.clients.forEach((client: any) => {
|
return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } });
|
||||||
// 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 } });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
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