mirror of
https://github.com/workhardbekind/workout-challenge.git
synced 2026-07-05 09:43:33 -04:00
first commit
This commit is contained in:
commit
e7f627801f
152 changed files with 35352 additions and 0 deletions
58
src-frontend/src/utils/reducers/teamsSlice.js
Normal file
58
src-frontend/src/utils/reducers/teamsSlice.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import {createApi} from '@reduxjs/toolkit/query/react';
|
||||
import {baseQueryWithReauth} from './baseQueryWithReauth';
|
||||
|
||||
export const teamsApi = createApi({
|
||||
reducerPath: 'teamsApi',
|
||||
baseQuery: baseQueryWithReauth,
|
||||
tagTypes: ['Team'],
|
||||
keepUnusedDataFor: 60 * 60 * 12, // 12 hours cache (default is 60)
|
||||
refetchOnMountOrArgChange: 60 * 60, // Refetch if older than 1 hour
|
||||
endpoints: (builder) => ({
|
||||
getTeams: builder.query({
|
||||
query: (params = {}) => ({
|
||||
url: `team/`, //?${new URLSearchParams(params).toString()}
|
||||
method: 'GET',
|
||||
params: params,
|
||||
}),
|
||||
providesTags: (result = []) => result.length ? [...result.map(({id}) => ({ type: 'Team', id })), { type: 'Team' }] : [{ type: 'Team' }],
|
||||
}),
|
||||
getTeamById: builder.query({
|
||||
query: (id) => ({
|
||||
url: `team/${id}/`,
|
||||
method: 'GET',
|
||||
}),
|
||||
providesTags: (result, error, id) => [{type: 'Team', id}],
|
||||
}),
|
||||
addTeam: builder.mutation({
|
||||
query: (newTeam) => ({
|
||||
url: 'team/',
|
||||
method: 'POST',
|
||||
body: newTeam,
|
||||
}),
|
||||
invalidatesTags: ['Team'],
|
||||
}),
|
||||
updateTeam: builder.mutation({
|
||||
query: ({id, ...patch}) => ({
|
||||
url: `team/${id}/`,
|
||||
method: 'PATCH',
|
||||
body: patch,
|
||||
}),
|
||||
invalidatesTags: (result, error, {id}) => [{type: 'Team', id}],
|
||||
}),
|
||||
deleteTeam: builder.mutation({
|
||||
query: (id) => ({
|
||||
url: `team/${id}/`,
|
||||
method: 'DELETE',
|
||||
}),
|
||||
invalidatesTags: (result, error, id) => [{type: 'Team', id}],
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export const {
|
||||
useGetTeamsQuery,
|
||||
useGetTeamByIdQuery,
|
||||
useAddTeamMutation,
|
||||
useUpdateTeamMutation,
|
||||
useDeleteTeamMutation,
|
||||
} = teamsApi;
|
||||
Loading…
Add table
Add a link
Reference in a new issue