MSP-3203 create configService

This commit is contained in:
veselovnk committed 2024-05-08 12:22:11 +03:00
1 parent a8fb23b3d1
commit 4aeed36266
4 files changed
+103 -2

No files matched your search

+16 -1
View File
@@ -44,6 +44,13 @@ type PathKeys =
| 'getTokensByAppId'
| 'revokeTokens'
| 'revokeTokensForApp'
| 'getConfigsByModuleId'
| 'getConfigById'
| 'getAllVersions'
| 'createUpdateConfig'
| 'deleteVersion'
| 'deleteConfig'
| 'markConfigAsActive'
| 'getUI'
export const apiPaths: Record<PathKeys, string> = {
@@ -103,5 +110,13 @@ export const apiPaths: Record<PathKeys, string> = {
createToken: '/token/create_token',
getTokensByAppId: '/token/get_tokens_by_app_id',
revokeTokens: '/token/revoke_tokens',
revokeTokensForApp: '/token/revoke_tokens_for_app'
revokeTokensForApp: '/token/revoke_tokens_for_app',
// ======= CONFIGS ======
getConfigsByModuleId: '/config/get_configs_by_module_id',
getConfigById: '/config/get_config_by_id',
getAllVersions: '/config/get_all_version',
createUpdateConfig: '/config/create_update_config',
deleteVersion: '/config/delete_version',
deleteConfig: '/config/delete_config',
markConfigAsActive: '/config/mark_config_as_active'
}
+76
View File
@@ -0,0 +1,76 @@
import { createApi } from '@reduxjs/toolkit/query/react'
import { apiPaths } from '@constants/api/apiPaths.ts'
import { ConfigResponse, ConfigType } from '@pages/ModulesPage/module.type.ts'
import { axiosBaseQuery } from '@utils/apiUtils.ts'
import { VersionType } from '@type/version.type.ts'
const configServiceApi = createApi({
reducerPath: 'configApi',
tagTypes: ['configs', 'versions', 'config'],
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseConfigUrl }),
endpoints: (builder) => ({
getConfigsByModuleId: builder.query<ConfigResponse, string>({
query: (moduleId) => ({
url: apiPaths.getConfigsByModuleId,
data: { moduleId }
}),
transformResponse: (response: ConfigType[]): ConfigResponse => {
const activeObjects: ConfigType[] = []
const inactiveObjects: ConfigType[] = []
response.forEach((obj) => {
if (obj.active) {
activeObjects.push(obj)
} else {
inactiveObjects.push(obj)
}
})
return {
originalResponse: response,
activeConfigs: activeObjects,
inactiveConfigs: inactiveObjects
}
},
providesTags: () => ['configs']
}),
getConfigById: builder.query<ConfigType, string>({
query: (id) => ({
url: apiPaths.getConfigById,
data: { id }
}),
providesTags: () => ['config']
}),
getAllVersion: builder.query<VersionType[], string>({
query: (id) => ({
url: apiPaths.getAllVersions,
data: { id }
}),
transformResponse: (response: VersionType[]) => {
return response.sort((a, b) => b.configVersion - a.configVersion)
},
providesTags: () => ['versions']
}),
createUpdateConfig: builder.mutation<ConfigType, ConfigType>({
query: (data) => ({ url: apiPaths.createUpdateConfig, data }),
invalidatesTags: () => ['configs', 'versions']
}),
deleteVersion: builder.mutation<void, string>({
query: (id) => ({ url: apiPaths.deleteVersion, data: { id } }),
invalidatesTags: () => ['versions']
}),
deleteConfig: builder.mutation<void, string>({
query: (id) => ({ url: apiPaths.deleteVersion, data: [id] }),
invalidatesTags: () => ['versions']
}),
markConfigAsActive: builder.mutation<void, string>({
query: (id) => ({ url: apiPaths.markConfigAsActive, data: { id } }),
invalidatesTags: () => ['configs']
})
})
})
export default configServiceApi
+4 -1
View File
@@ -7,6 +7,7 @@ import accessListApi from '@services/accessListService.ts'
import appApi from '@services/appService.ts'
import applicationsGroupApi from '@services/applicationsGroupService.ts'
import applicationsApi from '@services/applicationsService.ts'
import configServiceApi from '@services/configService.ts'
import modulesServiceApi from '@services/modulesService.ts'
import roleApi from '@services/roleService.ts'
import routeApi from '@services/routeService.ts'
@@ -41,6 +42,7 @@ const rootReducer = combineReducers({
[modulesServiceApi.reducerPath]: modulesServiceApi.reducer,
[applicationsGroupApi.reducerPath]: applicationsGroupApi.reducer,
[applicationsApi.reducerPath]: applicationsApi.reducer,
[configServiceApi.reducerPath]: configServiceApi.reducer,
[tokensApi.reducerPath]: tokensApi.reducer
})
@@ -60,7 +62,8 @@ export const setupStore = () =>
modulesServiceApi.middleware,
applicationsGroupApi.middleware,
applicationsApi.middleware,
tokensApi.middleware
tokensApi.middleware,
configServiceApi.middleware
)
})
+7
View File
@@ -0,0 +1,7 @@
export interface VersionType {
id: string
configId: string
configVersion: number
createdAt: string
data: Record<string, unknown>
}