diff --git a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/index.ts b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/index.ts index 82dd600a9..61c13b9b9 100644 --- a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/index.ts +++ b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/index.ts @@ -1,12 +1,14 @@ import { createStore } from "vuex"; import { State as MotiveStates, moduleMotive } from "./modules/motive"; import { State as TicketStates, moduleTicket } from "./modules/ticket"; -import { State as CommentStates, moduleComment } from "./modules/comment"; +import { State as CommentStates, moduleComment } from "./modules/comment"; +import { State as UserStates, moduleUser } from "./modules/user"; export type RootState = { motive: MotiveStates; ticket: TicketStates; comment: CommentStates; + user: UserStates; }; export const store = createStore({ @@ -14,6 +16,7 @@ export const store = createStore({ motive:moduleMotive, ticket:moduleTicket, comment:moduleComment, + user:moduleUser, } }); diff --git a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/ticket.ts b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/ticket.ts index 4e3a55762..c02b520eb 100644 --- a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/ticket.ts +++ b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/ticket.ts @@ -1,5 +1,3 @@ -import { fetchResults, makeFetch } from "../../../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods"; - import { Module } from "vuex"; import { RootState } from ".."; diff --git a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/user.ts b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/user.ts new file mode 100644 index 000000000..5fa9e8be1 --- /dev/null +++ b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/user.ts @@ -0,0 +1,70 @@ +import { + fetchResults, + makeFetch, +} from "../../../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods"; + +import { Module } from "vuex"; +import { RootState } from ".."; + +import { + User, + UserGroup, + UserGroupOrUser, +} from "../../../../../../../../ChillMainBundle/Resources/public/types"; + +export interface State { + userGroups: Array; + users: Array; +} + +export const moduleUser: Module = { + state: () => ({ + userGroups: [] as Array, + users: [] as Array, + }), + getters: { + getUserGroups(state) { + return state.userGroups; + }, + getUsers(state) { + return state.users; + }, + }, + mutations: {}, + actions: { + getUserGroups({ commit }) { + try { + fetchResults("/api/1.0/main/user-group.json").then( + (results) => { + commit("setUserGroups", results); + } + ); + } catch (e: any) { + throw e.name; + } + }, + getUsers({ commit }) { + try { + fetchResults("/1.0/main/user.json").then((results) => { + commit("setUserGroups", results); + }); + } catch (e: any) { + throw e.name; + } + }, + + async setAdressees({ commit }, datas: { ticketId: number; addressees: Array}) { + const { ticketId, addressees } = datas; + try { + const result = await makeFetch( + "POST", + `/api/1.0/ticket/${ticketId}/addressees/set`, + addressees + ); + commit("setTicket", result); + } catch (e: any) { + throw e.name; + } + }, + }, +};