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

86 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-06-23 11:39:09 +05:30
import apiClient from '@/api/client';
import toast from 'react-hot-toast';
export type AccreditationType = 'ACCREDITATION' | 'CERTIFICATION';
export interface Accreditation {
id?: number;
title: string;
type: AccreditationType;
logo?: string;
image?: string;
description?: string;
sortOrder: number;
isActive: boolean;
createdAt?: string;
updatedAt?: string;
}
export const getAccreditationsApi = async (type?: AccreditationType) => {
const query = type ? `?type=${type}` : '';
const res = await apiClient.get(`/accreditation/getAll${query}`);
return res.data;
};
export const getAccreditationApi = async (id: number) => {
const res = await apiClient.get(`/accreditation/${id}`);
return res.data;
};
export const getActiveAccreditationsApi = async (type?: AccreditationType) => {
const query = type ? `?type=${type}` : '';
const res = await apiClient.get(`/accreditation/active${query}`);
return res.data;
};
export const createAccreditationApi = async (data: Partial<Accreditation>) => {
try {
const res = await apiClient.post('/accreditation', data);
toast.success('Accreditation created successfully');
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || 'Failed to create accreditation');
throw error;
}
};
export const updateAccreditationApi = async (id: number, data: Partial<Accreditation>) => {
try {
const res = await apiClient.put(`/accreditation/${id}`, data);
toast.success('Accreditation updated successfully');
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || 'Failed to update accreditation');
throw error;
}
};
export const deleteAccreditationApi = async (id: number) => {
try {
const res = await apiClient.delete(`/accreditation/${id}`);
toast.success('Accreditation deleted successfully');
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || 'Failed to delete accreditation');
throw error;
}
};