Snai3i-MarketPlace / frontend / src / app / backend / endpoints / auth.ts
auth.ts
Raw
import api from '..';

const AUTH_API = 'auth';

export const authApi = api.injectEndpoints({
  endpoints: (build) => ({
    login: build.mutation<ResponseI<UserI>, UserAuthI>({
      query: (userAuth) => ({
        url: `${AUTH_API}/login`,
        method: 'POST',
        body: userAuth,
      }),
    }),
    register: build.mutation<ResponseI<UserI>, UserI>({
      query: (userRegister) => ({
        url: `${AUTH_API}/register`,
        method: 'POST',
        body: userRegister,
      }),
      invalidatesTags: ['users'],
    }),
    registerTeacher: build.mutation<ResponseI<UserI>, UserI>({
      query: (userRegister) => ({
        url: `${AUTH_API}/register/teacher`,
        method: 'POST',
        body: userRegister,
      }),
      invalidatesTags: ['users', 'teachers'],
    }),
    logout: build.mutation<ResponseI<null>, void>({
      query: () => ({
        url: `${AUTH_API}/logout`,
        method: 'POST',
      }),
      invalidatesTags: ['users'],
    }),
    getUser: build.mutation<ResponseI<UserI>, void>({
      query: () => ({
        url: `${AUTH_API}`,
        method: 'GET',
      }),
      invalidatesTags: ['users'],
    }),
    resetPassword: build.mutation<
      ResponseI<UserI>,
      { userId: string; newPassword: string }
    >({
      query: (body) => ({
        url: `${AUTH_API}/reset`,
        method: 'PUT',
        body,
      }),
    }),
    resetTeacherPassword: build.mutation<
      ResponseI<UserI>,
      { teacherId: string; newPassword: string }
    >({
      query: (body) => ({
        url: `${AUTH_API}/reset/teacher`,
        method: 'PUT',
        body,
      }),
    }),
    // updateProfile: build.mutation<ResponseI<UserI>, UserUpdateI>({
    //   query: (body) => ({
    //     url: `${USERS_API}/profile`,
    //     method: 'PUT',
    //     body,
    //   }),
    //   invalidatesTags: ['users'],
    // })
  }),
});

export const {
  useLoginMutation,
  useRegisterMutation,
  useLogoutMutation,
  useGetUserMutation,
  useRegisterTeacherMutation,
  useResetTeacherPasswordMutation,
  useResetPasswordMutation,
  // useResetPasswordMutation,
  //   useUpdateProfileMutation,
} = authApi;