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