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
7b2f67a0
Commit
7b2f67a0
authored
Nov 27, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#68
refacor create and change of task
parent
2f75a546
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
50 deletions
+68
-50
helpers.ts
planner-api/src/helpers.ts
+23
-6
Task.ts
planner-api/src/models/Task.ts
+6
-0
copyTasks.ts
planner-api/src/routers/copyTasks.ts
+5
-5
tasks.ts
planner-api/src/routers/tasks.ts
+34
-39
No files found.
planner-api/src/helpers.ts
View file @
7b2f67a0
import
express
,
{
NextFunction
,
Request
,
Response
,
Router
}
from
"express"
;
import
{
myDataSource
}
from
"./app-data-source"
;
import
{
Task
}
from
"./models/Task"
;
import
{
User
}
from
"./models/User"
;
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
/** Check if user with given token exists , return user */
...
...
@@ -25,8 +25,8 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
const
token
=
req
.
get
(
'Authorization'
);
const
{
taskId
}
=
req
.
body
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
req
.
body
=
{...
req
.
body
,
executor
:
false
}
req
.
body
=
{...
req
.
body
,
author
:
false
}
req
.
body
=
{...
req
.
body
,
executor
Status
:
false
}
req
.
body
=
{...
req
.
body
,
author
Status
:
false
}
const
executor
=
await
dataSource
.
createQueryBuilder
()
...
...
@@ -37,7 +37,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
.
getOne
();
console
.
log
(
'executor'
,
executor
)
if
(
executor
)
{
req
.
body
=
{...
req
.
body
,
executor
:
executor
}
req
.
body
=
{...
req
.
body
,
executor
Status
:
true
}
}
const
author
=
await
dataSource
.
createQueryBuilder
()
...
...
@@ -48,8 +48,25 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
.
getOne
();
console
.
log
(
'author'
,
author
)
if
(
author
)
{
req
.
body
=
{...
req
.
body
,
author
:
author
}
req
.
body
=
{...
req
.
body
,
author
Status
:
true
}
}
if
(
!
author
&&
!
executor
)
return
res
.
status
(
401
).
send
({
Message
:
'user is not authorized'
})
next
()
};
/**task finder by id, return one task */
export
const
taskFinderById
=
async
(
taskId
:
string
):
Promise
<
null
|
Task
>=>
{
const
task
=
await
dataSource
.
getRepository
(
Task
)
.
findOne
({
relations
:{
executor
:
true
,
author
:
true
,
dateTimeTasks
:
true
},
where
:{
id
:
taskId
}
})
return
task
}
\ No newline at end of file
planner-api/src/models/Task.ts
View file @
7b2f67a0
...
...
@@ -20,6 +20,7 @@ import { DateTimeTask } from './DateTimeTask';
id
:
string
;
title
:
string
;
description
:
string
;
note
:
string
;
createdAt
:
Date
;
dateTimeStart
:
Date
|
null
;
dateTimeDue
:
Date
|
null
;
...
...
@@ -27,6 +28,7 @@ import { DateTimeTask } from './DateTimeTask';
dateTimeFactDeadLine
:
Date
|
null
;
accomplish
:
taskFinishType
;
priority
:
priorityType
|
null
;
archive
:
boolean
,
author
:
User
;
project
:
Project
|
null
;
dateTimeTasks
:
DateTimeTask
[]
|
null
;
...
...
@@ -41,6 +43,8 @@ import { DateTimeTask } from './DateTimeTask';
title
!
:
string
@
Column
({
name
:
'description'
,
type
:
'varchar'
,
length
:
50
,
nullable
:
true
})
description
!
:
string
@
Column
({
name
:
'note'
,
type
:
'varchar'
,
length
:
100
,
nullable
:
true
})
note
!
:
string
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
@
Column
({
name
:
'dateTimeStart'
,
type
:
Date
,
nullable
:
true
})
...
...
@@ -51,6 +55,8 @@ import { DateTimeTask } from './DateTimeTask';
dateTimeDeadLine
!
:
Date
;
@
Column
({
name
:
'dateTimeFactDeadLine'
,
type
:
Date
,
nullable
:
true
})
dateTimeFactDeadLine
!
:
Date
;
@
Column
({
name
:
'archive'
,
type
:
'varchar'
,
length
:
50
,
nullable
:
false
,
default
:
false
})
archive
!
:
boolean
@
Column
({
type
:
"enum"
,
...
...
planner-api/src/routers/copyTasks.ts
View file @
7b2f67a0
...
...
@@ -29,8 +29,8 @@ const taskFinderById = async (taskId:string):Promise<null | Task>=>{
/** make copy of task in calendar view */
router
.
post
(
"/make-copy"
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
executor
,
taskId
,
start
,
due
}
=
req
.
body
if
(
executor
){
const
{
executor
Status
,
taskId
,
start
,
due
}
=
req
.
body
if
(
executor
Status
){
const
newDateTimeTask
=
new
DateTimeTask
();
newDateTimeTask
.
dateTimeStart
=
start
newDateTimeTask
.
dateTimeDue
=
due
...
...
@@ -44,8 +44,8 @@ router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Resp
/** change date time of copy of task in calendar view */
router
.
put
(
"change-copy"
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
executor
,
dateTimeTaskId
,
taskId
,
start
,
due
}
=
req
.
body
if
(
executor
){
const
{
executor
Status
,
dateTimeTaskId
,
taskId
,
start
,
due
}
=
req
.
body
if
(
executor
Status
){
const
dateTimeTask
=
await
dataSource
.
createQueryBuilder
()
.
select
(
'dateTikeTask'
)
...
...
planner-api/src/routers/tasks.ts
View file @
7b2f67a0
...
...
@@ -5,7 +5,7 @@ import { User } from '../models/User';
import
{
Member
}
from
'../models/Member'
;
import
{
In
}
from
'typeorm'
;
import
{
DateTimeTask
}
from
'../models/DateTimeTask'
;
import
{
auth
}
from
'../helpers'
;
import
{
auth
,
authAuthorOrExecutorOfTask
,
taskFinderById
}
from
'../helpers'
;
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
...
...
@@ -25,24 +25,14 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
/**create new task */
router
.
post
(
'/'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
user
,
title
,
description
,
project
,
dateTimeTaskArray
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
const
{
user
,
title
,
description
,
project
,
executor
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
const
newTask
=
new
Task
();
const
dateTimeArray
=
[];
if
(
dateTimeTaskArray
&&
dateTimeTaskArray
.
length
>
0
){
for
(
let
dateTimeStartDue
of
dateTimeTaskArray
){
const
newDateTimeTask
=
new
DateTimeTask
();
newDateTimeTask
.
dateTimeStart
=
dateTimeStartDue
.
dateTimeStart
;
newDateTimeTask
.
dateTimeDue
=
dateTimeStartDue
.
dateTimeDue
;
await
newDateTimeTask
.
save
();
dateTimeArray
.
push
(
newDateTimeTask
);
}
newTask
.
dateTimeTasks
=
dateTimeArray
;
}
newTask
.
title
=
title
;
newTask
.
description
=
description
;
newTask
.
project
=
project
;
newTask
.
dateTimeDeadLine
=
dateTimeDeadLine
;
newTask
.
author
=
user
;
newTask
.
executor
=
executor
;
newTask
.
priority
=
priority
;
await
newTask
.
save
();
return
res
.
send
({
newTask
});
...
...
@@ -78,7 +68,6 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
/**check tasks of current user where he is author or executor, search by id*/
router
.
get
(
'/my'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
user
=
req
.
body
.
user
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
...
...
@@ -165,34 +154,40 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
/**change of task by task id */
router
.
put
(
'/'
,
auth
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
{
user
,
id
,
title
,
description
,
project
,
dateTimeTaskArray
,
executor
,
accomplish
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
const
task
=
await
dataSource
router
.
put
(
'/'
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
{
authorStatus
,
executorStatus
,
taskId
,
title
,
description
,
note
,
archive
,
project
,
dateTimeTaskId
,
start
,
due
,
executor
,
accomplish
,
dateTimeDeadLine
,
dateTimeFactDeadLine
,
priority
}
=
req
.
body
;
const
task
=
await
taskFinderById
(
taskId
)
if
(
!
task
)
return
res
.
status
(
404
).
send
({
Message
:
'task not found'
})
let
dateTimeTask
=
null
;
if
(
dateTimeTaskId
)
{
const
dateTimeTaskData
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"t
ask"
)
.
from
(
Task
,
"t
ask"
)
.
where
(
"task.id = :id"
,
{
id
})
.
select
(
"dateTimeT
ask"
)
.
from
(
DateTimeTask
,
"dateTimeT
ask"
)
.
where
(
"dateTimeTask,id=:dateTimeTaskId"
,{
dateTimeTaskId
})
.
getOne
()
if
(
!
task
)
return
res
.
status
(
404
).
send
({
Message
:
'task not found'
})
const
dateTimeArray
=
[];
if
(
dateTimeTaskArray
&&
dateTimeTaskArray
.
length
>
0
){
for
(
let
dateTimeStartDue
of
dateTimeTaskArray
){
const
newDateTimeTask
=
new
DateTimeTask
();
newDateTimeTask
.
dateTimeStart
=
dateTimeStartDue
.
dateTimeStart
;
newDateTimeTask
.
dateTimeDue
=
dateTimeStartDue
.
dateTimeDue
;
await
newDateTimeTask
.
save
();
dateTimeArray
.
push
(
newDateTimeTask
);
}
task
.
dateTimeTasks
=
dateTimeArray
;
if
(
!
dateTimeTask
)
return
res
.
status
(
404
).
send
({
Message
:
'dateTimeTask not found'
})
dateTimeTask
=
dateTimeTaskData
}
task
.
title
=
title
if
(
authorStatus
){
task
.
title
=
title
task
.
description
=
description
task
.
project
=
project
task
.
archive
=
archive
task
.
dateTimeDeadLine
=
dateTimeDeadLine
;
task
.
author
=
user
task
.
project
=
project
task
.
executor
=
executor
task
.
accomplish
=
accomplish
task
.
priority
=
priority
}
if
(
executorStatus
&&
dateTimeTask
!==
null
){
dateTimeTask
.
dateTimeStart
=
start
dateTimeTask
.
dateTimeDue
=
due
await
dateTimeTask
.
save
()
task
.
note
=
note
task
.
dateTimeFactDeadLine
=
dateTimeFactDeadLine
}
task
.
accomplish
=
accomplish
await
task
.
save
()
res
.
send
({
message
:
'update task successfully'
})
})
...
...
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