Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import type { DiscoveryEvent } from '@/services/discovery'
|
|
import axiosInstance from '@/config/axios'
|
|
import { parseRemittanceList, unwrapApiPayload } from '@/helpers/listResponse'
|
|
|
|
export const getBookmarkStatus = async (eventId: string): Promise<boolean> => {
|
|
const response = await axiosInstance.get(`events/${eventId}/bookmark`)
|
|
|
|
return Boolean(unwrapApiPayload(response.data)?.isBookmarked)
|
|
}
|
|
|
|
export const getBookmarkStatuses = async (eventIds: string[]): Promise<Set<string>> => {
|
|
if (eventIds.length === 0) return new Set()
|
|
|
|
const response = await axiosInstance.post('events/bookmarks/status', { eventIds })
|
|
const payload = unwrapApiPayload<{ bookmarkedEventIds?: string[] }>(response.data)
|
|
const ids = payload.bookmarkedEventIds
|
|
|
|
return new Set(Array.isArray(ids) ? ids : [])
|
|
}
|
|
|
|
export const bookmarkEvent = async (eventId: string): Promise<void> => {
|
|
await axiosInstance.post(`events/${eventId}/bookmark`)
|
|
}
|
|
|
|
export const removeEventBookmark = async (eventId: string): Promise<void> => {
|
|
await axiosInstance.delete(`events/${eventId}/bookmark`)
|
|
}
|
|
|
|
export const getBookmarkedEvents = async (page = 1, pageSize = 40) => {
|
|
const response = await axiosInstance.get('events/bookmarks', { params: { page, pageSize, sort: '-createdAt' } })
|
|
const { items, pagination } = parseRemittanceList<DiscoveryEvent>(unwrapApiPayload(response.data) ?? response.data)
|
|
|
|
return { items, totalItemsCount: pagination.totalItemsCount }
|
|
}
|