Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#151 update preview events endpoint #173

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/shared/lib/io/use-events-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type TUseEventsRequests = () => {
deleteList: (uuids: EventId[]) => Promise<void | Response>,
deleteSingle: (id: EventId) => Promise<void | Response>,
deleteByType: (type: EventType) => Promise<void | Response>,
getEventRestUrl: (param: EventId | undefined) => string
getEventRestUrl: (param: EventId) => string
}

// TODO: add 403 response handling
Expand All @@ -18,9 +18,10 @@ export const useEventsRequests: TUseEventsRequests = () => {
const app = useNuxtApp()
const {token} = app.$authToken ?? {token: null}
const headers = {"X-Auth-Token": token || ''}
const getEventRestUrl = (param?: string): string => `${REST_API_URL}/api/event${param ? `/${param}` : 's'}`
const getEventRestUrl = (param: string): string => `${REST_API_URL}/api/event/${param}`
const getEventsRestUrl = (): string => `${REST_API_URL}/api/events/preview`

const getAll = () => fetch(getEventRestUrl(), { headers })
const getAll = () => fetch(getEventsRestUrl(), { headers })
.then((response) => response.json())
.then((response) => {
if (response?.data) {
Expand Down Expand Up @@ -52,12 +53,12 @@ export const useEventsRequests: TUseEventsRequests = () => {
console.error('Fetch Error', err)
})

const deleteAll = () => fetch(getEventRestUrl(), {method: 'DELETE', headers})
const deleteAll = () => fetch(getEventsRestUrl(), {method: 'DELETE', headers})
.catch((err) => {
console.error('Fetch Error', err)
})

const deleteList = (uuids: EventId[]) => fetch(getEventRestUrl(), {
const deleteList = (uuids: EventId[]) => fetch(getEventsRestUrl(), {
method: 'DELETE',
headers,
body: JSON.stringify({uuids})
Expand All @@ -66,7 +67,7 @@ export const useEventsRequests: TUseEventsRequests = () => {
console.error('Fetch Error', err)
})

const deleteByType = (type: EventType) => fetch(getEventRestUrl(), {
const deleteByType = (type: EventType) => fetch(getEventsRestUrl(), {
method: 'DELETE',
headers,
body: JSON.stringify({type})
Expand Down
Loading