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
Hide 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";
import
{
faker
}
from
'@faker-js/faker'
;
import
{
Task
}
from
"./models/Task"
;
import
{
Project
}
from
"./models/Project"
;
import
{
Member
,
MemberRole
}
from
"./models/Member"
;
function
randomIntFromInterval
(
min
:
number
,
max
:
number
)
{
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
)
+
min
)
...
...
@@ -50,7 +51,7 @@ const loadFixtures = async () => {
const
newTask
=
new
Task
();
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
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
.
dateTimeStart
=
faker
.
date
.
recent
((
randomIntFromInterval
(
0
,
8
)));
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
...
...
@@ -62,7 +63,7 @@ const loadFixtures = async () => {
const
newTask
=
new
Task
();
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
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
.
dateTimeStart
=
null
;
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
...
...
@@ -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
[]
=
[]
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
const
newProject
=
new
Project
();
newProject
.
title
=
`Project
${
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
.
workers
=
faker
.
helpers
.
arrayElements
(
users
,
randomIntFromInterval
(
1
,
3
));
//
newProject.workers = faker.helpers.arrayElements(users, randomIntFromInterval(1, 3));
await
newProject
.
save
();
projects
.
push
(
newProject
)
}
...
...
planner-api/src/models/Member.ts
View file @
4aa1ced5
...
...
@@ -37,7 +37,7 @@ import {
@
ManyToOne
(()
=>
User
,
(
user
:
{
members
:
Member
[];
})
=>
user
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
})
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
;
@
Column
({
...
...
planner-api/src/models/Task.ts
View file @
4aa1ced5
...
...
@@ -5,7 +5,7 @@ import {
CreateDateColumn
,
BaseEntity
,
ManyToOne
,
ManyToMany
,
OneToOne
,
JoinTable
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
...
...
@@ -25,7 +25,7 @@ import {
priority
:
priorityType
|
null
;
author
:
User
;
project
:
Project
|
null
;
executor
s
:
User
[]
;
executor
:
User
;
}
@
Entity
({
name
:
'Task'
})
...
...
@@ -64,9 +64,9 @@ import {
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
})
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
()
executor
s
!
:
User
[]
;
executor
!
:
User
;
@
ManyToOne
(()
=>
Project
,(
project
:{
tasks
:
Task
[]})
=>
project
.
tasks
,{
eager
:
true
,
nullable
:
true
,
onUpdate
:
'CASCADE'
})
project
!
:
Project
;
...
...
planner-api/src/models/User.ts
View file @
4aa1ced5
...
...
@@ -8,6 +8,7 @@ import {
ManyToMany
,
OneToMany
,
JoinTable
,
OneToOne
,
}
from
'typeorm'
;
import
{
IsEmail
}
from
"class-validator"
;
...
...
@@ -82,7 +83,7 @@ export class User extends BaseEntity implements IUser {
@
OneToMany
(()
=>
Task
,
(
task
:
{
user
:
User
})
=>
task
.
user
)
createdTasks
!
:
Task
[];
@
ManyToMany
(()
=>
Task
,
(
task
:
{
users
:
User
[]
})
=>
task
.
users
)
@
OneToMany
(()
=>
Task
,
(
task
:
{
user
:
User
})
=>
task
.
user
)
tasks
!
:
Task
[];
...
...
planner-api/src/routers/projects.ts
View file @
4aa1ced5
...
...
@@ -29,10 +29,10 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
project
.
title
=
title
;
project
.
color
=
color
;
project
.
dateDue
=
dateDue
||
null
;
project
.
department
=
department
;
project
.
workers
=
workers
||
null
;
//
project.department = department;
//
project.workers = workers|| null;
project
.
tasks
=
tasks
||
null
;
project
.
admin
=
user
;
//
project.admin = user;
await
project
.
save
()
return
res
.
send
({
project
})
})
...
...
planner-api/src/routers/tasks.ts
View file @
4aa1ced5
...
...
@@ -3,6 +3,7 @@ import {Task} from '../models/Task';
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
User
}
from
'../models/User'
;
import
{
Project
}
from
'../models/Project'
;
import
{
Member
}
from
'../models/Member'
;
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
...
...
@@ -28,7 +29,7 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
newTask
.
title
=
title
;
newTask
.
description
=
description
;
newTask
.
project
=
project
;
newTask
.
executors
=
executors
;
//
newTask.executors = executors;
newTask
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
author
=
user
;
...
...
@@ -38,13 +39,23 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
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 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
.
getRepository
(
Task
)
.
createQueryBuilder
(
'task'
)
.
innerJoinAndSelect
(
'task.executors'
,
'user'
)
.
where
(
'user.id = :userId'
,
{
userId
:
userId
})
.
getRepository
(
Member
)
.
createQueryBuilder
(
'member'
)
.
innerJoinAndSelect
(
'member.project'
,
'project'
)
.
innerJoinAndSelect
(
'project.tasks'
,
'task'
)
.
where
(
'member.user.id = :userId'
)
.
andWhere
(
'member.project.id= task.project.id'
)
.
select
(
'task.*'
)
.
getMany
()
return
res
.
send
({
tasks
})
})
...
...
@@ -104,7 +115,7 @@ router.put('/',async(req:Request, res:Response)=> {
task
.
dateTimeDue
=
dateTimeDue
task
.
dateTimeStart
=
dateTimeStart
task
.
author
=
user
task
.
executors
=
executors
//
task.executors=executors
task
.
accomplish
=
accomplish
task
.
priority
=
priority
await
task
.
save
()
...
...
@@ -121,7 +132,7 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
.
getRepository
(
Task
)
.
find
({
relations
:{
executors
:
true
,
//
executors:true,
author
:
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