Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
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
Евгений Положенцев
planner-team-one
Commits
80837de7
Commit
80837de7
authored
Nov 16, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#53
axios interceptor fix , remove headers in tasksActions
parent
e23e8c1b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
36 deletions
+22
-36
tasks.ts
planner-api/src/routers/tasks.ts
+3
-1
users.ts
planner-api/src/routers/users.ts
+0
-5
constants.js
planner-front/src/constants.js
+1
-1
MyTasks.js
planner-front/src/containers/MyTasks/MyTasks.js
+3
-3
index.js
planner-front/src/index.js
+9
-8
tasksActions.js
planner-front/src/store/actions/tasksActions.js
+6
-18
No files found.
planner-api/src/routers/tasks.ts
View file @
80837de7
...
...
@@ -80,6 +80,7 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
router
.
put
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
user
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"user"
)
...
...
@@ -94,6 +95,7 @@ router.put('/',async(req:Request, res:Response)=> {
.
from
(
Task
,
"task"
)
.
where
(
"task.id = :id"
,
{
id
})
.
getOne
()
if
(
!
task
)
return
res
.
status
(
404
).
send
({
Message
:
'task not found'
})
task
.
title
=
title
task
.
description
=
description
...
...
planner-api/src/routers/users.ts
View file @
80837de7
...
...
@@ -35,9 +35,7 @@ return res.send({users})
router
.
post
(
'/'
,
upload
.
single
(
"avatar"
),
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
console
.
log
(
req
.
body
)
const
{
name
,
surname
,
password
,
email
,
role
}
=
req
.
body
;
console
.
log
(
req
.
body
)
const
displayName
=
surname
+
' '
+
name
[
0
]
+
'.'
const
user
=
new
User
();
user
.
name
=
name
;
...
...
@@ -47,13 +45,10 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response):
user
.
email
=
email
;
user
.
role
=
role
;
user
.
generateToken
()
console
.
log
(
"user "
+
user
)
await
user
.
save
();
console
.
log
(
"saved"
)
const
userToFront
:
User
|
null
=
await
dataSource
.
manager
.
findOneBy
(
User
,
{
email
:
user
.
email
})
console
.
log
(
"userToFront "
+
userToFront
)
return
res
.
send
({
userToFront
})
})
...
...
planner-front/src/constants.js
View file @
80837de7
export
const
apiUrl
=
"http://localhost:800
1
"
;
export
const
apiUrl
=
"http://localhost:800
0
"
;
export
const
uploadsUrl
=
`
${
apiUrl
}
/uploads`
;
planner-front/src/containers/MyTasks/MyTasks.js
View file @
80837de7
...
...
@@ -60,7 +60,7 @@ export default function EnhancedTable() {
useEffect
(()
=>
{
dispatch
(
fetchAllTasks
());
},
[]);
},
[
dispatch
]);
const
tasks
=
useSelector
((
state
)
=>
state
.
tasks
.
tasks
);
console
.
log
(
tasks
)
...
...
@@ -178,7 +178,7 @@ console.log(tasks)
setRecievedTasks
(
newTasks
);
};
const
HandleEditTask
=
(
task
)
=>
{
const
HandleEditTask
=
(
task
)
=>
{
dispatch
(
editTask
(
task
))
}
...
...
planner-front/src/index.js
View file @
80837de7
...
...
@@ -6,7 +6,7 @@ import { configureStore } from '@reduxjs/toolkit';
import
{
Provider
}
from
'react-redux'
;
import
usersReducer
from
'./store/reducers/usersReducer'
;
import
tasksReducer
from
'./store/reducers/tasksReducer'
;
import
axios
from
'
axios
'
;
import
axios
from
'
./axiosPlanner
'
;
const
localStorageMiddleware
=
({
getState
})
=>
(
next
)
=>
(
action
)
=>
{
const
result
=
next
(
action
);
...
...
@@ -21,13 +21,6 @@ const loadFromLocalStorage = () => {
return
undefined
;
};
axios
.
interceptors
.
request
.
use
(
config
=>
{
try
{
config
.
headers
[
'Authorization'
]
=
store
.
getState
().
users
.
user
.
token
;
}
catch
(
e
){
}
return
config
;
})
const
store
=
configureStore
({
reducer
:
{
...
...
@@ -38,6 +31,14 @@ const store = configureStore({
middleware
:
(
getDefaultMiddleware
)
=>
getDefaultMiddleware
().
concat
(
localStorageMiddleware
)
})
axios
.
interceptors
.
request
.
use
(
config
=>
{
try
{
config
.
headers
[
'Authorization'
]
=
store
.
getState
().
users
.
user
.
token
;
}
catch
(
e
){
}
return
config
;
})
const
root
=
ReactDOM
.
createRoot
(
document
.
getElementById
(
'root'
));
root
.
render
(
<
Provider
store
=
{
store
}
>
...
...
planner-front/src/store/actions/tasksActions.js
View file @
80837de7
...
...
@@ -70,11 +70,7 @@ export const addTask = (task) => {
dispatch
(
addTaskRequest
());
const
token
=
getState
().
users
?.
user
?.
token
;
try
{
await
axios
.
post
(
"/tasks"
,
task
,
{
headers
:
{
'Authorization'
:
'IwGVRaksGTWtnKlOZd7zJ'
}
});
await
axios
.
post
(
"/tasks"
,
task
);
dispatch
(
addTaskSuccess
())
dispatch
(
fetchCalendarTasks
())
}
catch
(
error
)
{
...
...
@@ -98,14 +94,10 @@ const editTaskFailure = (error) => {
export
const
editTask
=
(
task
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
dispatch
(
editTaskRequest
());
const
token
=
getState
().
users
?.
user
?.
token
;
//
const token = getState().users?.user?.token;
try
{
console
.
log
(
task
)
const
r
=
await
axios
.
put
(
"/tasks"
,
task
,
{
headers
:
{
'Authorization'
:
'IwGVRaksGTWtnKlOZd7zJ'
}
});
console
.
log
(
'task'
,
task
)
const
r
=
await
axios
.
put
(
"/tasks/"
,
task
);
console
.
log
(
r
)
dispatch
(
editTaskSuccess
())
dispatch
(
fetchAllTasks
())
...
...
@@ -131,13 +123,9 @@ const deleteTaskFailure = (error) => {
export
const
deleteTask
=
(
taskId
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
dispatch
(
deleteTaskRequest
());
const
token
=
getState
().
users
?.
user
?.
token
;
//
const token = getState().users?.user?.token;
try
{
await
axios
.
delete
(
`/tasks/
${
taskId
}
`
,
{
headers
:
{
'Authorization'
:
'IwGVRaksGTWtnKlOZd7zJ'
}
});
await
axios
.
delete
(
`/tasks/
${
taskId
}
`
);
dispatch
(
deleteTaskSuccess
())
dispatch
(
fetchCalendarTasks
())
dispatch
(
fetchAllTasks
())
...
...
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