feat: add department dashboard

This commit is contained in:
ARJUN S THAMPI
2026-03-16 17:55:33 +05:30
parent aaa62ae3f5
commit 46bbd8106b
23 changed files with 1621 additions and 684 deletions

12
frontend/src/api/auth.ts Normal file
View File

@@ -0,0 +1,12 @@
import apiClient from "./client";
export const loginApi = async (
username: string,
password: string,
): Promise<any> => {
const response = await apiClient.post("/auth/login/", {
username,
password,
});
return response.data;
};

View File

@@ -0,0 +1,48 @@
import axios from "axios";
import type {InternalAxiosRequestConfig} from "axios";
const BASE_URL: string = "http://localhost:3000/api";
const apiClient = axios.create({
baseURL: BASE_URL,
headers: {
"Content-Type": "application/json",
},
});
export const setAxiosAuthToken = (token: string | null): void => {
if (token) {
apiClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
} else {
delete apiClient.defaults.headers.common["Authorization"];
}
};
apiClient.interceptors.request.use(
(config: InternalAxiosRequestConfig) => {
const token = localStorage.getItem("token");
if (token && config.headers) {
config.headers["Authorization"] = `Bearer ${token}`;
}
return config;
},
(error: any) => Promise.reject(error),
);
apiClient.interceptors.response.use(
(response) => response,
async (error) => {
if (error.response?.status === 401) {
console.error("Unauthorized - token missing or invalid");
localStorage.removeItem("token");
window.location.href = "/login";
}
return Promise.reject(error);
},
);
export default apiClient;

View File

@@ -0,0 +1,57 @@
import apiClient from "@/api/client";
export interface Department {
departmentId: string;
name: string;
para1: string;
para2: string;
para3: string;
facilities: string;
services: string;
}
/* ---------------- GET ALL ---------------- */
export const getDepartmentsApi = async () => {
const res = await apiClient.get("/departments/getAll");
return res.data;
};
/* ---------------- CREATE ---------------- */
export const createDepartmentApi = async (data: {
departmentId: string;
name: string;
para1?: string;
para2?: string;
para3?: string;
facilities?: string;
services?: string;
}) => {
const res = await apiClient.post("/departments", data);
return res.data;
};
/* ---------------- UPDATE ---------------- */
export const updateDepartmentApi = async (
id: number,
data: {
name?: string;
para1?: string;
para2?: string;
para3?: string;
facilities?: string;
services?: string;
},
) => {
const res = await apiClient.put(`/departments/${id}`, data);
return res.data;
};
/* ---------------- DELETE ---------------- */
export const deleteDepartmentApi = async (id: number) => {
const res = await apiClient.delete(`/departments/${id}`);
return res.data;
};