Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
order-management-react
Project
Project
Details
Activity
Releases
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
Ascend
order-management-react
Commits
fccab38d
Commit
fccab38d
authored
4 years ago
by
Alex Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-111]
Create 'ManagerService' to handle manager API calls (
@asegers
)
parent
c6fae170
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
ManagerService.ts
src/services/ManagerService.ts
+69
-0
index.ts
src/services/index.ts
+1
-0
No files found.
src/services/ManagerService.ts
0 → 100644
View file @
fccab38d
import
{
Manager
}
from
'Manager'
import
{
tokenStorage
}
from
'utils'
import
Axios
,
{
AxiosError
}
from
'axios'
const
BASE_PATH
=
'/api/managers'
export
const
authenticate
=
async
(
token
:
string
):
Promise
<
Manager
>
=>
{
try
{
const
{
data
}
=
await
Axios
.
post
(
`
${
BASE_PATH
}
/auth`
,
{},
// Empty body
{
headers
:
{
Authorization
:
`Bearer
${
token
}
`
}
}
)
return
data
;
}
catch
(
error
)
{
const
{
response
}
=
error
as
AxiosError
;
// Get Status Code
return
response
?.
data
;
}
}
export
const
getAccount
=
async
():
Promise
<
Manager
>
=>
{
const
token
=
tokenStorage
.
get
();
try
{
const
{
data
}
=
await
Axios
.
get
(
`
${
BASE_PATH
}
/account`
,
{
headers
:
{
Authorization
:
`Bearer
${
token
}
`
}
}
)
return
data
;
}
catch
(
error
)
{
const
{
response
}
=
error
as
AxiosError
;
return
response
?.
data
;
}
}
export
const
updateAccount
=
async
():
Promise
<
Manager
>
=>
{
const
token
=
tokenStorage
.
get
();
try
{
const
{
data
}
=
await
Axios
.
patch
(
`
${
BASE_PATH
}
/account`
,
{},
// Empty body
{
headers
:
{
Authorization
:
`Bearer
${
token
}
`
}
}
)
return
data
;
}
catch
(
error
)
{
const
{
response
}
=
error
as
AxiosError
;
return
response
?.
data
;
}
}
export
const
deleteAccount
=
async
()
=>
{
const
token
=
tokenStorage
.
get
();
try
{
await
Axios
.
delete
(
`
${
BASE_PATH
}
/account`
,
{
headers
:
{
Authorization
:
`Bearer
${
token
}
`
}
}
)
}
catch
(
error
)
{
const
{
response
}
=
error
as
AxiosError
;
return
response
?.
data
;
}
}
export
default
{
authenticate
,
getAccount
,
updateAccount
,
deleteAccount
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/services/index.ts
View file @
fccab38d
export
{
default
as
ManagerService
}
from
'./ManagerService'
export
{
default
as
OrderService
}
from
'./OrderService'
export
{
default
as
GoogleAuthService
}
from
'./GoogleAuthService'
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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