Files
gg-backend/frontend/src/api/department.ts
T

87 lines
1.7 KiB
TypeScript
Raw Normal View History

2026-03-16 17:55:33 +05:30
import apiClient from "@/api/client";
2026-05-11 10:51:34 +05:30
import toast from "react-hot-toast";
2026-03-16 17:55:33 +05:30
export interface Department {
departmentId: string;
name: string;
2026-04-14 17:33:21 +05:30
image?: string;
2026-03-16 17:55:33 +05:30
para1: string;
para2: string;
para3: string;
facilities: string;
services: string;
2026-05-11 10:51:34 +05:30
isActive?: boolean;
sortOrder?: number;
2026-03-16 17:55:33 +05:30
}
export const getDepartmentsApi = async () => {
const res = await apiClient.get("/departments/getAll?admin=true");
2026-03-16 17:55:33 +05:30
return res.data;
};
export const createDepartmentApi = async (data: {
departmentId: string;
name: string;
para1?: string;
para2?: string;
para3?: string;
facilities?: string;
services?: string;
}) => {
2026-05-11 10:51:34 +05:30
try {
const res = await apiClient.post("/departments", data);
toast.success("Department created successfully");
return res.data;
} catch (error: any) {
toast.error(
error?.response?.data?.message || "Failed to create department",
);
throw error;
}
2026-03-16 17:55:33 +05:30
};
export const updateDepartmentApi = async (
2026-03-17 13:11:00 +05:30
departmentId: string,
2026-03-16 17:55:33 +05:30
data: {
name?: string;
para1?: string;
para2?: string;
para3?: string;
facilities?: string;
services?: string;
},
) => {
2026-05-11 10:51:34 +05:30
try {
const res = await apiClient.put(`/departments/${departmentId}`, data);
toast.success("Department updated successfully");
return res.data;
} catch (error: any) {
toast.error(
error?.response?.data?.message || "Failed to update department",
);
throw error;
}
2026-03-16 17:55:33 +05:30
};
2026-03-17 13:11:00 +05:30
export const deleteDepartmentApi = async (departmentId: string) => {
2026-05-11 10:51:34 +05:30
try {
const res = await apiClient.delete(`/departments/${departmentId}`);
toast.success("Department deleted successfully");
return res.data;
} catch (error: any) {
toast.error(
error?.response?.data?.message || "Failed to delete department",
);
throw error;
}
2026-03-16 17:55:33 +05:30
};