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
37c61d64
Commit
37c61d64
authored
Nov 06, 2022
by
“Yevgeniy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#25
finished task, user CR, fix many to many relations
parent
9c90a525
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
47 deletions
+111
-47
Project.ts
planner-api/src/models/Project.ts
+10
-8
Task.ts
planner-api/src/models/Task.ts
+16
-11
User.ts
planner-api/src/models/User.ts
+8
-4
projects.ts
planner-api/src/routers/projects.ts
+17
-18
tasks.ts
planner-api/src/routers/tasks.ts
+56
-5
users.ts
planner-api/src/routers/users.ts
+4
-1
No files found.
planner-api/src/models/Project.ts
View file @
37c61d64
...
@@ -6,7 +6,8 @@ import {
...
@@ -6,7 +6,8 @@ import {
BaseEntity
,
BaseEntity
,
ManyToOne
,
ManyToOne
,
ManyToMany
,
ManyToMany
,
OneToMany
OneToMany
,
JoinTable
}
from
'typeorm'
;
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
import
{
User
}
from
'./User'
;
import
{
Task
}
from
'./Task'
;
import
{
Task
}
from
'./Task'
;
...
@@ -61,12 +62,13 @@ import {
...
@@ -61,12 +62,13 @@ import {
@
Column
({
name
:
'department'
,
type
:
Boolean
,
nullable
:
true
,
default
:
false
})
@
Column
({
name
:
'department'
,
type
:
Boolean
,
nullable
:
true
,
default
:
false
})
department
!
:
boolean
;
department
!
:
boolean
;
@
ManyToOne
(()
=>
User
,
(
user
:
{
projects
:
Project
[];
})
=>
user
.
projects
)
@
ManyToOne
(()
=>
User
,
(
user
:
{
projects
:
Project
[];
})
=>
user
.
projects
,{
eager
:
true
}
)
admin
!
:
User
;
admin
!
:
User
;
@
ManyToMany
(()
=>
User
,
(
user
:
{
projects
:
Project
[];
})
=>
user
.
projects
)
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
,{
eager
:
true
})
workers
!
:
User
[];
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
)
tasks
!
:
Task
[]
|
null
;
tasks
!
:
Task
[]
|
null
;
}
@
ManyToMany
(()
=>
User
,
(
user
:
{
projects
:
Project
[];
})
=>
user
.
projects
,{
eager
:
true
})
@
JoinTable
()
workers
!
:
User
[];
}
\ No newline at end of file
planner-api/src/models/Task.ts
View file @
37c61d64
...
@@ -5,7 +5,8 @@ import {
...
@@ -5,7 +5,8 @@ import {
CreateDateColumn
,
CreateDateColumn
,
BaseEntity
,
BaseEntity
,
ManyToOne
,
ManyToOne
,
ManyToMany
ManyToMany
,
JoinTable
}
from
'typeorm'
;
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
import
{
User
}
from
'./User'
;
import
{
Project
}
from
'./Project'
;
import
{
Project
}
from
'./Project'
;
...
@@ -17,12 +18,12 @@ import {
...
@@ -17,12 +18,12 @@ import {
title
:
string
;
title
:
string
;
description
:
string
;
description
:
string
;
createdAt
:
Date
;
createdAt
:
Date
;
// dateTimeStart:Date| null;
dateTimeStart
:
Date
|
null
;
// dateTimeDue:Date| null;
dateTimeDue
:
Date
|
null
;
assignedTo
:
User
[];
accomplish
:
taskFinishType
;
accomplish
:
taskFinishType
;
author
:
User
;
author
:
User
;
project
:
Project
|
null
;
project
:
Project
|
null
;
executors
:
User
[]
}
}
@
Entity
({
name
:
'Task'
})
@
Entity
({
name
:
'Task'
})
...
@@ -35,10 +36,10 @@ import {
...
@@ -35,10 +36,10 @@ import {
description
!
:
string
description
!
:
string
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
createdAt
!
:
Date
;
// @CreateDate
Column({ name: 'dateTimeStart', type: Date,nullable: true })
@
Column
({
name
:
'dateTimeStart'
,
type
:
Date
,
nullable
:
true
})
//
dateTimeStart!: Date | null;
dateTimeStart
!
:
Date
|
null
;
// @CreateDate
Column({ name: 'dateTimeDue', type: Date,nullable: true })
@
Column
({
name
:
'dateTimeDue'
,
type
:
Date
,
nullable
:
true
})
//
dateTimeDue!: Date | null;
dateTimeDue
!
:
Date
|
null
;
@
Column
({
@
Column
({
type
:
"enum"
,
type
:
"enum"
,
enum
:
[
"opened"
,
"done"
,
"failed"
],
enum
:
[
"opened"
,
"done"
,
"failed"
],
...
@@ -47,12 +48,16 @@ import {
...
@@ -47,12 +48,16 @@ import {
accomplish
!
:
taskFinishType
accomplish
!
:
taskFinishType
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
)
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
}
)
author
!
:
User
;
author
!
:
User
;
@
ManyToMany
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
)
@
ManyToMany
(()
=>
User
,{
eager
:
true
})
assignedTo
!
:
User
[];
@
JoinTable
()
executors
!
:
User
[];
@
ManyToOne
(()
=>
Project
,(
project
:{
tasks
:
Task
[]})
=>
project
.
tasks
)
@
ManyToOne
(()
=>
Project
,(
project
:{
tasks
:
Task
[]})
=>
project
.
tasks
)
project
!
:
Project
|
null
;
project
!
:
Project
|
null
;
}
}
planner-api/src/models/User.ts
View file @
37c61d64
...
@@ -6,7 +6,8 @@ import {
...
@@ -6,7 +6,8 @@ import {
BeforeInsert
,
BeforeInsert
,
BaseEntity
,
BaseEntity
,
ManyToMany
,
ManyToMany
,
OneToMany
OneToMany
,
JoinTable
}
from
'typeorm'
;
}
from
'typeorm'
;
import
{
IsEmail
import
{
IsEmail
...
@@ -31,7 +32,9 @@ interface IUser {
...
@@ -31,7 +32,9 @@ interface IUser {
token
:
string
;
token
:
string
;
role
:
userRoleType
;
role
:
userRoleType
;
createdAt
:
Date
;
createdAt
:
Date
;
createdTasks
:
Task
[]
|
null
;
createdTasks
:
Task
[];
workerInProjects
:
Project
[];
adminInProjects
:
Project
[];
}
}
...
@@ -77,13 +80,14 @@ export class User extends BaseEntity implements IUser {
...
@@ -77,13 +80,14 @@ export class User extends BaseEntity implements IUser {
createdTasks
!
:
Task
[];
createdTasks
!
:
Task
[];
@
ManyToMany
(()
=>
Task
,
(
task
:
{
users
:
User
[]
})
=>
task
.
users
)
@
ManyToMany
(()
=>
Task
,
(
task
:
{
users
:
User
[]
})
=>
task
.
users
)
tasks
ToMake
!
:
Task
[];
tasks
!
:
Task
[];
@
OneToMany
(()
=>
Project
,
(
project
:
{
user
:
User
})
=>
project
.
user
)
@
OneToMany
(()
=>
Project
,
(
project
:
{
user
:
User
})
=>
project
.
user
)
adminInProjects
!
:
Project
[];
adminInProjects
!
:
Project
[];
@
ManyToMany
(()
=>
Project
,
(
project
:
{
users
:
User
[]
})
=>
project
.
users
)
@
ManyToMany
(()
=>
Project
,(
project
:
{
user
:
User
})
=>
project
.
user
)
@
JoinTable
()
workerInProjects
!
:
Project
[];
workerInProjects
!
:
Project
[];
...
...
planner-api/src/routers/projects.ts
View file @
37c61d64
...
@@ -12,29 +12,16 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
...
@@ -12,29 +12,16 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
return
res
.
send
({
projects
})
return
res
.
send
({
projects
})
})
})
router
.
get
(
"/project_id/:project_id"
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
const
project
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"project"
)
.
from
(
Project
,
"project"
)
// .where("user.workerInProjects= :projects", {projects.id : req.params.project_id } )
// .innerJoinAndSelect('project.workers','user')
.
leftJoinAndSelect
(
'project.admin'
,
'user'
)
.
where
(
"project.id = :id"
,
{
id
:
req
.
params
.
project_id
})
.
getOne
()
if
(
!
project
)
return
res
.
status
(
404
).
send
({
Message
:
'no such project in the base'
})
return
res
.
send
({
project
})
})
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
if
(
!
req
.
body
)
return
res
.
status
(
400
).
send
({
Message
:
'problem in incoming req.body'
})
if
(
!
req
.
body
)
return
res
.
status
(
400
).
send
({
Message
:
'problem in incoming req.body'
})
const
{
title
,
dateDue
,
color
,
department
,
userId
,
workers
,
tasks
}
=
req
.
body
;
const
token
=
req
.
get
(
'Authorization'
);
const
{
title
,
dateDue
,
color
,
department
,
workers
,
tasks
}
=
req
.
body
;
const
user
=
await
dataSource
const
user
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
"user"
)
.
select
(
"user"
)
.
from
(
User
,
"user"
)
.
from
(
User
,
"user"
)
.
where
(
"user.
id = :id"
,
{
id
:
userId
})
.
where
(
"user.
token = :token"
,
{
token
:
token
})
.
getOne
()
.
getOne
()
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
const
project
:
Project
=
new
Project
()
const
project
:
Project
=
new
Project
()
...
@@ -49,8 +36,19 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
...
@@ -49,8 +36,19 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
return
res
.
send
({
project
})
return
res
.
send
({
project
})
})
})
router
.
get
(
"/id/:id"
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
const
project
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"project"
)
.
from
(
Project
,
"project"
)
.
leftJoinAndSelect
(
'project.admin'
,
'user'
)
.
where
(
"project.id = :id"
,
{
id
:
req
.
params
.
id
})
.
getOne
()
if
(
!
project
)
return
res
.
status
(
404
).
send
({
Message
:
'no info on this project'
})
return
res
.
send
({
project
})
})
router
.
get
(
'/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
get
(
'/
userId/
:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
userId
:
string
=
req
.
params
.
userId
const
userId
:
string
=
req
.
params
.
userId
const
user
=
await
dataSource
const
user
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
...
@@ -63,7 +61,8 @@ router.get('/:userId', async (req : Request, res : Response): Promise<Response>=
...
@@ -63,7 +61,8 @@ router.get('/:userId', async (req : Request, res : Response): Promise<Response>=
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
'project'
)
.
select
(
'project'
)
.
from
(
Project
,
"project"
)
.
from
(
Project
,
"project"
)
.
where
(
"Project_adminId = :id"
,
{
id
:
userId
})
.
where
(
"project.admin = :id"
,
{
id
:
userId
})
.
getMany
();
return
res
.
send
({
userProjects
})
return
res
.
send
({
userProjects
})
})
})
...
...
planner-api/src/routers/tasks.ts
View file @
37c61d64
import
express
,{
Router
,
Request
,
Response
}
from
'express'
;
import
express
,{
Router
,
Request
,
Response
}
from
'express'
;
// import {User} from '../models/User';
// import {Project} from '../models/Project';
import
{
Task
}
from
'../models/Task'
;
import
{
Task
}
from
'../models/Task'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
myDataSource
}
from
'../app-data-source'
;
// import { nanoid } from 'nanoid';
import
{
User
}
from
'../models/User'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
const
tasks
=
await
dataSource
.
manager
.
find
(
Task
)
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
find
()
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
export
default
router
;
export
default
router
;
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
newTask
=
new
Task
();
const
{
title
,
description
,
project
,
executors
,
dateTimeDue
,
dateTimeStart
}
=
req
.
body
;
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'
})
newTask
.
title
=
title
;
newTask
.
description
=
description
;
newTask
.
project
=
project
;
newTask
.
executors
=
executors
;
newTask
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
author
=
user
;
await
newTask
.
save
();
return
res
.
send
({
newTask
})
})
router
.
get
(
'/userId/:userId'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
userId
=
req
.
params
.
userId
;
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
createQueryBuilder
(
'task'
)
.
innerJoinAndSelect
(
'task.executors'
,
'user'
)
.
where
(
'user.id = :userId'
,
{
userId
:
userId
})
.
getMany
()
return
res
.
send
({
tasks
})
})
router
.
get
(
'/my'
,
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
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
createQueryBuilder
(
'task'
)
.
innerJoinAndSelect
(
'task.executors'
,
'user'
)
.
where
(
'user.id = :userId'
,
{
userId
:
user
.
id
})
.
getMany
()
return
res
.
send
({
tasks
})
})
\ No newline at end of file
planner-api/src/routers/users.ts
View file @
37c61d64
...
@@ -7,7 +7,10 @@ const router:Router = express.Router();
...
@@ -7,7 +7,10 @@ const router:Router = express.Router();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
const
users
=
await
dataSource
.
manager
.
find
(
User
)
const
users
=
await
dataSource
.
getRepository
(
User
)
.
createQueryBuilder
(
"user"
)
.
getMany
()
return
res
.
send
({
users
})
return
res
.
send
({
users
})
})
})
...
...
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