Advertisement
bebo231312312321

Untitled

Jul 8th, 2025
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { requestFactory } from "./requester";
  2.  
  3. const apiUrl = process.env.REACT_APP_API_URL;
  4.  
  5. export const initiativeServiceFactory = (token) => {
  6.   const requester = requestFactory(token);
  7.  
  8.   return {
  9.     createInitiative: async (initiativeData) => {
  10.       return requester.post(`${apiUrl}/initiatives/create`, initiativeData);
  11.     },
  12.     // Draft endpoints
  13.     saveDraftInitiative: async (draftData) => {
  14.       return requester.post(`${apiUrl}/initiatives/draft/save`, draftData);
  15.     },
  16.  
  17.     updateDraftInitiative: async (id, draftData) => {
  18.       return requester.post(`${apiUrl}/initiatives/draft/save/${id}`, draftData);
  19.     },
  20.  
  21.     getAllDrafts: async (page = 1, limit = 6) => {
  22.       return requester.get(`${apiUrl}/initiatives/drafts?page=${page}&limit=${limit}`);
  23.     },
  24.  
  25.     getDraftById: async (id) => {
  26.       return requester.get(`${apiUrl}/initiatives/draft/${id}`);
  27.     },
  28.     toggleDraftStatus: async (identifier) => {
  29.  
  30.       return requester.patch(`${apiUrl}/initiatives/toggle-draft/${identifier}`);
  31.     },
  32.  
  33.     deleteDraftInitiative: async (draftId) => {
  34.       return requester.del(`${apiUrl}/initiatives/draft/${draftId}`);
  35.     },
  36.     getInitiativeById: async (id) => {
  37.       return requester.get(`${apiUrl}/initiatives/single/${id}`);
  38.     },
  39.     toggleBookmark: async (initiativeId) => {
  40.       return requester.post(`${apiUrl}/initiatives/bookmark/${initiativeId}`);
  41.     },
  42.     getAllBookmarkedInitiatives: async (email) => {
  43.       return requester.get(`${apiUrl}/initiatives/user-initiatives/${email}`);
  44.     },
  45.     getUserInitiatives: async (email) => {
  46.       return requester.get(`${apiUrl}/initiatives/user-initiatives/${email}`);
  47.     },
  48.  
  49.     getAllInitiatives: async (page = 1, limit = 6) => {
  50.       return requester.get(`${apiUrl}/initiatives/all?page=${page}&limit=${limit}`);
  51.     },
  52.  
  53.     updateInitiative: async (identifier, initiativeData) => {
  54.       // πŸ”§ Π£Π²Π΅Ρ€Π΅Ρ‚Π΅ сС, Ρ‡Π΅ endpoint-ΡŠΡ‚ ΠΏΡ€ΠΈΠ΅ΠΌΠ° ΠΊΠ°ΠΊΡ‚ΠΎ ID, Ρ‚Π°ΠΊΠ° ΠΈ slug
  55.       return requester.put(`${apiUrl}/initiatives/${identifier}`, initiativeData);
  56.     },
  57.     deleteInitiative: async (identifier) => {
  58.       // πŸ”§ Π£Π²Π΅Ρ€Π΅Ρ‚Π΅ сС, Ρ‡Π΅ endpoint-ΡŠΡ‚ ΠΏΡ€ΠΈΠ΅ΠΌΠ° ΠΊΠ°ΠΊΡ‚ΠΎ ID, Ρ‚Π°ΠΊΠ° ΠΈ slug
  59.       return requester.del(`${apiUrl}/initiatives/${identifier}`);
  60.     },
  61.  
  62.     // Initiative comments endpoints
  63.  
  64.     // БъздаванС Π½Π° ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€/reply
  65.     createComment: async (commentData) => {
  66.       const response = await requester.post(`${apiUrl}/comments/create`, commentData);
  67.       return response;
  68.     },
  69.     // ΠŸΠΎΠ»ΡƒΡ‡Π°Π²Π°Π½Π΅ Π½Π° всички ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈ Π·Π° ΠΈΠ½ΠΈΡ†ΠΈΠ°Ρ‚ΠΈΠ²Π°
  70.     getInitiativeComments: async (initiativeId) => {
  71.       return requester.get(`${apiUrl}/comments/all/initiative/${initiativeId}`);
  72.     },
  73.  
  74.     // ΠŸΠΎΠ»ΡƒΡ‡Π°Π²Π°Π½Π΅ Π½Π° всички ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈ Π·Π° ΠΏΡ€ΠΎΠ΅ΠΊΡ‚  
  75.     getProjectComments: async (projectId) => {
  76.       return requester.get(`${apiUrl}/comments/all/project/${projectId}`);
  77.     },
  78.     // ОбновяванС Π½Π° ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€/reply
  79.     updateComment: async (commentId, commentData) => {
  80.       // commentData: { content }
  81.       return requester.patch(`${apiUrl}/comments/${commentId}`, commentData);
  82.     },
  83.  
  84.     // Π˜Π·Ρ‚Ρ€ΠΈΠ²Π°Π½Π΅ Π½Π° ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€/reply
  85.     deleteComment: async (commentId) => {
  86.       return requester.del(`${apiUrl}/comments/${commentId}`);
  87.     },
  88.  
  89.     // Π₯арСсванС Π½Π° ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€/reply
  90.     likeComment: async (commentId) => {
  91.       const response = await requester.post(`${apiUrl}/comments/like/${commentId}`);
  92.       return response;
  93.     },
  94.  
  95.     getSingleComment: async (commentId) => {
  96.       return requester.get(`${apiUrl}/comments/single/${commentId}`);
  97.     },
  98.  
  99.     // Project endpoints
  100.     createProject: async (initiativeData) => {
  101.       return requester.post(`${apiUrl}/projects/create`, initiativeData);
  102.     },
  103.     getAllProjects: async () => {
  104.       return requester.get(`${apiUrl}/projects/all`);
  105.     },
  106.  
  107.     getProjectById: async (id) => {
  108.       return requester.get(`${apiUrl}/projects/single/${id}`);
  109.     },
  110.  
  111.     getProjectsByInitiative: async (initiativeId) => {
  112.       return requester.get(`${apiUrl}/projects/initiative/${initiativeId}`);
  113.     },
  114.     // Project Draft endpoints
  115.     saveDraftProject: async (draftData) => {
  116.       return requester.post(`${apiUrl}/projects/draft/save`, draftData);
  117.     },
  118.  
  119.     updateDraftProject: async (id, draftData) => {
  120.       return requester.post(`${apiUrl}/projects/draft/save/${id}`, draftData);
  121.     },
  122.  
  123.     getDraftProjectById: async (id) => {
  124.       return requester.get(`${apiUrl}/projects/draft/${id}`);
  125.     },
  126.  
  127.     deleteDraftProject: async (draftId) => {
  128.       return requester.del(`${apiUrl}/projects/draft/${draftId}`);
  129.     },
  130.  
  131.     toggleProjectDraftStatus: async (identifier) => {
  132.       return requester.patch(`${apiUrl}/projects/toggle-draft/${identifier}`);
  133.     },
  134.  
  135.     getAllProjectDrafts: async (page = 1, limit = 6) => {
  136.       return requester.get(`${apiUrl}/projects/drafts?page=${page}&limit=${limit}`);
  137.     },
  138.     //bookmark-project
  139.     toggleBookmarkProject: async (projectId) => {
  140.       return requester.post(`${apiUrl}/projects/bookmark/${projectId}`);
  141.     },
  142.     getAllBookmarkedProjects: async (email) => {
  143.       return requester.get(`${apiUrl}/projects/user-projects/${email}`);
  144.     },
  145.  
  146.     // Project applications endpoints
  147.     applyToProject: async (projectId, applicationData) => {
  148.       return requester.post(`${apiUrl}/projects/${projectId}/apply`, applicationData);
  149.     },
  150.  
  151.     getProjectApplications: async (projectId) => {
  152.       return requester.get(`${apiUrl}/projects/${projectId}/applications`);
  153.     },
  154.  
  155.     getAllApplications: async () => {
  156.       return requester.get(`${apiUrl}/applications/all`);
  157.     },
  158.  
  159.     updateApplicationStatus: async (applicationId, status) => {
  160.       return requester.patch(`${apiUrl}/applications/${applicationId}/status`, { status });
  161.     },
  162.  
  163.     deleteApplication: async (applicationId) => {
  164.       return requester.del(`${apiUrl}/applications/${applicationId}`);
  165.     },
  166.  
  167.     sendPersonalizedEmails: async (emailData) => {
  168.       return requester.post(`${apiUrl}/applications/send-personalized-emails`, emailData);
  169.     },
  170.   };
  171. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement