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
c7557dfc
Commit
c7557dfc
authored
Nov 08, 2022
by
“Yevgeniy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#33
added put and update routers/tasks
parent
15ec7a8c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
18 deletions
+77
-18
Task.ts
planner-api/src/models/Task.ts
+11
-4
User.ts
planner-api/src/models/User.ts
+9
-9
tasks.ts
planner-api/src/routers/tasks.ts
+57
-5
No files found.
planner-api/src/models/Task.ts
View file @
c7557dfc
...
@@ -12,6 +12,7 @@ import {
...
@@ -12,6 +12,7 @@ import {
import
{
Project
}
from
'./Project'
;
import
{
Project
}
from
'./Project'
;
type
taskFinishType
=
"open"
|
"done"
|
"failed"
;
type
taskFinishType
=
"open"
|
"done"
|
"failed"
;
type
priorityType
=
"A"
|
"B"
|
"C"
;
interface
ITask
{
interface
ITask
{
id
:
string
;
id
:
string
;
...
@@ -21,6 +22,7 @@ import {
...
@@ -21,6 +22,7 @@ import {
dateTimeStart
:
Date
|
null
;
dateTimeStart
:
Date
|
null
;
dateTimeDue
:
Date
|
null
;
dateTimeDue
:
Date
|
null
;
accomplish
:
taskFinishType
;
accomplish
:
taskFinishType
;
priority
:
priorityType
;
author
:
User
;
author
:
User
;
project
:
Project
|
null
;
project
:
Project
|
null
;
executors
:
User
[]
executors
:
User
[]
...
@@ -48,10 +50,15 @@ import {
...
@@ -48,10 +50,15 @@ import {
})
})
accomplish
!
:
taskFinishType
accomplish
!
:
taskFinishType
@
Column
({
name
:
'dateTimeStart'
,
type
:
Date
,
nullable
:
true
})
dateTimeStart
!
:
Date
|
null
;
@
Column
({
@
Column
({
name
:
'dateTimeDue'
,
type
:
Date
,
nullable
:
true
})
type
:
"enum"
,
dateTimeDue
!
:
Date
|
null
;
enum
:
[
"A"
,
"B"
,
"C"
],
default
:
"C"
})
priority
!
:
priorityType
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
})
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
})
author
!
:
User
;
author
!
:
User
;
...
...
planner-api/src/models/User.ts
View file @
c7557dfc
...
@@ -41,26 +41,26 @@ interface IUser {
...
@@ -41,26 +41,26 @@ interface IUser {
@
Entity
({
name
:
'User'
})
@
Entity
({
name
:
'User'
})
export
class
User
extends
BaseEntity
implements
IUser
{
export
class
User
extends
BaseEntity
implements
IUser
{
@
PrimaryGeneratedColumn
(
'uuid'
)
@
PrimaryGeneratedColumn
(
"uuid"
)
id
!
:
string
id
!
:
string
;
@
Column
({
name
:
'name'
,
type
:
'varchar'
,
length
:
20
,
nullable
:
false
})
@
Column
({
name
:
'name'
,
type
:
'varchar'
,
length
:
20
,
nullable
:
false
})
name
!
:
string
name
!
:
string
;
@
Column
({
name
:
'surname'
,
type
:
'varchar'
,
length
:
30
,
nullable
:
false
})
@
Column
({
name
:
'surname'
,
type
:
'varchar'
,
length
:
30
,
nullable
:
false
})
surname
!
:
string
surname
!
:
string
;
@
Column
({
name
:
'displayName'
,
type
:
'varchar'
,
length
:
30
,
nullable
:
false
})
@
Column
({
name
:
'displayName'
,
type
:
'varchar'
,
length
:
30
,
nullable
:
false
})
displayName
!
:
string
displayName
!
:
string
;
@
Column
({
name
:
'email'
,
type
:
'varchar'
,
length
:
20
,
unique
:
true
,
nullable
:
false
})
@
Column
({
name
:
'email'
,
type
:
'varchar'
,
length
:
20
,
unique
:
true
,
nullable
:
false
})
@
IsEmail
()
@
IsEmail
()
email
!
:
string
email
!
:
string
;
@
Column
({
name
:
'phone'
,
type
:
'varchar'
,
length
:
10
,
unique
:
true
,
nullable
:
true
})
@
Column
({
name
:
'phone'
,
type
:
'varchar'
,
length
:
10
,
unique
:
true
,
nullable
:
true
})
phone
?:
string
phone
?:
string
;
@
Column
({
name
:
'token'
,
type
:
'varchar'
,
length
:
100
,
unique
:
true
,
nullable
:
false
})
@
Column
({
name
:
'token'
,
type
:
'varchar'
,
length
:
100
,
unique
:
true
,
nullable
:
false
})
token
!
:
string
token
!
:
string
;
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
createdAt
!
:
Date
;
...
@@ -74,7 +74,7 @@ export class User extends BaseEntity implements IUser {
...
@@ -74,7 +74,7 @@ export class User extends BaseEntity implements IUser {
@
Column
({
type
:
'varchar'
,
nullable
:
false
,
select
:
true
})
@
Column
({
type
:
'varchar'
,
nullable
:
false
,
select
:
true
})
@
Exclude
({
toPlainOnly
:
true
})
@
Exclude
({
toPlainOnly
:
true
})
password
!
:
string
password
!
:
string
;
@
OneToMany
(()
=>
Task
,
(
task
:
{
user
:
User
})
=>
task
.
user
)
@
OneToMany
(()
=>
Task
,
(
task
:
{
user
:
User
})
=>
task
.
user
)
...
...
planner-api/src/routers/tasks.ts
View file @
c7557dfc
...
@@ -17,7 +17,7 @@ export default router;
...
@@ -17,7 +17,7 @@ export default router;
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
token
=
req
.
get
(
'Authorization'
);
const
newTask
=
new
Task
();
const
newTask
=
new
Task
();
const
{
title
,
description
,
project
,
executors
,
dateTimeDue
,
dateTimeStart
,
accomplish
}
=
req
.
body
;
const
{
title
,
description
,
project
,
executors
,
dateTimeDue
,
dateTimeStart
,
accomplish
,
priority
}
=
req
.
body
;
const
user
=
await
dataSource
const
user
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
"user"
)
.
select
(
"user"
)
...
@@ -33,11 +33,12 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
...
@@ -33,11 +33,12 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
author
=
user
;
newTask
.
author
=
user
;
newTask
.
accomplish
=
accomplish
;
newTask
.
accomplish
=
accomplish
;
newTask
.
priority
=
priority
;
await
newTask
.
save
();
await
newTask
.
save
();
return
res
.
send
({
newTask
})
return
res
.
send
({
newTask
})
})
})
router
.
get
(
'/userId/:userId'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
router
.
get
(
'/userId/:userId'
,
async
(
req
:
Request
,
res
:
Response
)
:
Promise
<
Response
>
=>
{
const
userId
=
req
.
params
.
userId
;
const
userId
=
req
.
params
.
userId
;
const
tasks
=
await
dataSource
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
getRepository
(
Task
)
...
@@ -48,8 +49,7 @@ router.get('/userId/:userId', async (req: Request, res: Response)=>{
...
@@ -48,8 +49,7 @@ router.get('/userId/:userId', async (req: Request, res: Response)=>{
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
router
.
get
(
'/my'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
get
(
'/my'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
token
=
req
.
get
(
'Authorization'
);
const
user
=
await
dataSource
const
user
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
...
@@ -65,4 +65,56 @@ router.get('/my', async (req: Request, res: Response)=>{
...
@@ -65,4 +65,56 @@ router.get('/my', async (req: Request, res: Response)=>{
.
where
(
'user.id = :userId'
,
{
userId
:
user
.
id
})
.
where
(
'user.id = :userId'
,
{
userId
:
user
.
id
})
.
getMany
()
.
getMany
()
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
\ No newline at end of file
router
.
delete
(
'/:taskId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
// const token = req.get('Authorization');
// const user = await dataSource
// .createQueryBuilder()
// .select("user")
// .from(User, "user")
// .where("user.token = :token", { token: token })
// .getOne()
// if(!user) return res.status(404).send({Message:'user not found'})
const
taskId
=
req
.
params
.
taskId
;
await
myDataSource
.
createQueryBuilder
()
.
delete
()
.
from
(
Task
)
.
where
(
"id = :id"
,
{
id
:
taskId
})
.
execute
()
return
res
.
send
({
message
:
'Task deleted successfully'
})
})
router
.
put
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
user
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"user"
)
.
from
(
User
,
"user"
)
.
where
(
"user.token = :token"
,
{
token
:
token
})
.
getOne
()
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
const
{
id
,
title
,
description
,
project
,
executors
,
dateTimeDue
,
dateTimeStart
,
accomplish
,
priority
}
=
req
.
body
;
await
dataSource
.
createQueryBuilder
()
.
update
(
Task
)
.
set
({
title
:
title
,
description
:
description
,
project
:
project
,
executors
:
executors
,
dateTimeDue
:
dateTimeDue
,
dateTimeStart
:
dateTimeStart
,
author
:
user
,
accomplish
:
accomplish
,
priority
:
priority
})
.
where
(
"id = :id"
,
{
id
:
id
})
.
execute
()
res
.
send
({
message
:
'update task successfully'
})
// res.send({task})
})
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