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

81 lines
1.7 KiB
TypeScript
Raw Normal View History

2026-05-26 15:48:01 +05:30
import apiClient from '@/api/client';
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 () => {
2026-05-26 15:48:01 +05:30
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 {
2026-05-26 15:48:01 +05:30
const res = await apiClient.post('/departments', data);
2026-05-11 10:51:34 +05:30
2026-05-26 15:48:01 +05:30
toast.success('Department created successfully');
2026-05-11 10:51:34 +05:30
return res.data;
} catch (error: any) {
2026-05-26 15:48:01 +05:30
toast.error(error?.response?.data?.message || 'Failed to create department');
2026-05-11 10:51:34 +05:30
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-26 15:48:01 +05:30
}
2026-03-16 17:55:33 +05:30
) => {
2026-05-11 10:51:34 +05:30
try {
const res = await apiClient.put(`/departments/${departmentId}`, data);
2026-05-26 15:48:01 +05:30
toast.success('Department updated successfully');
2026-05-11 10:51:34 +05:30
return res.data;
} catch (error: any) {
2026-05-26 15:48:01 +05:30
toast.error(error?.response?.data?.message || 'Failed to update department');
2026-05-11 10:51:34 +05:30
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}`);
2026-05-26 15:48:01 +05:30
toast.success('Department deleted successfully');
2026-05-11 10:51:34 +05:30
return res.data;
} catch (error: any) {
2026-05-26 15:48:01 +05:30
toast.error(error?.response?.data?.message || 'Failed to delete department');
2026-05-11 10:51:34 +05:30
throw error;
}
2026-03-16 17:55:33 +05:30
};