Client - init OAuth Applications list
This commit is contained in:
@ -3,6 +3,11 @@ import {
|
||||
AuthUserGetters,
|
||||
AuthUserMutations,
|
||||
} from '@/store/modules/authUser/enums'
|
||||
import {
|
||||
OAuth2Actions,
|
||||
OAuth2Getters,
|
||||
OAuth2Mutations,
|
||||
} from '@/store/modules/oauth2/enums'
|
||||
import {
|
||||
RootActions,
|
||||
RootGetters,
|
||||
@ -52,6 +57,11 @@ export const AUTH_USER_STORE = {
|
||||
GETTERS: AuthUserGetters,
|
||||
MUTATIONS: AuthUserMutations,
|
||||
}
|
||||
export const OAUTH2_STORE = {
|
||||
ACTIONS: OAuth2Actions,
|
||||
GETTERS: OAuth2Getters,
|
||||
MUTATIONS: OAuth2Mutations,
|
||||
}
|
||||
|
||||
export const USERS_STORE = {
|
||||
ACTIONS: UsersActions,
|
||||
|
36
fittrackee_client/src/store/modules/oauth2/actions.ts
Normal file
36
fittrackee_client/src/store/modules/oauth2/actions.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { ActionContext, ActionTree } from 'vuex'
|
||||
|
||||
import authApi from '@/api/authApi'
|
||||
import { OAUTH2_STORE, ROOT_STORE } from '@/store/constants'
|
||||
import { IOAuth2Actions, IOAuth2State } from '@/store/modules/oauth2/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IOauth2ClientsPayload } from '@/types/oauth'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
export const actions: ActionTree<IOAuth2State, IRootState> & IOAuth2Actions = {
|
||||
[OAUTH2_STORE.ACTIONS.GET_CLIENTS](
|
||||
context: ActionContext<IOAuth2State, IRootState>,
|
||||
payload: IOauth2ClientsPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
.get('oauth/apps', {
|
||||
params: payload,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context.commit(
|
||||
OAUTH2_STORE.MUTATIONS.SET_CLIENTS,
|
||||
res.data.data.clients
|
||||
)
|
||||
context.commit(
|
||||
OAUTH2_STORE.MUTATIONS.SET_CLIENTS_PAGINATION,
|
||||
res.data.pagination
|
||||
)
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
},
|
||||
}
|
13
fittrackee_client/src/store/modules/oauth2/enums.ts
Normal file
13
fittrackee_client/src/store/modules/oauth2/enums.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export enum OAuth2Actions {
|
||||
GET_CLIENTS = 'GET_CLIENTS',
|
||||
}
|
||||
|
||||
export enum OAuth2Getters {
|
||||
CLIENTS = 'CLIENTS',
|
||||
CLIENTS_PAGINATION = 'CLIENTS_PAGINATION',
|
||||
}
|
||||
|
||||
export enum OAuth2Mutations {
|
||||
SET_CLIENTS = 'SET_CLIENTS',
|
||||
SET_CLIENTS_PAGINATION = 'SET_CLIENTS_PAGINATION',
|
||||
}
|
11
fittrackee_client/src/store/modules/oauth2/getters.ts
Normal file
11
fittrackee_client/src/store/modules/oauth2/getters.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { GetterTree } from 'vuex'
|
||||
|
||||
import { OAUTH2_STORE } from '@/store/constants'
|
||||
import { IOAuth2Getters, IOAuth2State } from '@/store/modules/oauth2/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
|
||||
export const getters: GetterTree<IOAuth2State, IRootState> & IOAuth2Getters = {
|
||||
[OAUTH2_STORE.GETTERS.CLIENTS]: (state: IOAuth2State) => state.clients,
|
||||
[OAUTH2_STORE.GETTERS.CLIENTS_PAGINATION]: (state: IOAuth2State) =>
|
||||
state.pagination,
|
||||
}
|
17
fittrackee_client/src/store/modules/oauth2/index.ts
Normal file
17
fittrackee_client/src/store/modules/oauth2/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Module } from 'vuex'
|
||||
|
||||
import { actions } from '@/store/modules/oauth2/actions'
|
||||
import { getters } from '@/store/modules/oauth2/getters'
|
||||
import { mutations } from '@/store/modules/oauth2/mutations'
|
||||
import { oAuth2State } from '@/store/modules/oauth2/state'
|
||||
import { IOAuth2State } from '@/store/modules/oauth2/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
|
||||
const oauth2: Module<IOAuth2State, IRootState> = {
|
||||
state: oAuth2State,
|
||||
actions,
|
||||
getters,
|
||||
mutations,
|
||||
}
|
||||
|
||||
export default oauth2
|
21
fittrackee_client/src/store/modules/oauth2/mutations.ts
Normal file
21
fittrackee_client/src/store/modules/oauth2/mutations.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { MutationTree } from 'vuex'
|
||||
|
||||
import { OAUTH2_STORE } from '@/store/constants'
|
||||
import { IOAuth2State, TOAuth2Mutations } from '@/store/modules/oauth2/types'
|
||||
import { IPagination } from '@/types/api'
|
||||
import { IOAuth2Client } from '@/types/oauth'
|
||||
|
||||
export const mutations: MutationTree<IOAuth2State> & TOAuth2Mutations = {
|
||||
[OAUTH2_STORE.MUTATIONS.SET_CLIENTS](
|
||||
state: IOAuth2State,
|
||||
clients: IOAuth2Client[]
|
||||
) {
|
||||
state.clients = clients
|
||||
},
|
||||
[OAUTH2_STORE.MUTATIONS.SET_CLIENTS_PAGINATION](
|
||||
state: IOAuth2State,
|
||||
pagination: IPagination
|
||||
) {
|
||||
state.pagination = pagination
|
||||
},
|
||||
}
|
7
fittrackee_client/src/store/modules/oauth2/state.ts
Normal file
7
fittrackee_client/src/store/modules/oauth2/state.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IOAuth2State } from '@/store/modules/oauth2/types'
|
||||
import { IPagination } from '@/types/api'
|
||||
|
||||
export const oAuth2State: IOAuth2State = {
|
||||
clients: [],
|
||||
pagination: <IPagination>{},
|
||||
}
|
60
fittrackee_client/src/store/modules/oauth2/types.ts
Normal file
60
fittrackee_client/src/store/modules/oauth2/types.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import {
|
||||
ActionContext,
|
||||
CommitOptions,
|
||||
DispatchOptions,
|
||||
Store as VuexStore,
|
||||
} from 'vuex'
|
||||
|
||||
import { OAUTH2_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IPagination } from '@/types/api'
|
||||
import { IOAuth2Client, IOauth2ClientsPayload } from '@/types/oauth'
|
||||
|
||||
export interface IOAuth2State {
|
||||
clients: IOAuth2Client[]
|
||||
pagination: IPagination
|
||||
}
|
||||
|
||||
export interface IOAuth2Actions {
|
||||
[OAUTH2_STORE.ACTIONS.GET_CLIENTS](
|
||||
context: ActionContext<IOAuth2State, IRootState>,
|
||||
payload: IOauth2ClientsPayload
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IOAuth2Getters {
|
||||
[OAUTH2_STORE.GETTERS.CLIENTS](state: IOAuth2State): IOAuth2Client[]
|
||||
[OAUTH2_STORE.GETTERS.CLIENTS_PAGINATION](state: IOAuth2State): IPagination
|
||||
}
|
||||
|
||||
export type TOAuth2Mutations<S = IOAuth2State> = {
|
||||
[OAUTH2_STORE.MUTATIONS.SET_CLIENTS](state: S, clients: IOAuth2Client[]): void
|
||||
[OAUTH2_STORE.MUTATIONS.SET_CLIENTS_PAGINATION](
|
||||
state: S,
|
||||
pagination: IPagination
|
||||
): void
|
||||
}
|
||||
|
||||
export type TOAuth2StoreModule<S = IOAuth2State> = Omit<
|
||||
VuexStore<S>,
|
||||
'commit' | 'getters' | 'dispatch'
|
||||
> & {
|
||||
dispatch<K extends keyof IOAuth2Actions>(
|
||||
key: K,
|
||||
payload?: Parameters<IOAuth2Actions[K]>[1],
|
||||
options?: DispatchOptions
|
||||
): ReturnType<IOAuth2Actions[K]>
|
||||
} & {
|
||||
getters: {
|
||||
[K in keyof IOAuth2Getters]: ReturnType<IOAuth2Getters[K]>
|
||||
}
|
||||
} & {
|
||||
commit<
|
||||
K extends keyof TOAuth2Mutations,
|
||||
P extends Parameters<TOAuth2Mutations[K]>[1]
|
||||
>(
|
||||
key: K,
|
||||
payload?: P,
|
||||
options?: CommitOptions
|
||||
): ReturnType<TOAuth2Mutations[K]>
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { Module, ModuleTree } from 'vuex'
|
||||
|
||||
import authUserModule from '@/store/modules/authUser'
|
||||
import oAuthModule from '@/store/modules/oauth2'
|
||||
import { actions } from '@/store/modules/root/actions'
|
||||
import { getters } from '@/store/modules/root/getters'
|
||||
import { mutations } from '@/store/modules/root/mutations'
|
||||
@ -13,6 +14,7 @@ import workoutsModule from '@/store/modules/workouts'
|
||||
|
||||
const modules: ModuleTree<IRootState> = {
|
||||
authUserModule,
|
||||
oAuthModule,
|
||||
sportsModule,
|
||||
statsModule,
|
||||
usersModule,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { TAuthUserStoreModule } from '@/store/modules/authUser/types'
|
||||
import { TOAuth2StoreModule } from '@/store/modules/oauth2/types'
|
||||
import { TRootStoreModule } from '@/store/modules/root/types'
|
||||
import { TSportsStoreModule } from '@/store/modules/sports/types'
|
||||
import { TStatisticsStoreModule } from '@/store/modules/statistics/types'
|
||||
@ -7,6 +8,7 @@ import { TWorkoutsStoreModule } from '@/store/modules/workouts/types'
|
||||
|
||||
type StoreModules = {
|
||||
authUserModule: TAuthUserStoreModule
|
||||
oauth2Module: TOAuth2StoreModule
|
||||
rootModule: TRootStoreModule
|
||||
sportsModule: TSportsStoreModule
|
||||
statsModule: TStatisticsStoreModule
|
||||
@ -15,6 +17,7 @@ type StoreModules = {
|
||||
}
|
||||
|
||||
export type Store = TAuthUserStoreModule<Pick<StoreModules, 'authUserModule'>> &
|
||||
TOAuth2StoreModule<Pick<StoreModules, 'oauth2Module'>> &
|
||||
TSportsStoreModule<Pick<StoreModules, 'sportsModule'>> &
|
||||
TStatisticsStoreModule<Pick<StoreModules, 'statsModule'>> &
|
||||
TWorkoutsStoreModule<Pick<StoreModules, 'workoutsModule'>> &
|
||||
|
Reference in New Issue
Block a user