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
2f75a546
Commit
2f75a546
authored
Nov 27, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#68
added router copy-tasks make and change options
parent
e5b3eab6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
15 deletions
+111
-15
helpers.ts
planner-api/src/helpers.ts
+36
-1
copyTasks.ts
planner-api/src/routers/copyTasks.ts
+65
-0
tasks.ts
planner-api/src/routers/tasks.ts
+8
-14
server.ts
planner-api/src/server.ts
+2
-0
No files found.
planner-api/src/helpers.ts
View file @
2f75a546
...
@@ -5,7 +5,8 @@ import { User } from "./models/User";
...
@@ -5,7 +5,8 @@ import { User } from "./models/User";
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
export
const
auth
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
any
,
Record
<
string
,
any
>>>=>
{
/** Check if user with given token exists , return user */
export
const
auth
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
Response
>>=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
token
=
req
.
get
(
'Authorization'
);
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
const
user
=
await
dataSource
const
user
=
await
dataSource
...
@@ -17,4 +18,38 @@ export const auth = async(req: Request,res: Response, next:NextFunction):Promise
...
@@ -17,4 +18,38 @@ export const auth = async(req: Request,res: Response, next:NextFunction):Promise
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
req
.
body
=
{...
req
.
body
,
user
:
user
}
req
.
body
=
{...
req
.
body
,
user
:
user
}
next
()
next
()
};
/**Check if user with the given token is executor or author of task with the given Id(taskId) */
export
const
authAuthorOrExecutorOfTask
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
Response
>>=>
{
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
}
const
executor
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"user"
)
.
from
(
User
,
"user"
)
.
leftJoinAndSelect
(
"user.tasks"
,
"task"
)
.
where
(
"user.token = :token"
,
{
token
:
token
})
.
getOne
();
console
.
log
(
'executor'
,
executor
)
if
(
executor
)
{
req
.
body
=
{...
req
.
body
,
executor
:
executor
}
}
const
author
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"user"
)
.
from
(
User
,
"user"
)
.
leftJoinAndSelect
(
"user.createdTasks"
,
"task"
)
.
where
(
"user.token = :token"
,
{
token
:
token
})
.
getOne
();
console
.
log
(
'author'
,
author
)
if
(
author
)
{
req
.
body
=
{...
req
.
body
,
author
:
author
}
}
if
(
!
author
&&
!
executor
)
return
res
.
status
(
401
).
send
({
Message
:
'user is not authorized'
})
next
()
};
};
\ No newline at end of file
planner-api/src/routers/copyTasks.ts
0 → 100644
View file @
2f75a546
import
express
,{
Router
,
Request
,
Response
,
NextFunction
}
from
'express'
;
import
{
Task
}
from
'../models/Task'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
User
}
from
'../models/User'
;
import
{
Member
}
from
'../models/Member'
;
import
{
In
}
from
'typeorm'
;
import
{
DateTimeTask
}
from
'../models/DateTimeTask'
;
import
{
auth
,
authAuthorOrExecutorOfTask
}
from
'../helpers'
;
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
/**task finder by id, return one task */
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
}
/** 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
newDateTimeTask
=
new
DateTimeTask
();
newDateTimeTask
.
dateTimeStart
=
start
newDateTimeTask
.
dateTimeDue
=
due
newDateTimeTask
.
task
=
taskId
await
newDateTimeTask
.
save
()
const
task
=
taskFinderById
(
taskId
)
return
res
.
send
({
task
})
}
return
res
.
send
({
message
:
"Something wrong in make-copy router"
})
}
)
/** 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
dateTimeTask
=
await
dataSource
.
createQueryBuilder
()
.
select
(
'dateTikeTask'
)
.
from
(
DateTimeTask
,
'dateTimeTask'
)
.
where
(
"dateTimeTask.id = :dateTimeTaskId"
,{
dateTimeTaskId
})
.
getOne
()
if
(
!
dateTimeTask
)
return
res
.
send
({
message
:
"such dateTimeTask does not exists"
})
dateTimeTask
.
dateTimeStart
=
start
dateTimeTask
.
dateTimeDue
=
due
await
dateTimeTask
.
save
()
const
task
=
taskFinderById
(
taskId
)
return
res
.
send
({
task
})
}
return
res
.
send
({
message
:
"Something wrong in make-copy router"
})
})
export
default
router
;
planner-api/src/routers/tasks.ts
View file @
2f75a546
import
express
,{
Router
,
Request
,
Response
,
NextFunction
}
from
'express'
;
import
express
,{
Router
,
Request
,
Response
}
from
'express'
;
import
{
Task
}
from
'../models/Task'
;
import
{
Task
}
from
'../models/Task'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
User
}
from
'../models/User'
;
import
{
User
}
from
'../models/User'
;
...
@@ -10,8 +10,6 @@ const router:Router = express.Router();
...
@@ -10,8 +10,6 @@ const router:Router = express.Router();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
/**get all tasks */
/**get all tasks */
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
const
tasks
=
await
dataSource
const
tasks
=
await
dataSource
...
@@ -24,6 +22,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
...
@@ -24,6 +22,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
/**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
,
dateTimeTaskArray
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
const
{
user
,
title
,
description
,
project
,
dateTimeTaskArray
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
...
@@ -49,6 +48,7 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
...
@@ -49,6 +48,7 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
return
res
.
send
({
newTask
});
return
res
.
send
({
newTask
});
})
})
/**check tasks of specific user by userID */
/**check tasks of specific user by userID */
router
.
get
(
'/user/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
get
(
'/user/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
userId
=
req
.
params
.
userId
;
const
userId
=
req
.
params
.
userId
;
...
@@ -75,6 +75,7 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
...
@@ -75,6 +75,7 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
/**check tasks of current user where he is author or executor, search by id*/
/**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
>=>
{
router
.
get
(
'/my'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
token
=
req
.
get
(
'Authorization'
);
...
@@ -102,6 +103,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
...
@@ -102,6 +103,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
/**check tasks of projects in which current user is involved, search by token*/
/**check tasks of projects in which current user is involved, search by token*/
router
.
get
(
'/related'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
get
(
'/related'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
user
=
req
.
body
.
user
const
user
=
req
.
body
.
user
...
@@ -143,11 +145,11 @@ router.get('/related', auth,async (req: Request, res: Response):Promise<Response
...
@@ -143,11 +145,11 @@ router.get('/related', auth,async (req: Request, res: Response):Promise<Response
)}
)}
}
}
})
})
}
}
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
/**delete of task by task id */
/**delete of task by task id */
router
.
delete
(
'/:taskId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
delete
(
'/:taskId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
taskId
=
req
.
params
.
taskId
;
const
taskId
=
req
.
params
.
taskId
;
...
@@ -162,9 +164,8 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
...
@@ -162,9 +164,8 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
})
})
/**
modification
of task by task id */
/**
change
of task by task id */
router
.
put
(
'/'
,
auth
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
router
.
put
(
'/'
,
auth
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
{
user
,
id
,
title
,
description
,
project
,
dateTimeTaskArray
,
executor
,
accomplish
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
const
{
user
,
id
,
title
,
description
,
project
,
dateTimeTaskArray
,
executor
,
accomplish
,
dateTimeDeadLine
,
priority
}
=
req
.
body
;
const
task
=
await
dataSource
const
task
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
...
@@ -197,14 +198,7 @@ router.put('/',auth,async(req:Request, res:Response)=> {
...
@@ -197,14 +198,7 @@ router.put('/',auth,async(req:Request, res:Response)=> {
})
})
/**create copy of task */
/** search all tasks on given projects: project Id array[] */
router
.
post
(
'make-copy'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
})
/** search all tasks on given projects: projectId[] */
router
.
post
(
'/project'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
post
(
'/project'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
let
projectArray
:
string
[]
=
req
.
body
;
let
projectArray
:
string
[]
=
req
.
body
;
if
(
projectArray
.
length
===
0
)
{
if
(
projectArray
.
length
===
0
)
{
...
...
planner-api/src/server.ts
View file @
2f75a546
...
@@ -4,6 +4,7 @@ import users from './routers/users';
...
@@ -4,6 +4,7 @@ import users from './routers/users';
import
tasks
from
'./routers/tasks'
;
import
tasks
from
'./routers/tasks'
;
import
projects
from
'./routers/projects'
;
import
projects
from
'./routers/projects'
;
import
{
myDataSource
}
from
'./app-data-source'
;
import
{
myDataSource
}
from
'./app-data-source'
;
import
copyTasks
from
'./routers/copyTasks'
;
myDataSource
myDataSource
...
@@ -22,6 +23,7 @@ app.use(express.json());
...
@@ -22,6 +23,7 @@ app.use(express.json());
const
PORT
=
8000
;
const
PORT
=
8000
;
app
.
use
(
'/users'
,
users
)
app
.
use
(
'/users'
,
users
)
app
.
use
(
'/tasks'
,
tasks
)
app
.
use
(
'/tasks'
,
tasks
)
app
.
use
(
'/copy-tasks'
,
copyTasks
)
app
.
use
(
'/projects'
,
projects
)
app
.
use
(
'/projects'
,
projects
)
const
run
=
async
()
=>
{
const
run
=
async
()
=>
{
...
...
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