Client - init OAuth Applications list

This commit is contained in:
Sam
2022-05-28 16:16:36 +02:00
parent 489710c29d
commit 25decef696
25 changed files with 358 additions and 3 deletions

View File

@ -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,

View 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))
},
}

View 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',
}

View 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,
}

View 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

View 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
},
}

View File

@ -0,0 +1,7 @@
import { IOAuth2State } from '@/store/modules/oauth2/types'
import { IPagination } from '@/types/api'
export const oAuth2State: IOAuth2State = {
clients: [],
pagination: <IPagination>{},
}

View 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]>
}

View File

@ -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,

View File

@ -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'>> &