MSP-3107 add RouteService
This commit is contained in:
1 parent
e924ae9ad2
commit
bcf776d07e
3 files changed
+58
-3
No files matched your search
@@ -13,6 +13,7 @@ type PathKeys =
|
||||
| 'getById'
|
||||
| 'setList'
|
||||
| 'setOne'
|
||||
| 'getAllRoutes'
|
||||
export const apiPaths: Record<PathKeys, string> = {
|
||||
baseUrl: '/api/admin',
|
||||
baseSystemUrl: '/api/system',
|
||||
@@ -32,5 +33,6 @@ export const apiPaths: Record<PathKeys, string> = {
|
||||
// ======= ACCESS_LIST ======
|
||||
getById: '/access_list/get_by_id',
|
||||
setList: '/access_list/set_list',
|
||||
setOne: '/access_list/set_one'
|
||||
setOne: '/access_list/set_one',
|
||||
getAllRoutes: '/routing/get_routes'
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
import {
|
||||
EndpointType,
|
||||
RouteApiResponseType,
|
||||
RouteType
|
||||
} from '@type/accessList.type.ts'
|
||||
|
||||
|
||||
const routeApi = createApi({
|
||||
reducerPath: 'routeApi',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['Routes'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseConfigUrl }),
|
||||
endpoints: (builder) => ({
|
||||
getAllRoutes: builder.query<RouteApiResponseType, void>({
|
||||
query: () => ({ url: apiPaths.getAllRoutes }),
|
||||
transformResponse: (response: RouteType[]) => {
|
||||
const moduleEndpoints: Record<string, EndpointType[]> = {}
|
||||
const allRouteMap: Record<string, EndpointType> = {}
|
||||
|
||||
response.forEach((route) => {
|
||||
if (route.endpoints && route.endpoints.length) {
|
||||
moduleEndpoints[route.moduleName] = route.endpoints
|
||||
}
|
||||
})
|
||||
Object.keys(moduleEndpoints)
|
||||
.sort()
|
||||
.forEach((groupName) => {
|
||||
moduleEndpoints[groupName].forEach((method) => {
|
||||
allRouteMap[method.path] = method
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
originalResponse: response,
|
||||
moduleEndpoints: moduleEndpoints,
|
||||
allRouteMap: allRouteMap
|
||||
}
|
||||
},
|
||||
providesTags: () => ['Routes']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default routeApi
|
||||
@@ -6,6 +6,7 @@ import { createContext, Dispatch, SetStateAction } from 'react'
|
||||
import accessListApi from '@services/accessListService.ts'
|
||||
import appApi from '@services/appService.ts'
|
||||
import roleApi from '@services/roleService.ts'
|
||||
import routeApi from '@services/routeService.ts'
|
||||
|
||||
import profileReducer from './redusers/ProfileSlice.ts'
|
||||
|
||||
@@ -24,7 +25,8 @@ const rootReducer = combineReducers({
|
||||
profileReducer,
|
||||
[roleApi.reducerPath]: roleApi.reducer,
|
||||
[appApi.reducerPath]: appApi.reducer,
|
||||
[accessListApi.reducerPath]: accessListApi.reducer
|
||||
[accessListApi.reducerPath]: accessListApi.reducer,
|
||||
[routeApi.reducerPath]: routeApi.reducer
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
@@ -34,7 +36,8 @@ export const setupStore = () =>
|
||||
getDefaultMiddleware().concat(
|
||||
roleApi.middleware,
|
||||
appApi.middleware,
|
||||
accessListApi.middleware
|
||||
accessListApi.middleware,
|
||||
routeApi.middleware
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user