feat: add newsletter service for subscription functionality
This service was missing from the repository, causing build failures.
This commit is contained in:
parent
44e2952fa1
commit
988296ba39
52
services/newsletter.service.ts
Normal file
52
services/newsletter.service.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { api } from './api';
|
||||||
|
import { API_ENDPOINTS } from '@/utils/constants';
|
||||||
|
|
||||||
|
export interface NewsletterSubscribeData {
|
||||||
|
email: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiResponse<T = any> {
|
||||||
|
success: boolean;
|
||||||
|
message?: string;
|
||||||
|
data?: T;
|
||||||
|
count?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const newsletterService = {
|
||||||
|
// Subscribe to newsletter
|
||||||
|
subscribe: async (data: NewsletterSubscribeData): Promise<ApiResponse> => {
|
||||||
|
// Newsletter subscription doesn't require authentication
|
||||||
|
const response = await api.post<ApiResponse>(
|
||||||
|
API_ENDPOINTS.NEWSLETTER.SUBSCRIBE,
|
||||||
|
data,
|
||||||
|
{ token: '' } // No token needed for public endpoint
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Unsubscribe from newsletter
|
||||||
|
unsubscribe: async (email: string): Promise<ApiResponse> => {
|
||||||
|
const response = await api.post<ApiResponse>(
|
||||||
|
API_ENDPOINTS.NEWSLETTER.UNSUBSCRIBE,
|
||||||
|
{ email },
|
||||||
|
{ token: '' } // No token needed for public endpoint
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Get all subscribers (Admin only)
|
||||||
|
getSubscribers: async (): Promise<ApiResponse> => {
|
||||||
|
const response = await api.get<ApiResponse>(
|
||||||
|
API_ENDPOINTS.NEWSLETTER.SUBSCRIBERS
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Get active subscriber count (Admin only)
|
||||||
|
getActiveCount: async (): Promise<number> => {
|
||||||
|
const response = await api.get<ApiResponse>(
|
||||||
|
API_ENDPOINTS.NEWSLETTER.COUNT
|
||||||
|
);
|
||||||
|
return response.count || 0;
|
||||||
|
},
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user