import apiClient from './index.js' import { apiEndpoints as E } from './endpoints.js' import { paginatedGet } from './paginate.js' import { apiCall } from './apiError.js' // storyService passes story data through unchanged; tracked_flag is // authored by the view as 'Y'/'N' string and the backend accepts either. /** * Drop null/undefined keys so an empty UI filter doesn't turn into * `?student_id=undefined` over the wire. */ const cleanParams = (params) => { const out = {} for (const [k, v] of Object.entries(params || {})) { if (v !== null && v !== undefined) out[k] = v } return out } // Get all stories with optional filters export const getStories = (params = {}) => paginatedGet(apiClient, E.STORIES.LIST, cleanParams(params)) // Get a single story by id export const getStoryById = (storyId) => apiCall('GET', E.STORIES.DETAIL(storyId), null, 'Failed to fetch story detail') // Create story export const createStory = (data) => apiCall('POST', E.STORIES.LIST, { data }, 'Failed to create story') // Update story export const updateStory = (storyId, data) => apiCall('PATCH', E.STORIES.UPDATE(storyId), { data }, 'Failed to update story') // Delete story export const deleteStory = (storyId) => apiCall('DELETE', E.STORIES.DELETE(storyId), null, 'Failed to delete story')