calendar create and delete
This commit is contained in:
parent
762a9f2b8e
commit
792be3b497
7 changed files with 411 additions and 16 deletions
77
src/stores/admin/calendar.ts
Normal file
77
src/stores/admin/calendar.ts
Normal file
|
@ -0,0 +1,77 @@
|
|||
import { defineStore } from "pinia";
|
||||
import type {
|
||||
CreateCalendarViewModel,
|
||||
UpdateCalendarViewModel,
|
||||
CalendarViewModel,
|
||||
} from "@/viewmodels/admin/calendar.models";
|
||||
import { http } from "@/serverCom";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
export const useCalendarStore = defineStore("calendar", {
|
||||
state: () => {
|
||||
return {
|
||||
calendars: [] as Array<CalendarViewModel>,
|
||||
loading: "loading" as "loading" | "fetched" | "failed",
|
||||
loadingFields: "loading" as "loading" | "fetched" | "failed",
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
formattedItems: (state) => {
|
||||
return state.calendars.map((c) => ({
|
||||
id: c.id,
|
||||
title: c.title,
|
||||
start: c.starttime,
|
||||
end: c.endtime,
|
||||
backgroundColor: c.type.color,
|
||||
}));
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
fetchCalendars() {
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get("/admin/calendar/items")
|
||||
.then((result) => {
|
||||
this.calendars = result.data;
|
||||
this.loading = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
fetchCalendarById(id: number): Promise<AxiosResponse<any, any>> {
|
||||
return http.get(`/admin/calendar/item/${id}`);
|
||||
},
|
||||
async createCalendar(calendar: CreateCalendarViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.post(`/admin/calendar/item`, {
|
||||
starttime: calendar.starttime,
|
||||
endtime: calendar.endtime,
|
||||
title: calendar.title,
|
||||
content: calendar.content,
|
||||
allDay: calendar.allDay,
|
||||
location: calendar.location,
|
||||
typeId: calendar.typeId,
|
||||
});
|
||||
this.fetchCalendars();
|
||||
return result;
|
||||
},
|
||||
async updateActiveCalendar(calendar: UpdateCalendarViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/calendar/item/${calendar.id}`, {
|
||||
starttime: calendar.starttime,
|
||||
endtime: calendar.endtime,
|
||||
title: calendar.title,
|
||||
content: calendar.content,
|
||||
allDay: calendar.allDay,
|
||||
location: calendar.location,
|
||||
typeId: calendar.typeId,
|
||||
});
|
||||
this.fetchCalendars();
|
||||
return result;
|
||||
},
|
||||
async deleteCalendar(calendar: number): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.delete(`/admin/calendar/item/${calendar}`);
|
||||
this.fetchCalendars();
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue