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
a09aa306
Commit
a09aa306
authored
Nov 30, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'task-81-fix/put_request_tasks' into 'development'
Task 81 fix/put request tasks See merge request
!52
parents
228d63a9
f21a1820
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
32 deletions
+45
-32
helpers.ts
planner-api/src/helpers.ts
+27
-21
Task.ts
planner-api/src/models/Task.ts
+4
-4
tasks.ts
planner-api/src/routers/tasks.ts
+14
-7
No files found.
planner-api/src/helpers.ts
View file @
a09aa306
...
@@ -24,33 +24,39 @@ export const auth = async(req: Request,res: Response, next:NextFunction):Promise
...
@@ -24,33 +24,39 @@ export const auth = async(req: Request,res: Response, next:NextFunction):Promise
export
const
authAuthorOrExecutorOfTask
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
Response
>>=>
{
export
const
authAuthorOrExecutorOfTask
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
Response
>>=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
token
=
req
.
get
(
'Authorization'
);
const
{
taskId
}
=
req
.
body
const
{
taskId
}
=
req
.
body
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
req
.
body
=
{...
req
.
body
,
executorStatus
:
false
}
req
.
body
=
{...
req
.
body
,
executorStatus
:
false
}
req
.
body
=
{...
req
.
body
,
authorStatus
:
false
}
req
.
body
=
{...
req
.
body
,
authorStatus
:
false
}
const
executor
=
await
dataSource
const
task
=
await
dataSource
.
createQueryBuilder
()
.
getRepository
(
Task
)
.
select
(
"user"
)
.
findOne
({
.
from
(
User
,
"user"
)
relations
:{
.
leftJoinAndSelect
(
"user.tasks"
,
"task"
)
executor
:
true
,
.
where
(
"user.token = :token"
,
{
token
:
token
})
author
:
true
,
.
getOne
();
},
console
.
log
(
'executor'
,
executor
)
where
:[
if
(
executor
)
{
{
req
.
body
=
{...
req
.
body
,
executorStatus
:
true
}
id
:
taskId
,
}
executor
:{
const
author
=
await
dataSource
token
:
token
.
createQueryBuilder
()
}
.
select
(
"user"
)
},
.
from
(
User
,
"user"
)
{
.
leftJoinAndSelect
(
"user.createdTasks"
,
"task"
)
id
:
taskId
,
.
where
(
"user.token = :token"
,
{
token
:
token
})
author
:{
.
getOne
();
token
:
token
console
.
log
(
'author'
,
author
)
}
if
(
author
)
{
},
]})
if
(
!
task
)
return
res
.
status
(
404
).
send
({
message
:
'task with possible user involved is not found'
})
if
(
task
?.
author
?.
token
===
token
)
{
req
.
body
=
{...
req
.
body
,
authorStatus
:
true
}
req
.
body
=
{...
req
.
body
,
authorStatus
:
true
}
}
else
if
(
task
?.
executor
?.
token
===
token
)
{
req
.
body
=
{...
req
.
body
,
executorStatus
:
true
}
}
else
{
}
}
if
(
!
author
&&
!
executor
)
return
res
.
status
(
401
).
send
({
Message
:
'user is not authorized'
})
next
()
next
()
};
};
...
...
planner-api/src/models/Task.ts
View file @
a09aa306
...
@@ -7,7 +7,8 @@ import {
...
@@ -7,7 +7,8 @@ import {
ManyToOne
,
ManyToOne
,
OneToOne
,
OneToOne
,
JoinTable
,
JoinTable
,
OneToMany
OneToMany
,
JoinColumn
}
from
'typeorm'
;
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
import
{
User
}
from
'./User'
;
import
{
Project
}
from
'./Project'
;
import
{
Project
}
from
'./Project'
;
...
@@ -28,9 +29,9 @@ import { DateTimeTask } from './DateTimeTask';
...
@@ -28,9 +29,9 @@ import { DateTimeTask } from './DateTimeTask';
priority
:
priorityType
|
null
;
priority
:
priorityType
|
null
;
archive
:
boolean
,
archive
:
boolean
,
author
:
User
;
author
:
User
;
executor
:
User
;
project
:
Project
|
null
;
project
:
Project
|
null
;
dateTimeTasks
:
DateTimeTask
[]
|
null
;
dateTimeTasks
:
DateTimeTask
[]
|
null
;
executor
:
User
;
}
}
@
Entity
({
name
:
'Task'
})
@
Entity
({
name
:
'Task'
})
...
@@ -73,8 +74,7 @@ import { DateTimeTask } from './DateTimeTask';
...
@@ -73,8 +74,7 @@ import { DateTimeTask } from './DateTimeTask';
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
})
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
})
author
!
:
User
;
author
!
:
User
;
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[]})
=>
user
.
tasks
,{
eager
:
true
,
nullable
:
true
,
onUpdate
:
'CASCADE'
})
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[]})
=>
user
.
tasks
,{
nullable
:
true
,
cascade
:
true
,
onUpdate
:
'CASCADE'
,
eager
:
true
,})
@
JoinTable
()
executor
!
:
User
;
executor
!
:
User
;
@
ManyToOne
(()
=>
Project
,(
project
:{
tasks
:
Task
[]})
=>
project
.
tasks
,{
eager
:
true
,
nullable
:
true
,
onUpdate
:
'CASCADE'
})
@
ManyToOne
(()
=>
Project
,(
project
:{
tasks
:
Task
[]})
=>
project
.
tasks
,{
eager
:
true
,
nullable
:
true
,
onUpdate
:
'CASCADE'
})
...
...
planner-api/src/routers/tasks.ts
View file @
a09aa306
...
@@ -25,7 +25,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
...
@@ -25,7 +25,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
/**create new task */
/**create new task */
router
.
post
(
'/'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
post
(
'/'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
user
,
title
,
description
,
project
,
executor
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
const
{
user
,
title
,
description
,
project
,
executor
,
dateTimeStart
,
dateTimeDue
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
const
newTask
=
new
Task
();
const
newTask
=
new
Task
();
newTask
.
title
=
title
;
newTask
.
title
=
title
;
newTask
.
description
=
description
;
newTask
.
description
=
description
;
...
@@ -35,6 +35,11 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
...
@@ -35,6 +35,11 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
newTask
.
executor
=
executor
;
newTask
.
executor
=
executor
;
newTask
.
priority
=
priority
;
newTask
.
priority
=
priority
;
await
newTask
.
save
();
await
newTask
.
save
();
const
newDateTimeTask
=
new
DateTimeTask
();
newDateTimeTask
.
dateTimeStart
=
dateTimeStart
newDateTimeTask
.
dateTimeDue
=
dateTimeDue
newDateTimeTask
.
task
=
newTask
await
newDateTimeTask
.
save
()
return
res
.
send
({
newTask
});
return
res
.
send
({
newTask
});
})
})
...
@@ -153,7 +158,7 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
...
@@ -153,7 +158,7 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
/**change of task by task id */
/**change of task by task id */
router
.
put
(
'/'
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
router
.
put
(
'/'
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
{
authorStatus
,
executorStatus
,
taskId
,
title
,
description
,
note
,
archive
,
project
,
dateTimeTaskId
,
start
,
d
ue
,
executor
,
accomplish
,
dateTimeDeadLine
,
dateTimeFactDeadLine
,
priority
}
=
req
.
body
;
const
{
authorStatus
,
executorStatus
,
taskId
,
title
,
description
,
note
,
archive
,
project
,
dateTimeTaskId
,
dateTimeStart
,
dateTimeD
ue
,
executor
,
accomplish
,
dateTimeDeadLine
,
dateTimeFactDeadLine
,
priority
}
=
req
.
body
;
const
task
=
await
taskFinderById
(
taskId
)
const
task
=
await
taskFinderById
(
taskId
)
if
(
!
task
)
return
res
.
status
(
404
).
send
({
Message
:
'task not found'
})
if
(
!
task
)
return
res
.
status
(
404
).
send
({
Message
:
'task not found'
})
let
dateTimeTask
=
null
;
let
dateTimeTask
=
null
;
...
@@ -168,6 +173,12 @@ router.put('/',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
...
@@ -168,6 +173,12 @@ router.put('/',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
dateTimeTask
=
dateTimeTaskData
dateTimeTask
=
dateTimeTaskData
}
}
if
(
dateTimeTask
!==
null
)
{
dateTimeTask
.
dateTimeStart
=
dateTimeStart
dateTimeTask
.
dateTimeDue
=
dateTimeDue
await
dateTimeTask
.
save
()
}
if
(
authorStatus
){
if
(
authorStatus
){
task
.
title
=
title
task
.
title
=
title
task
.
description
=
description
task
.
description
=
description
...
@@ -177,13 +188,9 @@ router.put('/',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
...
@@ -177,13 +188,9 @@ router.put('/',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
task
.
executor
=
executor
task
.
executor
=
executor
task
.
priority
=
priority
task
.
priority
=
priority
}
}
if
(
executorStatus
&&
dateTimeTask
!==
null
){
if
(
executorStatus
){
dateTimeTask
.
dateTimeStart
=
start
dateTimeTask
.
dateTimeDue
=
due
await
dateTimeTask
.
save
()
task
.
note
=
note
task
.
note
=
note
task
.
dateTimeFactDeadLine
=
dateTimeFactDeadLine
task
.
dateTimeFactDeadLine
=
dateTimeFactDeadLine
}
}
task
.
accomplish
=
accomplish
task
.
accomplish
=
accomplish
await
task
.
save
()
await
task
.
save
()
...
...
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