feat: facility and google review crud
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import apiClient from '@/api/client';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
export interface SeoData {
|
||||
seoTitle?: string;
|
||||
metaDescription?: string;
|
||||
focusKeyphrase?: string;
|
||||
slug?: string;
|
||||
tags?: string[];
|
||||
ogTitle?: string;
|
||||
ogDescription?: string;
|
||||
ogImage?: string;
|
||||
}
|
||||
|
||||
export interface FacilityImage {
|
||||
id?: number;
|
||||
url: string;
|
||||
altText?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface Facility {
|
||||
id?: number;
|
||||
facilityId: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
shortDescription?: string;
|
||||
description?: string;
|
||||
videoUrl?: string;
|
||||
isActive: boolean;
|
||||
isFeatured: boolean;
|
||||
sortOrder: number;
|
||||
departmentId?: number | null;
|
||||
department?: {
|
||||
id: number;
|
||||
departmentId: string;
|
||||
name: string;
|
||||
} | null;
|
||||
images?: FacilityImage[];
|
||||
seo?: SeoData | null;
|
||||
}
|
||||
|
||||
export const getAllFacilitiesApi = async () => {
|
||||
const res = await apiClient.get('/facilities/getAll?admin=true');
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getFacilityByIdApi = async (facilityId: string) => {
|
||||
const res = await apiClient.get(`/facilities/${facilityId}`);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getFeaturedFacilitiesApi = async () => {
|
||||
const res = await apiClient.get('/facilities/featured');
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const createFacilityApi = async (data: Partial<Facility> & SeoData) => {
|
||||
try {
|
||||
const res = await apiClient.post('/facilities', data);
|
||||
toast.success('Facility created successfully');
|
||||
return res.data;
|
||||
} catch (error: any) {
|
||||
toast.error(error?.response?.data?.message || 'Failed to create facility');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateFacilityApi = async (
|
||||
facilityId: string,
|
||||
data: Partial<Facility> & SeoData,
|
||||
action: 'toggleStatus' | 'toggleFeatured' | 'updateDetails' = 'updateDetails'
|
||||
) => {
|
||||
try {
|
||||
const res = await apiClient.patch(`/facilities/${facilityId}/${action}`, data);
|
||||
toast.success('Facility updated successfully');
|
||||
return res.data;
|
||||
} catch (error: any) {
|
||||
toast.error(error?.response?.data?.message || 'Failed to update facility');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteFacilityApi = async (facilityId: string) => {
|
||||
try {
|
||||
const res = await apiClient.delete(`/facilities/${facilityId}`);
|
||||
toast.success('Facility deleted successfully');
|
||||
return res.data;
|
||||
} catch (error: any) {
|
||||
toast.error(error?.response?.data?.message || 'Failed to delete facility');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user