From b15ff0f5e329dc19b04301a25236426fe12a12f0 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 24 Mar 2021 20:48:45 +0100 Subject: [PATCH] [events] Sync route names --- src/plugins/schedule/store.ts | 42 ++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/plugins/schedule/store.ts b/src/plugins/schedule/store.ts index ecb934e..113fd8f 100644 --- a/src/plugins/schedule/store.ts +++ b/src/plugins/schedule/store.ts @@ -33,7 +33,7 @@ export const useScheduleStore = defineStore({ async getJobTypes(force = false) { if (force || this.jobTypes.length == 0) try { - const { data } = await api.get('/schedule/job-types'); + const { data } = await api.get('/events/job-types'); this.jobTypes = data; } catch (error) { throw error; @@ -42,24 +42,24 @@ export const useScheduleStore = defineStore({ }, async addJobType(name: string) { - await api.post('/schedule/job-types', { name: name }); + await api.post('/events/job-types', { name: name }); //TODO: HAndle new JT }, async removeJobType(id: number) { - await api.delete(`/schedule/job-types/${id}`); + await api.delete(`/events/job-types/${id}`); //Todo Handle delete JT }, async renameJobType(id: number, newName: string) { - await api.put(`/schedule/job-types/${id}`, { name: newName }); + await api.put(`/events/job-types/${id}`, { name: newName }); // TODO handle rename }, async getEventTypes(force = false) { if (force || this.eventTypes.length == 0) try { - const { data } = await api.get('/schedule/event-types'); + const { data } = await api.get('/events/event-types'); this.eventTypes = data; } catch (error) { throw error; @@ -75,7 +75,7 @@ export const useScheduleStore = defineStore({ */ async addEventType(name: string) { try { - const { data } = await api.post('/schedule/event-types', { name: name }); + const { data } = await api.post('/events/event-types', { name: name }); return data; } catch (error) { if ('response' in error) { @@ -87,7 +87,9 @@ export const useScheduleStore = defineStore({ }, async removeEvent(id: number) { try { - await api.delete(`/schedule/events/${id}`); + await api.delete(`/events/${id}`); + const idx = this.templates.findIndex((v) => v.id === id); + if (idx !== -1) this.templates.splice(idx, 1); } catch (e) { const error = e; if (error.response && error.response.status === 404) return false; @@ -97,13 +99,13 @@ export const useScheduleStore = defineStore({ }, async removeEventType(id: number) { - await api.delete(`/schedule/event-types/${id}`); + await api.delete(`/events/event-types/${id}`); // TODO handle delete }, async renameEventType(id: number, newName: string) { try { - await api.put(`/schedule/event-types/${id}`, { name: newName }); + await api.put(`/events/event-types/${id}`, { name: newName }); // TODO handle rename return true; } catch (error) { @@ -117,7 +119,7 @@ export const useScheduleStore = defineStore({ async getTemplates(force = false) { if (force || this.templates.length == 0) { - const { data } = await api.get('/schedule/templates'); + const { data } = await api.get('/events/templates'); data.forEach((element) => fixEvent(element)); this.templates = data; } @@ -126,19 +128,27 @@ export const useScheduleStore = defineStore({ async getEvents(filter: { from?: Date; to?: Date } | undefined = undefined) { try { - const { data } = await api.get('/schedule/events', { params: filter }); + const { data } = await api.get('/events', { params: filter }); data.forEach((element) => fixEvent(element)); return data; } catch (error) { throw error; } }, + + async getEvent(id: number) { + try { + const { data } = await api.get(`/events/${id}`); + fixEvent(data); + return data; + } catch (error) { + throw error; + } + }, + async updateJob(eventId: number, jobId: number, service: FG.Service | UserService) { try { - const { data } = await api.put( - `/schedule/events/${eventId}/jobs/${jobId}`, - service - ); + const { data } = await api.put(`/events/${eventId}/jobs/${jobId}`, service); fixJob(data); return data; } catch (error) { @@ -147,7 +157,7 @@ export const useScheduleStore = defineStore({ }, async addEvent(event: FG.Event) { - const { data } = await api.post('/schedule/events', event); + const { data } = await api.post('/events', event); if (data.is_template) this.templates.push(data); return data; },