Compare commits
2 Commits
7a8ab80a84
...
e5fbe92dc5
| Author | SHA1 | Date | |
|---|---|---|---|
| e5fbe92dc5 | |||
| a24dd95d2a |
45
ems-service/controllers/lookup.controller.ts
Normal file
45
ems-service/controllers/lookup.controller.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import pool from "../../shared/db.ts";
|
||||||
|
|
||||||
|
export const getCompanies = async (ctx: any) => {
|
||||||
|
try {
|
||||||
|
const [rows] = await pool.query(`SELECT company_id, name FROM companies`);
|
||||||
|
ctx.response.status = 200;
|
||||||
|
ctx.response.body = { success: true, data: rows };
|
||||||
|
} catch (error) {
|
||||||
|
ctx.response.status = 500;
|
||||||
|
ctx.response.body = { success: false, error: (error as Error).message };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBranches = async (ctx: any) => {
|
||||||
|
try {
|
||||||
|
const [rows] = await pool.query(`SELECT branch_id, name, company_id FROM branches`);
|
||||||
|
ctx.response.status = 200;
|
||||||
|
ctx.response.body = { success: true, data: rows };
|
||||||
|
} catch (error) {
|
||||||
|
ctx.response.status = 500;
|
||||||
|
ctx.response.body = { success: false, error: (error as Error).message };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDepartments = async (ctx: any) => {
|
||||||
|
try {
|
||||||
|
const [rows] = await pool.query(`SELECT department_id, name, parent_id FROM departments`);
|
||||||
|
ctx.response.status = 200;
|
||||||
|
ctx.response.body = { success: true, data: rows };
|
||||||
|
} catch (error) {
|
||||||
|
ctx.response.status = 500;
|
||||||
|
ctx.response.body = { success: false, error: (error as Error).message };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getJobs = async (ctx: any) => {
|
||||||
|
try {
|
||||||
|
const [rows] = await pool.query(`SELECT job_id, title, department_id FROM job_positions`);
|
||||||
|
ctx.response.status = 200;
|
||||||
|
ctx.response.body = { success: true, data: rows };
|
||||||
|
} catch (error) {
|
||||||
|
ctx.response.status = 500;
|
||||||
|
ctx.response.body = { success: false, error: (error as Error).message };
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -4,10 +4,19 @@ import {
|
|||||||
createEmployee,
|
createEmployee,
|
||||||
getEmployeeById,
|
getEmployeeById,
|
||||||
updateEmployee,
|
updateEmployee,
|
||||||
deleteEmployee } from "./controllers/employee.controller.ts";
|
deleteEmployee
|
||||||
|
} from "./controllers/employee.controller.ts";
|
||||||
|
import {
|
||||||
|
getCompanies,
|
||||||
|
getBranches,
|
||||||
|
getDepartments,
|
||||||
|
getJobs
|
||||||
|
} from "./controllers/lookup.controller.ts";
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
|
// --- Employee Core Endpoints ---
|
||||||
|
|
||||||
// Retrieve all employees
|
// Retrieve all employees
|
||||||
router.get("/api/v1/employees", getEmployees);
|
router.get("/api/v1/employees", getEmployees);
|
||||||
|
|
||||||
@ -23,4 +32,18 @@ router.put("/api/v1/employees/:id", updateEmployee);
|
|||||||
// Deactivate an employee
|
// Deactivate an employee
|
||||||
router.delete("/api/v1/employees/:id", deleteEmployee);
|
router.delete("/api/v1/employees/:id", deleteEmployee);
|
||||||
|
|
||||||
|
// --- Organizational Lookup Endpoints ---
|
||||||
|
|
||||||
|
// Fetch legal entities and parent group structures.
|
||||||
|
router.get("/api/v1/companies", getCompanies);
|
||||||
|
|
||||||
|
//Fetch structural branch offices
|
||||||
|
router.get("/api/v1/branches", getBranches);
|
||||||
|
|
||||||
|
//List corporate departments and organizational chart reporting lines
|
||||||
|
router.get("/api/v1/departments", getDepartments);
|
||||||
|
|
||||||
|
//List company designations and employment titles.
|
||||||
|
router.get("/api/v1/jobs", getJobs);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
Loading…
x
Reference in New Issue
Block a user