1- import { useProfileStore } from "../../stores/profile" ;
1+ import { storeToRefs } from "pinia" ;
2+ import { useEventsStore , useProfileStore } from "../../stores" ;
23import type { EventId , EventType , ServerEvent } from '../../types' ;
34import { REST_API_URL } from "./constants" ;
45
@@ -16,10 +17,13 @@ type TUseEventsRequests = () => {
1617export const useEventsRequests : TUseEventsRequests = ( ) => {
1718 const { token } = storeToRefs ( useProfileStore ( ) )
1819
20+ const { activeProjectKey : project } = storeToRefs ( useEventsStore ( ) )
21+
1922 const headers = { "X-Auth-Token" : token . value }
20- const getEventRestUrl = ( param ?: string ) : string => `${ REST_API_URL } /api/event${ param ? `/${ param } ` : 's' } `
23+ const getEventRestUrl = ( param : string ) : string => `${ REST_API_URL } /api/event/${ param } ${ project . value ? `?project=${ project . value } ` : '' } `
24+ const getEventsRestUrl = ( ) : string => `${ REST_API_URL } /api/events${ project . value ? `?project=${ project . value } ` : '' } `
2125
22- const getAll = ( ) => fetch ( getEventRestUrl ( ) , { headers } )
26+ const getAll = ( ) => fetch ( getEventsRestUrl ( ) , { headers } )
2327 . then ( ( response ) => response . json ( ) )
2428 . then ( ( response ) => {
2529 if ( response ?. data ) {
@@ -46,17 +50,25 @@ export const useEventsRequests: TUseEventsRequests = () => {
4650 return null ;
4751 } )
4852
49- const deleteSingle = ( id : EventId ) => fetch ( getEventRestUrl ( id ) , { method : 'DELETE' , headers} )
53+ const deleteSingle = ( id : EventId ) => fetch ( getEventRestUrl ( id ) , {
54+ method : 'DELETE' ,
55+ headers,
56+ ...( project . value ? { body : JSON . stringify ( { project : project . value } ) } : null )
57+ } )
5058 . catch ( ( err ) => {
5159 console . error ( 'Fetch Error' , err )
5260 } )
5361
54- const deleteAll = ( ) => fetch ( getEventRestUrl ( ) , { method : 'DELETE' , headers} )
62+ const deleteAll = ( ) => fetch ( getEventsRestUrl ( ) , {
63+ method : 'DELETE' ,
64+ headers,
65+ ...( project . value ? { body : JSON . stringify ( { project : project . value } ) } : null )
66+ } )
5567 . catch ( ( err ) => {
5668 console . error ( 'Fetch Error' , err )
5769 } )
5870
59- const deleteList = ( uuids : EventId [ ] ) => fetch ( getEventRestUrl ( ) , {
71+ const deleteList = ( uuids : EventId [ ] ) => fetch ( getEventsRestUrl ( ) , {
6072 method : 'DELETE' ,
6173 headers,
6274 body : JSON . stringify ( { uuids} )
@@ -65,10 +77,13 @@ export const useEventsRequests: TUseEventsRequests = () => {
6577 console . error ( 'Fetch Error' , err )
6678 } )
6779
68- const deleteByType = ( type : EventType ) => fetch ( getEventRestUrl ( ) , {
80+ const deleteByType = ( type : EventType ) => fetch ( getEventsRestUrl ( ) , {
6981 method : 'DELETE' ,
7082 headers,
71- body : JSON . stringify ( { type} )
83+ body : JSON . stringify ( {
84+ type,
85+ ...( project . value ? { project : project . value } : null ) ,
86+ } )
7287 } )
7388 . catch ( ( err ) => {
7489 console . error ( 'Fetch Error' , err )
0 commit comments