Commit 9b567b33 authored by Pavel Mishakov's avatar Pavel Mishakov

add user api etc

parent 7a13304f
import axios from "axios"
import { EStatuses } from "../enums/EStatuses"
import IProduct from "../interfaces/IProduct"
import IResponse from "../interfaces/IResponse"
......@@ -13,7 +12,7 @@ class ProductApi {
return response.data
} catch (err: unknown) {
const error = err as Error
const response: IResponse = {
const response: IResponse<undefined> = {
status: EStatuses.NOT_OK,
result: undefined,
message: error.message
......@@ -28,7 +27,7 @@ class ProductApi {
return response.data
} catch (err: unknown) {
const error = err as Error
const response: IResponse = {
const response: IResponse<undefined> = {
status: EStatuses.NOT_OK,
result: undefined,
message: error.message
......@@ -37,13 +36,13 @@ class ProductApi {
}
}
public createProduct = async(product: FormData): Promise<IResponse> => {
public createProduct = async(product: FormData): Promise<IResponse<IProduct[] | undefined>> => {
try {
const response = await instance.post(`/products`, product)
return response.data
} catch (err: unknown) {
const error = err as Error
const response: IResponse = {
const response: IResponse<undefined> = {
status: EStatuses.NOT_OK,
result: undefined,
message: error.message
......@@ -52,13 +51,13 @@ class ProductApi {
}
}
public deleteProductById = async(id: string): Promise<IResponse> => {
public deleteProductById = async(id: string): Promise<IResponse<IProduct | undefined>> => {
try {
const response = await instance.delete(`/products/${id}`)
return response.data
} catch (err: unknown) {
const error = err as Error
const response: IResponse = {
const response: IResponse<undefined> = {
status: EStatuses.NOT_OK,
result: undefined,
message: error.message
......
import { EStatuses } from "../enums/EStatuses";
import IResponse from "../interfaces/IResponse";
import IUserCreateDto from "../interfaces/IUserCreateDto";
import IUserGetDto from "../interfaces/IUserGetDto";
import { instance } from "./instance";
class UserApi {
public login = async (user: IUserCreateDto): Promise<IResponse<IUserGetDto | undefined>> => {
try {
const response = await instance.post(`/users/login`, user)
return response.data
} catch (err: unknown) {
const error = err as Error
const response: IResponse<undefined> = {
status: EStatuses.NOT_OK,
result: undefined,
message: error.message
}
return response
}
}
public register = async (user: IUserCreateDto): Promise<IResponse<IUserGetDto | undefined>> => {
try {
const response = await instance.post(`/users`, user)
return response.data
} catch (err: unknown) {
const error = err as Error
const response: IResponse<undefined> = {
status: EStatuses.NOT_OK,
result: undefined,
message: error.message
}
return response
}
}
}
export const userApi = new UserApi()
\ No newline at end of file
import { configureStore, ThunkAction, Action } from "@reduxjs/toolkit"
import { useDispatch } from 'react-redux'
import { productsSlice } from "./products/products.slice"
import { usersSlice } from "./users/users.slice"
const makeStore = () => {
return configureStore({
reducer: {
products: productsSlice.reducer
products: productsSlice.reducer,
users: usersSlice.reducer
}
})
}
......
import IUserGetDto from "../../interfaces/IUserGetDto";
export default interface IUsersState {
user: IUserGetDto
isAuth: boolean
}
\ No newline at end of file
import { createSlice } from "@reduxjs/toolkit";
import IUser from "../../interfaces/IUser";
import IUsersState from "./IUsersState";
const namespace = 'users'
export const usersSlice = createSlice({
name: namespace,
initialState: {
user: {} as IUser,
isAuth: false
} as IUsersState,
reducers: {},
extraReducers: (builder) => {
// builder
// .addCase()
}
})
export const {} = usersSlice.actions
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment