Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
products_lesson_front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pavel Mishakov
products_lesson_front
Commits
9b567b33
Commit
9b567b33
authored
Mar 24, 2023
by
Pavel Mishakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add user api etc
parent
7a13304f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
8 deletions
+77
-8
productApi.ts
src/api/productApi.ts
+6
-7
userApi.ts
src/api/userApi.ts
+40
-0
store.ts
src/store/store.ts
+3
-1
IUsersState.ts
src/store/users/IUsersState.ts
+6
-0
users.slice.ts
src/store/users/users.slice.ts
+22
-0
No files found.
src/api/productApi.ts
View file @
9b567b33
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
...
...
src/api/userApi.ts
0 → 100644
View file @
9b567b33
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
src/store/store.ts
View file @
9b567b33
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
}
})
}
...
...
src/store/users/IUsersState.ts
0 → 100644
View file @
9b567b33
import
IUserGetDto
from
"../../interfaces/IUserGetDto"
;
export
default
interface
IUsersState
{
user
:
IUserGetDto
isAuth
:
boolean
}
\ No newline at end of file
src/store/users/users.slice.ts
0 → 100644
View file @
9b567b33
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment