|
| 1 | +import { Res } from 'common/types/responses' |
| 2 | +import { Req } from 'common/types/requests' |
| 3 | +import { service } from 'common/service' |
| 4 | + |
| 5 | +export const scimConfigurationService = service |
| 6 | + .enhanceEndpoints({ |
| 7 | + addTagTypes: ['ScimConfiguration'], |
| 8 | + }) |
| 9 | + .injectEndpoints({ |
| 10 | + endpoints: (builder) => ({ |
| 11 | + createScimConfiguration: builder.mutation< |
| 12 | + Res['scimConfigurationWithToken'], |
| 13 | + Req['createScimConfiguration'] |
| 14 | + >({ |
| 15 | + invalidatesTags: (_res, _err, query) => [ |
| 16 | + { id: query.organisation_id, type: 'ScimConfiguration' }, |
| 17 | + ], |
| 18 | + query: (query: Req['createScimConfiguration']) => ({ |
| 19 | + method: 'POST', |
| 20 | + url: `organisations/${query.organisation_id}/scim/`, |
| 21 | + }), |
| 22 | + }), |
| 23 | + deleteScimConfiguration: builder.mutation< |
| 24 | + void, |
| 25 | + Req['deleteScimConfiguration'] |
| 26 | + >({ |
| 27 | + invalidatesTags: (_res, _err, query) => [ |
| 28 | + { id: query.organisation_id, type: 'ScimConfiguration' }, |
| 29 | + ], |
| 30 | + query: (query: Req['deleteScimConfiguration']) => ({ |
| 31 | + method: 'DELETE', |
| 32 | + url: `organisations/${query.organisation_id}/scim/`, |
| 33 | + }), |
| 34 | + }), |
| 35 | + getScimConfiguration: builder.query< |
| 36 | + Res['scimConfiguration'], |
| 37 | + Req['getScimConfiguration'] |
| 38 | + >({ |
| 39 | + providesTags: (_res, _err, query) => [ |
| 40 | + { id: query.organisation_id, type: 'ScimConfiguration' }, |
| 41 | + ], |
| 42 | + query: (query: Req['getScimConfiguration']) => ({ |
| 43 | + url: `organisations/${query.organisation_id}/scim/`, |
| 44 | + }), |
| 45 | + }), |
| 46 | + regenerateScimToken: builder.mutation< |
| 47 | + Res['scimConfigurationWithToken'], |
| 48 | + Req['regenerateScimToken'] |
| 49 | + >({ |
| 50 | + invalidatesTags: (_res, _err, query) => [ |
| 51 | + { id: query.organisation_id, type: 'ScimConfiguration' }, |
| 52 | + ], |
| 53 | + query: (query: Req['regenerateScimToken']) => ({ |
| 54 | + method: 'POST', |
| 55 | + url: `organisations/${query.organisation_id}/scim/regenerate-token/`, |
| 56 | + }), |
| 57 | + }), |
| 58 | + // END OF ENDPOINTS |
| 59 | + }), |
| 60 | + }) |
| 61 | + |
| 62 | +export async function createScimConfiguration( |
| 63 | + store: any, |
| 64 | + data: Req['createScimConfiguration'], |
| 65 | + options?: Parameters< |
| 66 | + typeof scimConfigurationService.endpoints.createScimConfiguration.initiate |
| 67 | + >[1], |
| 68 | +) { |
| 69 | + return store.dispatch( |
| 70 | + scimConfigurationService.endpoints.createScimConfiguration.initiate( |
| 71 | + data, |
| 72 | + options, |
| 73 | + ), |
| 74 | + ) |
| 75 | +} |
| 76 | +export async function deleteScimConfiguration( |
| 77 | + store: any, |
| 78 | + data: Req['deleteScimConfiguration'], |
| 79 | + options?: Parameters< |
| 80 | + typeof scimConfigurationService.endpoints.deleteScimConfiguration.initiate |
| 81 | + >[1], |
| 82 | +) { |
| 83 | + return store.dispatch( |
| 84 | + scimConfigurationService.endpoints.deleteScimConfiguration.initiate( |
| 85 | + data, |
| 86 | + options, |
| 87 | + ), |
| 88 | + ) |
| 89 | +} |
| 90 | +export async function getScimConfiguration( |
| 91 | + store: any, |
| 92 | + data: Req['getScimConfiguration'], |
| 93 | + options?: Parameters< |
| 94 | + typeof scimConfigurationService.endpoints.getScimConfiguration.initiate |
| 95 | + >[1], |
| 96 | +) { |
| 97 | + return store.dispatch( |
| 98 | + scimConfigurationService.endpoints.getScimConfiguration.initiate( |
| 99 | + data, |
| 100 | + options, |
| 101 | + ), |
| 102 | + ) |
| 103 | +} |
| 104 | +export async function regenerateScimToken( |
| 105 | + store: any, |
| 106 | + data: Req['regenerateScimToken'], |
| 107 | + options?: Parameters< |
| 108 | + typeof scimConfigurationService.endpoints.regenerateScimToken.initiate |
| 109 | + >[1], |
| 110 | +) { |
| 111 | + return store.dispatch( |
| 112 | + scimConfigurationService.endpoints.regenerateScimToken.initiate( |
| 113 | + data, |
| 114 | + options, |
| 115 | + ), |
| 116 | + ) |
| 117 | +} |
| 118 | +// END OF FUNCTION_EXPORTS |
| 119 | + |
| 120 | +export const { |
| 121 | + useCreateScimConfigurationMutation, |
| 122 | + useDeleteScimConfigurationMutation, |
| 123 | + useGetScimConfigurationQuery, |
| 124 | + useRegenerateScimTokenMutation, |
| 125 | + // END OF EXPORTS |
| 126 | +} = scimConfigurationService |
| 127 | + |
| 128 | +/* Usage examples: |
| 129 | +const { data, isLoading } = useGetScimConfigurationQuery({ organisation_id: 2 }) //get hook |
| 130 | +const [createScimConfiguration, { isLoading, data, isSuccess }] = useCreateScimConfigurationMutation() //create hook |
| 131 | +scimConfigurationService.endpoints.getScimConfiguration.select({organisation_id: 2})(store.getState()) //access data from any function |
| 132 | +*/ |
0 commit comments