mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 09:18:24 +00:00 
			
		
		
		
	Add user store
This commit is contained in:
		| @@ -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, | ||||
|  | ||||
|       } | ||||
| }); | ||||
|   | ||||
| @@ -1,5 +1,3 @@ | ||||
| import { fetchResults, makeFetch } from "../../../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods"; | ||||
|  | ||||
| import { Module } from "vuex"; | ||||
| 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; | ||||
|             } | ||||
|         }, | ||||
|     }, | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user