import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' import { getConfigValue } from '@brojs/cli' import { BaseResponse, User } from '../model' export const api = createApi({ reducerPath: 'api', baseQuery: fetchBaseQuery({ baseUrl: getConfigValue('nav2.api'), headers: { 'Content-Type': 'application/json', }, }), tagTypes: ['Users'], endpoints: (builder) => ({ users: builder.query, void>({ query: () => ({ url: '/users', }), providesTags: ['Users'], transformResponse: (response: BaseResponse) => response.body.reduce((acc, user) => ({ ...acc, [user.id]: user }), {}), }), updateRating: builder.mutation({ query: ({ userId, rating }) => ({ url: `/user/rate/${userId}`, method: 'POST', body: { rating }, }), invalidatesTags: ['Users'], }), }), })