51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
|
|
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
|
import { baseQuery } from "../baseQuery";
|
|
|
|
export const profileApi = createApi({
|
|
reducerPath: "profileApi",
|
|
baseQuery,
|
|
|
|
tagTypes: ["userDetails"],
|
|
|
|
endpoints: (builder) => ({
|
|
|
|
getUserProfileDetails: builder.query({
|
|
query: (id) => `/website/user/${id}`,
|
|
providesTags: ["userDetails"]
|
|
}),
|
|
|
|
updateUserProfileDetails: builder.mutation({
|
|
query: ({ userDetails, userId }) => ({ // keep the name of the variables being passed here same as when calling the mutation hook
|
|
url: `/website/user/${userId}`,
|
|
method: "PUT",
|
|
body: userDetails
|
|
}),
|
|
invalidatesTags: ["userDetails"]
|
|
}),
|
|
|
|
getUserCards: builder.query({
|
|
query: ({sort,cityId}) => {
|
|
const params = new URLSearchParams()
|
|
|
|
params.append('cityXid', cityId);
|
|
|
|
if (sort) params.append('sort', sort);
|
|
|
|
return `/website/passes/all?${params.toString()}`
|
|
}
|
|
}),
|
|
|
|
getUserCardDetails: builder.query({
|
|
query: (cardId) => `/website/passes/${cardId}/details`,
|
|
}),
|
|
|
|
})
|
|
});
|
|
|
|
export const {
|
|
useGetUserProfileDetailsQuery,
|
|
useUpdateUserProfileDetailsMutation,
|
|
useGetUserCardsQuery,
|
|
useGetUserCardDetailsQuery
|
|
} = profileApi; |