2024-05-13 10:51:12: merge [main:6f6359c4c01bf3e0cef37b14d6b016b7d5a1fa84];
This commit is contained in:
1 parent
2989c66a65
commit
739a9a3a4b
45 files changed
+4018
-309
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user