mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 14:24:24 +00:00
Add user store
This commit is contained in:
parent
a27d92aba0
commit
7b8cd90cf1
@ -1,12 +1,14 @@
|
|||||||
import { createStore } from "vuex";
|
import { createStore } from "vuex";
|
||||||
import { State as MotiveStates, moduleMotive } from "./modules/motive";
|
import { State as MotiveStates, moduleMotive } from "./modules/motive";
|
||||||
import { State as TicketStates, moduleTicket } from "./modules/ticket";
|
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 = {
|
export type RootState = {
|
||||||
motive: MotiveStates;
|
motive: MotiveStates;
|
||||||
ticket: TicketStates;
|
ticket: TicketStates;
|
||||||
comment: CommentStates;
|
comment: CommentStates;
|
||||||
|
user: UserStates;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const store = createStore({
|
export const store = createStore({
|
||||||
@ -14,6 +16,7 @@ export const store = createStore({
|
|||||||
motive:moduleMotive,
|
motive:moduleMotive,
|
||||||
ticket:moduleTicket,
|
ticket:moduleTicket,
|
||||||
comment:moduleComment,
|
comment:moduleComment,
|
||||||
|
user:moduleUser,
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { fetchResults, makeFetch } from "../../../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
|
||||||
|
|
||||||
import { Module } from "vuex";
|
import { Module } from "vuex";
|
||||||
import { RootState } from "..";
|
import { RootState } from "..";
|
||||||
|
|
||||||
|
@ -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<UserGroup>;
|
||||||
|
users: Array<User>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const moduleUser: Module<State, RootState> = {
|
||||||
|
state: () => ({
|
||||||
|
userGroups: [] as Array<UserGroup>,
|
||||||
|
users: [] as Array<User>,
|
||||||
|
}),
|
||||||
|
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<UserGroupOrUser>}) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user