70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import api from "./api"
|
|
import type {
|
|
Event,
|
|
Trip,
|
|
Need,
|
|
VoyageLink,
|
|
VoyageData,
|
|
Permission,
|
|
} from "../types"
|
|
|
|
export const voyageService = {
|
|
// Events
|
|
async getEntityList<T>(voyageLinkId: string, entity: string): Promise<T[]> {
|
|
try {
|
|
const response: T[] = await api.get(`voyages/${voyageLinkId}/${entity}/`)
|
|
return response
|
|
} catch (error) {
|
|
console.error(`Error fetching ${entity}:`, error)
|
|
throw error
|
|
}
|
|
},
|
|
|
|
async createEntity<T>(
|
|
voyageLinkId: string,
|
|
entity: string,
|
|
data: Omit<T, "id">,
|
|
): Promise<T> {
|
|
try {
|
|
const response: T = await api.post(
|
|
`voyages/${voyageLinkId}/${entity}/`,
|
|
data,
|
|
)
|
|
return response
|
|
} catch (error) {
|
|
console.error(`Error creating ${entity}:`, error)
|
|
throw error
|
|
}
|
|
},
|
|
|
|
async updateEntity<T>(
|
|
voyageLinkId: string,
|
|
entity: string,
|
|
entityId: string,
|
|
data: Partial<T>,
|
|
): Promise<T> {
|
|
try {
|
|
const response: T = await api.put(
|
|
`voyages/${voyageLinkId}/${entity}/${entityId}/`,
|
|
data,
|
|
)
|
|
return response
|
|
} catch (error) {
|
|
console.error(`Error updating ${entity}:`, error)
|
|
throw error
|
|
}
|
|
},
|
|
|
|
async deleteEntity(
|
|
voyageLinkId: string,
|
|
entity: string,
|
|
entityId: string,
|
|
): Promise<void> {
|
|
try {
|
|
await api.delete(`voyages/${voyageLinkId}/${entity}/${entityId}/`)
|
|
} catch (error) {
|
|
console.error(`Error deleting ${entity}:`, error)
|
|
throw error
|
|
}
|
|
},
|
|
}
|