Compare commits
No commits in common. "85c9b01bb2046d43862b8febd05fe0b731b770f6" and "4e189d7e52f7f36b95d31630113d53129bfb26e7" have entirely different histories.
85c9b01bb2
...
4e189d7e52
@ -1,9 +1,41 @@
|
|||||||
import { Application } from "@oak/oak";
|
import { Application, Router } from "@oak/oak";
|
||||||
import router from "./routes.ts";
|
import pool from "../shared/db.ts";
|
||||||
|
|
||||||
const app = new Application();
|
const app = new Application();
|
||||||
|
const router = new Router();
|
||||||
|
|
||||||
|
// Define the endpoint Sufail will call from the Vite frontend
|
||||||
|
router.get("/api/employees", async (ctx) => {
|
||||||
|
try {
|
||||||
|
const [rows] = await pool.query(
|
||||||
|
`SELECT
|
||||||
|
e.employee_code,
|
||||||
|
p.first_name,
|
||||||
|
p.last_name,
|
||||||
|
d.name AS department,
|
||||||
|
j.title AS designation,
|
||||||
|
c.work_email
|
||||||
|
FROM employees e
|
||||||
|
JOIN partners p ON e.partner_id = p.partner_id
|
||||||
|
JOIN contracts c ON e.employee_id = c.employee_id
|
||||||
|
JOIN departments d ON c.department_id = d.department_id
|
||||||
|
JOIN job_positions j ON c.job_id = j.job_id`
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.response.body = {
|
||||||
|
success: true,
|
||||||
|
count: (rows as any[]).length,
|
||||||
|
data: rows
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
ctx.response.status = 500;
|
||||||
|
ctx.response.body = {
|
||||||
|
success: false,
|
||||||
|
error: (error as Error).message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Register the routes and allowed methods from routes.ts
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
app.use(router.allowedMethods());
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
import { Router } from "@oak/oak";
|
|
||||||
import pool from "../shared/db.ts";
|
|
||||||
|
|
||||||
const router = new Router();
|
|
||||||
|
|
||||||
// GET all employees with their relational data
|
|
||||||
router.get("/api/employees", async (ctx) => {
|
|
||||||
try {
|
|
||||||
const [rows] = await pool.query(
|
|
||||||
`SELECT
|
|
||||||
e.employee_code,
|
|
||||||
p.first_name,
|
|
||||||
p.last_name,
|
|
||||||
d.name AS department,
|
|
||||||
j.title AS designation,
|
|
||||||
c.work_email
|
|
||||||
FROM employees e
|
|
||||||
JOIN partners p ON e.partner_id = p.partner_id
|
|
||||||
JOIN contracts c ON e.employee_id = c.employee_id
|
|
||||||
JOIN departments d ON c.department_id = d.department_id
|
|
||||||
JOIN job_positions j ON c.job_id = j.job_id`
|
|
||||||
);
|
|
||||||
|
|
||||||
ctx.response.body = {
|
|
||||||
success: true,
|
|
||||||
count: (rows as any[]).length,
|
|
||||||
data: rows
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
ctx.response.status = 500;
|
|
||||||
ctx.response.body = {
|
|
||||||
success: false,
|
|
||||||
error: (error as Error).message
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default router;
|
|
||||||
Loading…
x
Reference in New Issue
Block a user