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
4aa1ced5
Commit
4aa1ced5
authored
Nov 22, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#58
added fixtures members and fix relations in models, remove related fields in routers
parent
ac604ae7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
21 deletions
+44
-21
fixtures.ts
planner-api/src/fixtures.ts
+15
-4
Member.ts
planner-api/src/models/Member.ts
+1
-1
Task.ts
planner-api/src/models/Task.ts
+4
-4
User.ts
planner-api/src/models/User.ts
+2
-1
projects.ts
planner-api/src/routers/projects.ts
+3
-3
tasks.ts
planner-api/src/routers/tasks.ts
+19
-8
[B[B[B[B[B[B[B[A[A[Aq
[B[B[B[B[B[B[B[A[A[Aq
+0
-0
No files found.
planner-api/src/fixtures.ts
View file @
4aa1ced5
...
@@ -4,6 +4,7 @@ import { User, UserRole } from "./models/User";
...
@@ -4,6 +4,7 @@ import { User, UserRole } from "./models/User";
import
{
faker
}
from
'@faker-js/faker'
;
import
{
faker
}
from
'@faker-js/faker'
;
import
{
Task
}
from
"./models/Task"
;
import
{
Task
}
from
"./models/Task"
;
import
{
Project
}
from
"./models/Project"
;
import
{
Project
}
from
"./models/Project"
;
import
{
Member
,
MemberRole
}
from
"./models/Member"
;
function
randomIntFromInterval
(
min
:
number
,
max
:
number
)
{
function
randomIntFromInterval
(
min
:
number
,
max
:
number
)
{
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
)
+
min
)
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
)
+
min
)
...
@@ -50,7 +51,7 @@ const loadFixtures = async () => {
...
@@ -50,7 +51,7 @@ const loadFixtures = async () => {
const
newTask
=
new
Task
();
const
newTask
=
new
Task
();
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
newTask
.
description
=
faker
.
random
.
words
(
4
);
newTask
.
description
=
faker
.
random
.
words
(
4
);
newTask
.
executor
s
=
faker
.
helpers
.
arrayElements
(
users
,
randomIntFromInterval
(
0
,
3
)
);
newTask
.
executor
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
dateTimeDue
=
faker
.
date
.
soon
(
randomIntFromInterval
(
1
,
15
));
newTask
.
dateTimeDue
=
faker
.
date
.
soon
(
randomIntFromInterval
(
1
,
15
));
newTask
.
dateTimeStart
=
faker
.
date
.
recent
((
randomIntFromInterval
(
0
,
8
)));
newTask
.
dateTimeStart
=
faker
.
date
.
recent
((
randomIntFromInterval
(
0
,
8
)));
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
...
@@ -62,7 +63,7 @@ const loadFixtures = async () => {
...
@@ -62,7 +63,7 @@ const loadFixtures = async () => {
const
newTask
=
new
Task
();
const
newTask
=
new
Task
();
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
newTask
.
description
=
faker
.
random
.
words
(
4
);
newTask
.
description
=
faker
.
random
.
words
(
4
);
newTask
.
executor
s
=
faker
.
helpers
.
arrayElements
(
users
,
randomIntFromInterval
(
0
,
3
)
);
newTask
.
executor
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
dateTimeDue
=
null
;
newTask
.
dateTimeDue
=
null
;
newTask
.
dateTimeStart
=
null
;
newTask
.
dateTimeStart
=
null
;
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
...
@@ -73,14 +74,24 @@ const loadFixtures = async () => {
...
@@ -73,14 +74,24 @@ const loadFixtures = async () => {
}
}
}
}
const
members
:
Member
[]
=
[]
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
const
newMember
=
new
Member
();
newMember
.
user
=
faker
.
helpers
.
arrayElement
(
users
);
newMember
.
role
=
faker
.
helpers
.
objectValue
(
MemberRole
);
await
newMember
.
save
();
members
.
push
(
newMember
)
}
const
projects
:
Project
[]
=
[]
const
projects
:
Project
[]
=
[]
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
const
newProject
=
new
Project
();
const
newProject
=
new
Project
();
newProject
.
title
=
`Project
${
faker
.
random
.
words
(
1
)}
`
;
newProject
.
title
=
`Project
${
faker
.
random
.
words
(
1
)}
`
;
newProject
.
color
=
faker
.
random
.
words
(
1
);
newProject
.
color
=
faker
.
random
.
words
(
1
);
newProject
.
admin
=
faker
.
helpers
.
arrayElement
(
users
);
newProject
.
members
=
faker
.
helpers
.
arrayElements
(
members
,
randomIntFromInterval
(
1
,
3
))
// newProject.admin = faker.helpers.arrayElement(users);
newProject
.
tasks
=
faker
.
helpers
.
arrayElements
(
tasks
,
randomIntFromInterval
(
1
,
3
));
newProject
.
tasks
=
faker
.
helpers
.
arrayElements
(
tasks
,
randomIntFromInterval
(
1
,
3
));
newProject
.
workers
=
faker
.
helpers
.
arrayElements
(
users
,
randomIntFromInterval
(
1
,
3
));
//
newProject.workers = faker.helpers.arrayElements(users, randomIntFromInterval(1, 3));
await
newProject
.
save
();
await
newProject
.
save
();
projects
.
push
(
newProject
)
projects
.
push
(
newProject
)
}
}
...
...
planner-api/src/models/Member.ts
View file @
4aa1ced5
...
@@ -37,7 +37,7 @@ import {
...
@@ -37,7 +37,7 @@ import {
@
ManyToOne
(()
=>
User
,
(
user
:
{
members
:
Member
[];
})
=>
user
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
})
@
ManyToOne
(()
=>
User
,
(
user
:
{
members
:
Member
[];
})
=>
user
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
})
user
!
:
User
;
user
!
:
User
;
@
ManyToOne
(()
=>
Project
,
(
project
:
{
members
:
Member
[];
})
=>
project
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
})
@
ManyToOne
(()
=>
Project
,
(
project
:
{
members
:
Member
[];
})
=>
project
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
,
nullable
:
true
})
project
!
:
Project
;
project
!
:
Project
;
@
Column
({
@
Column
({
...
...
planner-api/src/models/Task.ts
View file @
4aa1ced5
...
@@ -5,7 +5,7 @@ import {
...
@@ -5,7 +5,7 @@ import {
CreateDateColumn
,
CreateDateColumn
,
BaseEntity
,
BaseEntity
,
ManyToOne
,
ManyToOne
,
ManyToMany
,
OneToOne
,
JoinTable
JoinTable
}
from
'typeorm'
;
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
import
{
User
}
from
'./User'
;
...
@@ -25,7 +25,7 @@ import {
...
@@ -25,7 +25,7 @@ import {
priority
:
priorityType
|
null
;
priority
:
priorityType
|
null
;
author
:
User
;
author
:
User
;
project
:
Project
|
null
;
project
:
Project
|
null
;
executor
s
:
User
[]
;
executor
:
User
;
}
}
@
Entity
({
name
:
'Task'
})
@
Entity
({
name
:
'Task'
})
...
@@ -64,9 +64,9 @@ import {
...
@@ -64,9 +64,9 @@ import {
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
})
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
})
author
!
:
User
;
author
!
:
User
;
@
ManyTo
Many
(()
=>
User
,{
eager
:
true
,
cascad
e
:
true
,
onUpdate
:
'CASCADE'
})
@
ManyTo
One
(()
=>
User
,
(
user
:
{
tasks
:
Task
[]})
=>
user
.
tasks
,{
eager
:
true
,
nullabl
e
:
true
,
onUpdate
:
'CASCADE'
})
@
JoinTable
()
@
JoinTable
()
executor
s
!
:
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'
})
project
!
:
Project
;
project
!
:
Project
;
...
...
planner-api/src/models/User.ts
View file @
4aa1ced5
...
@@ -8,6 +8,7 @@ import {
...
@@ -8,6 +8,7 @@ import {
ManyToMany
,
ManyToMany
,
OneToMany
,
OneToMany
,
JoinTable
,
JoinTable
,
OneToOne
,
}
from
'typeorm'
;
}
from
'typeorm'
;
import
{
IsEmail
import
{
IsEmail
}
from
"class-validator"
;
}
from
"class-validator"
;
...
@@ -82,7 +83,7 @@ export class User extends BaseEntity implements IUser {
...
@@ -82,7 +83,7 @@ export class User extends BaseEntity implements IUser {
@
OneToMany
(()
=>
Task
,
(
task
:
{
user
:
User
})
=>
task
.
user
)
@
OneToMany
(()
=>
Task
,
(
task
:
{
user
:
User
})
=>
task
.
user
)
createdTasks
!
:
Task
[];
createdTasks
!
:
Task
[];
@
ManyToMany
(()
=>
Task
,
(
task
:
{
users
:
User
[]
})
=>
task
.
users
)
@
OneToMany
(()
=>
Task
,
(
task
:
{
user
:
User
})
=>
task
.
user
)
tasks
!
:
Task
[];
tasks
!
:
Task
[];
...
...
planner-api/src/routers/projects.ts
View file @
4aa1ced5
...
@@ -29,10 +29,10 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
...
@@ -29,10 +29,10 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
project
.
title
=
title
;
project
.
title
=
title
;
project
.
color
=
color
;
project
.
color
=
color
;
project
.
dateDue
=
dateDue
||
null
;
project
.
dateDue
=
dateDue
||
null
;
project
.
department
=
department
;
//
project.department = department;
project
.
workers
=
workers
||
null
;
//
project.workers = workers|| null;
project
.
tasks
=
tasks
||
null
;
project
.
tasks
=
tasks
||
null
;
project
.
admin
=
user
;
//
project.admin = user;
await
project
.
save
()
await
project
.
save
()
return
res
.
send
({
project
})
return
res
.
send
({
project
})
})
})
...
...
planner-api/src/routers/tasks.ts
View file @
4aa1ced5
...
@@ -3,6 +3,7 @@ import {Task} from '../models/Task';
...
@@ -3,6 +3,7 @@ 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'
;
import
{
Project
}
from
'../models/Project'
;
import
{
Project
}
from
'../models/Project'
;
import
{
Member
}
from
'../models/Member'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
...
@@ -28,7 +29,7 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
...
@@ -28,7 +29,7 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
newTask
.
title
=
title
;
newTask
.
title
=
title
;
newTask
.
description
=
description
;
newTask
.
description
=
description
;
newTask
.
project
=
project
;
newTask
.
project
=
project
;
newTask
.
executors
=
executors
;
//
newTask.executors = executors;
newTask
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
author
=
user
;
newTask
.
author
=
user
;
...
@@ -38,13 +39,23 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
...
@@ -38,13 +39,23 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
return
res
.
send
({
newTask
})
return
res
.
send
({
newTask
})
})
})
router
.
get
(
'/: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
;
// const tasks = await dataSource
// .getRepository(Task)
// .createQueryBuilder('task')
// .innerJoinAndSelect('task.executors', 'user')
// .where('user.id = :userId', {userId :userId})
// .getMany()
// return res.send({tasks})
const
tasks
=
await
dataSource
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
getRepository
(
Member
)
.
createQueryBuilder
(
'task'
)
.
createQueryBuilder
(
'member'
)
.
innerJoinAndSelect
(
'task.executors'
,
'user'
)
.
innerJoinAndSelect
(
'member.project'
,
'project'
)
.
where
(
'user.id = :userId'
,
{
userId
:
userId
})
.
innerJoinAndSelect
(
'project.tasks'
,
'task'
)
.
where
(
'member.user.id = :userId'
)
.
andWhere
(
'member.project.id= task.project.id'
)
.
select
(
'task.*'
)
.
getMany
()
.
getMany
()
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
...
@@ -104,7 +115,7 @@ router.put('/',async(req:Request, res:Response)=> {
...
@@ -104,7 +115,7 @@ router.put('/',async(req:Request, res:Response)=> {
task
.
dateTimeDue
=
dateTimeDue
task
.
dateTimeDue
=
dateTimeDue
task
.
dateTimeStart
=
dateTimeStart
task
.
dateTimeStart
=
dateTimeStart
task
.
author
=
user
task
.
author
=
user
task
.
executors
=
executors
//
task.executors=executors
task
.
accomplish
=
accomplish
task
.
accomplish
=
accomplish
task
.
priority
=
priority
task
.
priority
=
priority
await
task
.
save
()
await
task
.
save
()
...
@@ -121,7 +132,7 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
...
@@ -121,7 +132,7 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
.
getRepository
(
Task
)
.
getRepository
(
Task
)
.
find
({
.
find
({
relations
:{
relations
:{
executors
:
true
,
//
executors:true,
author
:
true
,
author
:
true
,
project
:
true
project
:
true
}
}
...
...
[B[B[B[B[B[B[B[A[A[Aq
0 → 100644
View file @
4aa1ced5
This diff is collapsed.
Click to expand it.
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