From e924ae9ad21e6fcd743ac014142b44de81009414 Mon Sep 17 00:00:00 2001 From: veselovnk Date: Thu, 11 Apr 2024 17:17:29 +0300 Subject: [PATCH] MSP-3107 add accessListService --- src/constants/api/apiPaths.ts | 9 +++++- src/services/accessListService.ts | 35 ++++++++++++++++++++++ src/stores/index.tsx | 3 ++ src/type/accessList.type.ts | 48 +++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/services/accessListService.ts create mode 100644 src/type/accessList.type.ts diff --git a/src/constants/api/apiPaths.ts b/src/constants/api/apiPaths.ts index e34d694..1195bc5 100644 --- a/src/constants/api/apiPaths.ts +++ b/src/constants/api/apiPaths.ts @@ -10,6 +10,9 @@ type PathKeys = | 'logout' | 'getProfile' | 'getSystemTree' + | 'getById' + | 'setList' + | 'setOne' export const apiPaths: Record = { baseUrl: '/api/admin', baseSystemUrl: '/api/system', @@ -25,5 +28,9 @@ export const apiPaths: Record = { // ======= PROFILE ====== getProfile: '/api/admin/user/get_profile', // ======= APPLICATIONS ====== - getSystemTree: '/application/get_system_tree' + getSystemTree: '/application/get_system_tree', + // ======= ACCESS_LIST ====== + getById: '/access_list/get_by_id', + setList: '/access_list/set_list', + setOne: '/access_list/set_one' } diff --git a/src/services/accessListService.ts b/src/services/accessListService.ts new file mode 100644 index 0000000..0b22cdf --- /dev/null +++ b/src/services/accessListService.ts @@ -0,0 +1,35 @@ +import { createApi } from '@reduxjs/toolkit/query/react' + +import { apiPaths } from '@constants/api/apiPaths.ts' + +import { axiosBaseQuery } from '@utils/apiUtils.ts' + +import { + AccessListMethodType, + AccessListSetListRequestType, + AccessListSetListSetOneRequestType +} from '@type/accessList.type.ts' + + +const accessListApi = createApi({ + reducerPath: 'accessListApi', + refetchOnFocus: true, + tagTypes: ['AccessItems'], + baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }), + endpoints: (builder) => ({ + getById: builder.query({ + query: ({ id }) => ({ url: apiPaths.getById, data: { id } }), + providesTags: () => ['AccessItems'] + }), + setList: builder.mutation({ + query: (data) => ({ url: apiPaths.setList, data }), + invalidatesTags: () => ['AccessItems'] + }), + setOne: builder.mutation({ + query: (data) => ({ url: apiPaths.setOne, data }), + invalidatesTags: () => ['AccessItems'] + }) + }) +}) + +export default accessListApi diff --git a/src/stores/index.tsx b/src/stores/index.tsx index f313980..87044a3 100644 --- a/src/stores/index.tsx +++ b/src/stores/index.tsx @@ -3,6 +3,7 @@ import { theme } from 'antd' import { MapToken, SeedToken } from 'antd/es/theme/interface' import { createContext, Dispatch, SetStateAction } from 'react' +import accessListApi from '@services/accessListService.ts' import appApi from '@services/appService.ts' import roleApi from '@services/roleService.ts' @@ -23,6 +24,7 @@ const rootReducer = combineReducers({ profileReducer, [roleApi.reducerPath]: roleApi.reducer, [appApi.reducerPath]: appApi.reducer, + [accessListApi.reducerPath]: accessListApi.reducer }) export const setupStore = () => @@ -32,6 +34,7 @@ export const setupStore = () => getDefaultMiddleware().concat( roleApi.middleware, appApi.middleware, + accessListApi.middleware ) }) diff --git a/src/type/accessList.type.ts b/src/type/accessList.type.ts new file mode 100644 index 0000000..8295f19 --- /dev/null +++ b/src/type/accessList.type.ts @@ -0,0 +1,48 @@ +export interface AccessListMethodType { + method: string + value: boolean +} + +export interface AccessListSetListRequestType { + appId: number + methods: AccessListMethodType[] + removeOld?: boolean +} + +export interface AccessListSetListSetOneRequestType { + appId: number + method: string + value: boolean +} + +export interface EndpointType { + extra: Record + inner: boolean + path: string + userAuthRequired: boolean +} + +export type AddressType = { + ip: string + port: string +} + +export type RequiredModuleType = { + name: string + required: boolean +} + +export type RouteType = { + address: AddressType + endpoints: EndpointType[] + libVersion: string + moduleName: string + requiredModules: RequiredModuleType[] + version: string +} + +export interface RouteApiResponseType { + originalResponse: RouteType[] + moduleEndpoints: Record + allRouteMap: Record +}