[events] Sync route names

This commit is contained in:
Ferdinand Thiessen 2021-03-24 20:48:45 +01:00
parent 6da4f67d68
commit b15ff0f5e3
1 changed files with 26 additions and 16 deletions

View File

@ -33,7 +33,7 @@ export const useScheduleStore = defineStore({
async getJobTypes(force = false) { async getJobTypes(force = false) {
if (force || this.jobTypes.length == 0) if (force || this.jobTypes.length == 0)
try { try {
const { data } = await api.get<FG.JobType[]>('/schedule/job-types'); const { data } = await api.get<FG.JobType[]>('/events/job-types');
this.jobTypes = data; this.jobTypes = data;
} catch (error) { } catch (error) {
throw error; throw error;
@ -42,24 +42,24 @@ export const useScheduleStore = defineStore({
}, },
async addJobType(name: string) { async addJobType(name: string) {
await api.post<FG.JobType>('/schedule/job-types', { name: name }); await api.post<FG.JobType>('/events/job-types', { name: name });
//TODO: HAndle new JT //TODO: HAndle new JT
}, },
async removeJobType(id: number) { async removeJobType(id: number) {
await api.delete(`/schedule/job-types/${id}`); await api.delete(`/events/job-types/${id}`);
//Todo Handle delete JT //Todo Handle delete JT
}, },
async renameJobType(id: number, newName: string) { 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 // TODO handle rename
}, },
async getEventTypes(force = false) { async getEventTypes(force = false) {
if (force || this.eventTypes.length == 0) if (force || this.eventTypes.length == 0)
try { try {
const { data } = await api.get<FG.EventType[]>('/schedule/event-types'); const { data } = await api.get<FG.EventType[]>('/events/event-types');
this.eventTypes = data; this.eventTypes = data;
} catch (error) { } catch (error) {
throw error; throw error;
@ -75,7 +75,7 @@ export const useScheduleStore = defineStore({
*/ */
async addEventType(name: string) { async addEventType(name: string) {
try { try {
const { data } = await api.post<FG.EventType>('/schedule/event-types', { name: name }); const { data } = await api.post<FG.EventType>('/events/event-types', { name: name });
return data; return data;
} catch (error) { } catch (error) {
if ('response' in error) { if ('response' in error) {
@ -87,7 +87,9 @@ export const useScheduleStore = defineStore({
}, },
async removeEvent(id: number) { async removeEvent(id: number) {
try { 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) { } catch (e) {
const error = <AxiosError>e; const error = <AxiosError>e;
if (error.response && error.response.status === 404) return false; if (error.response && error.response.status === 404) return false;
@ -97,13 +99,13 @@ export const useScheduleStore = defineStore({
}, },
async removeEventType(id: number) { async removeEventType(id: number) {
await api.delete(`/schedule/event-types/${id}`); await api.delete(`/events/event-types/${id}`);
// TODO handle delete // TODO handle delete
}, },
async renameEventType(id: number, newName: string) { async renameEventType(id: number, newName: string) {
try { try {
await api.put(`/schedule/event-types/${id}`, { name: newName }); await api.put(`/events/event-types/${id}`, { name: newName });
// TODO handle rename // TODO handle rename
return true; return true;
} catch (error) { } catch (error) {
@ -117,7 +119,7 @@ export const useScheduleStore = defineStore({
async getTemplates(force = false) { async getTemplates(force = false) {
if (force || this.templates.length == 0) { if (force || this.templates.length == 0) {
const { data } = await api.get<FG.Event[]>('/schedule/templates'); const { data } = await api.get<FG.Event[]>('/events/templates');
data.forEach((element) => fixEvent(element)); data.forEach((element) => fixEvent(element));
this.templates = data; this.templates = data;
} }
@ -126,19 +128,27 @@ export const useScheduleStore = defineStore({
async getEvents(filter: { from?: Date; to?: Date } | undefined = undefined) { async getEvents(filter: { from?: Date; to?: Date } | undefined = undefined) {
try { try {
const { data } = await api.get<FG.Event[]>('/schedule/events', { params: filter }); const { data } = await api.get<FG.Event[]>('/events', { params: filter });
data.forEach((element) => fixEvent(element)); data.forEach((element) => fixEvent(element));
return data; return data;
} catch (error) { } catch (error) {
throw error; throw error;
} }
}, },
async getEvent(id: number) {
try {
const { data } = await api.get<FG.Event>(`/events/${id}`);
fixEvent(data);
return data;
} catch (error) {
throw error;
}
},
async updateJob(eventId: number, jobId: number, service: FG.Service | UserService) { async updateJob(eventId: number, jobId: number, service: FG.Service | UserService) {
try { try {
const { data } = await api.put<FG.Job>( const { data } = await api.put<FG.Job>(`/events/${eventId}/jobs/${jobId}`, service);
`/schedule/events/${eventId}/jobs/${jobId}`,
service
);
fixJob(data); fixJob(data);
return data; return data;
} catch (error) { } catch (error) {
@ -147,7 +157,7 @@ export const useScheduleStore = defineStore({
}, },
async addEvent(event: FG.Event) { async addEvent(event: FG.Event) {
const { data } = await api.post<FG.Event>('/schedule/events', event); const { data } = await api.post<FG.Event>('/events', event);
if (data.is_template) this.templates.push(data); if (data.is_template) this.templates.push(data);
return data; return data;
}, },