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
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
255 additions
and
21 deletions
+255
-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
+211
-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
[1mdiff --git a/planner-api/src/fixtures.ts b/planner-api/src/fixtures.ts[m
[1mindex 8734749..b80ffb6 100644[m
[1m--- a/planner-api/src/fixtures.ts[m
[1m+++ b/planner-api/src/fixtures.ts[m
[36m@@ -4,6 +4,7 @@[m [mimport { User, UserRole } from "./models/User";[m
import { faker } from '@faker-js/faker';[m
import { Task } from "./models/Task";[m
import { Project } from "./models/Project";[m
[32m+[m[32mimport { Member, MemberRole } from "./models/Member";[m
[m
function randomIntFromInterval(min:number, max:number) { [m
return Math.floor(Math.random() * (max - min + 1) + min)[m
[36m@@ -50,7 +51,7 @@[m [mconst loadFixtures = async () => {[m
const newTask = new Task();[m
newTask.title = `Buy ${faker.commerce.productName()}`;[m
newTask.description = faker.random.words(4);[m
[31m- newTask.executors = faker.helpers.arrayElements(users, randomIntFromInterval(0, 3));[m
[32m+[m[32m newTask.executor = faker.helpers.arrayElement(users);[m
newTask.dateTimeDue = faker.date.soon(randomIntFromInterval(1, 15));[m
newTask.dateTimeStart = faker.date.recent((randomIntFromInterval(0, 8)));[m
newTask.author = faker.helpers.arrayElement(users);[m
[36m@@ -62,7 +63,7 @@[m [mconst loadFixtures = async () => {[m
const newTask = new Task();[m
newTask.title = `Buy ${faker.commerce.productName()}`;[m
newTask.description = faker.random.words(4);[m
[31m- newTask.executors = faker.helpers.arrayElements(users, randomIntFromInterval(0, 3));[m
[32m+[m[32m newTask.executor = faker.helpers.arrayElement(users);[m
newTask.dateTimeDue = null;[m
newTask.dateTimeStart = null;[m
newTask.author = faker.helpers.arrayElement(users);[m
[36m@@ -73,14 +74,24 @@[m [mconst loadFixtures = async () => {[m
}[m
}[m
[m
[32m+[m[32m const members:Member[]=[][m
[32m+[m[32m for (let i = 0; i < 5; i++) {[m
[32m+[m[32m const newMember = new Member();[m
[32m+[m[32m newMember.user = faker.helpers.arrayElement(users);[m
[32m+[m[32m newMember.role=faker.helpers.objectValue(MemberRole);[m
[32m+[m[32m await newMember.save();[m
[32m+[m[32m members.push(newMember)[m
[32m+[m[32m }[m
[32m+[m
const projects:Project[] = [][m
for (let i = 0; i < 5; i++) {[m
const newProject = new Project();[m
newProject.title = `Project ${faker.random.words(1)}`;[m
newProject.color = faker.random.words(1);[m
[31m- newProject.admin = faker.helpers.arrayElement(users);[m
[32m+[m[32m newProject.members = faker.helpers.arrayElements(members,randomIntFromInterval(1, 3))[m
[32m+[m[32m // newProject.admin = faker.helpers.arrayElement(users);[m
newProject.tasks= faker.helpers.arrayElements(tasks, randomIntFromInterval(1, 3));[m
[31m- newProject.workers = faker.helpers.arrayElements(users, randomIntFromInterval(1, 3));[m
[32m+[m[32m // newProject.workers = faker.helpers.arrayElements(users, randomIntFromInterval(1, 3));[m
await newProject.save();[m
projects.push(newProject)[m
}[m
[1mdiff --git a/planner-api/src/models/Member.ts b/planner-api/src/models/Member.ts[m
[1mindex 37bb23c..9bd0a66 100644[m
[1m--- a/planner-api/src/models/Member.ts[m
[1m+++ b/planner-api/src/models/Member.ts[m
[36m@@ -37,7 +37,7 @@[m [mimport {[m
@ManyToOne(() => User, (user: { members: Member[]; }) => user.members,{cascade: true, onUpdate:'CASCADE'})[m
user!: User;[m
[m
[31m- @ManyToOne(() => Project, (project: { members: Member[]; }) => project.members,{cascade: true, onUpdate:'CASCADE'})[m
[32m+[m[32m @ManyToOne(() => Project, (project: { members: Member[]; }) => project.members,{cascade: true, onUpdate:'CASCADE',nullable:true})[m
project!: Project;[m
[m
@Column({[m
[1mdiff --git a/planner-api/src/models/Task.ts b/planner-api/src/models/Task.ts[m
[1mindex a5e9f83..c8a1650 100644[m
[1m--- a/planner-api/src/models/Task.ts[m
[1m+++ b/planner-api/src/models/Task.ts[m
[36m@@ -5,7 +5,7 @@[m [mimport {[m
CreateDateColumn,[m
BaseEntity,[m
ManyToOne,[m
[31m- ManyToMany,[m
[32m+[m[32m OneToOne,[m
JoinTable[m
} from 'typeorm';[m
import {User} from './User';[m
[36m@@ -25,7 +25,7 @@[m [mimport {[m
priority: priorityType | null;[m
author: User;[m
project:Project|null;[m
[31m- executors:User[];[m
[32m+[m[32m executor:User;[m
}[m
[m
@Entity({ name: 'Task' })[m
[36m@@ -64,9 +64,9 @@[m [mimport {[m
@ManyToOne(() => User, (user: { tasks: Task[]; }) => user.tasks,{eager : true})[m
author!: User;[m
[m
[31m- @ManyToMany(() => User,{eager : true, cascade: true, onUpdate:'CASCADE'})[m
[32m+[m[32m @ManyToOne(() =>User, (user: { tasks: Task[]}) => user.tasks,{eager : true,nullable: true, onUpdate:'CASCADE'})[m
@JoinTable()[m
[31m- executors!: User[];[m
[32m+[m[32m executor!: User;[m
[m
@ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks,{eager : true,nullable: true,onUpdate:'CASCADE'})[m
project!: Project;[m
[1mdiff --git a/planner-api/src/models/User.ts b/planner-api/src/models/User.ts[m
[1mindex 9b967fe..855ee37 100644[m
[1m--- a/planner-api/src/models/User.ts[m
[1m+++ b/planner-api/src/models/User.ts[m
[36m@@ -8,6 +8,7 @@[m [mimport {[m
ManyToMany,[m
OneToMany,[m
JoinTable,[m
[32m+[m[32m OneToOne,[m
} from 'typeorm';[m
import {IsEmail[m
} from "class-validator";[m
[36m@@ -82,7 +83,7 @@[m [mexport class User extends BaseEntity implements IUser {[m
@OneToMany(() => Task, (task: { user: User }) => task.user)[m
createdTasks!: Task[];[m
[m
[31m- @ManyToMany(() => Task, (task: { users: User[] }) =>task.users)[m
[32m+[m[32m @OneToMany(() => Task, (task: { user: User }) =>task.user)[m
tasks!: Task[];[m
[m
[m
[1mdiff --git a/planner-api/src/routers/projects.ts b/planner-api/src/routers/projects.ts[m
[1mindex bea1f3a..0cfa624 100644[m
[1m--- a/planner-api/src/routers/projects.ts[m
[1m+++ b/planner-api/src/routers/projects.ts[m
[36m@@ -29,10 +29,10 @@[m [mrouter.post('/', async (req:Request, res:Response): Promise<Response> => {[m
project.title = title;[m
project.color = color; [m
project.dateDue = dateDue || null;[m
[31m- project.department = department;[m
[31m- project.workers = workers|| null;[m
[32m+[m[32m // project.department = department;[m
[32m+[m[32m // project.workers = workers|| null;[m
project.tasks = tasks || null;[m
[31m- project.admin = user;[m
[32m+[m[32m // project.admin = user;[m
await project.save()[m
return res.send({project})[m
})[m
[1mdiff --git a/planner-api/src/routers/tasks.ts b/planner-api/src/routers/tasks.ts[m
[1mindex 7d70d2c..b51ae60 100644[m
[1m--- a/planner-api/src/routers/tasks.ts[m
[1m+++ b/planner-api/src/routers/tasks.ts[m
[36m@@ -3,6 +3,7 @@[m [mimport {Task} from '../models/Task';[m
import {myDataSource} from '../app-data-source';[m
import { User } from '../models/User';[m
import { Project } from '../models/Project';[m
[32m+[m[32mimport { Member } from '../models/Member';[m
const router:Router = express.Router();[m
const dataSource = myDataSource;[m
[m
[36m@@ -28,7 +29,7 @@[m [mrouter.post('/', async(req:Request, res:Response):Promise<Response>=>{[m
newTask.title = title;[m
newTask.description = description;[m
newTask.project = project;[m
[31m- newTask.executors = executors;[m
[32m+[m[32m // newTask.executors = executors;[m
newTask.dateTimeDue = dateTimeDue;[m
newTask.dateTimeStart = dateTimeStart;[m
newTask.author= user;[m
[36m@@ -38,13 +39,23 @@[m [mrouter.post('/', async(req:Request, res:Response):Promise<Response>=>{[m
return res.send({newTask})[m
})[m
[m
[31m-router.get('/:userId', async (req: Request, res: Response):Promise<Response>=>{ [m
[32m+[m[32mrouter.get('/user/:userId', async (req: Request, res: Response):Promise<Response>=>{[m[41m [m
const userId = req.params.userId;[m
[32m+[m[32m // const tasks = await dataSource[m
[32m+[m[32m // .getRepository(Task)[m
[32m+[m[32m // .createQueryBuilder('task')[m
[32m+[m[32m // .innerJoinAndSelect('task.executors', 'user')[m
[32m+[m[32m // .where('user.id = :userId', {userId :userId})[m
[32m+[m[32m // .getMany()[m
[32m+[m[32m // return res.send({tasks})[m
const tasks = await dataSource[m
[31m- .getRepository(Task)[m
[31m- .createQueryBuilder('task')[m
[31m- .innerJoinAndSelect('task.executors', 'user')[m
[31m- .where('user.id = :userId', {userId :userId})[m
[32m+[m[32m .getRepository(Member)[m
[32m+[m[32m .createQueryBuilder('member')[m
[32m+[m[32m .innerJoinAndSelect('member.project','project')[m
[32m+[m[32m .innerJoinAndSelect('project.tasks','task')[m
[32m+[m[32m .where('member.user.id = :userId')[m
[32m+[m[32m .andWhere('member.project.id= task.project.id')[m
[32m+[m[32m .select('task.*')[m
.getMany()[m
return res.send({tasks})[m
})[m
[36m@@ -104,7 +115,7 @@[m [mrouter.put('/',async(req:Request, res:Response)=> {[m
task.dateTimeDue= dateTimeDue[m
task.dateTimeStart= dateTimeStart[m
task.author=user[m
[31m- task.executors=executors[m
[32m+[m[32m // task.executors=executors[m
task.accomplish= accomplish[m
task.priority= priority [m
await task.save()[m
[36m@@ -121,7 +132,7 @@[m [mrouter.post('/project',async (req: Request, res: Response):Promise<Response>=>{[m
.getRepository(Task)[m
.find({[m
relations:{[m
[31m- executors:true,[m
[32m+[m[32m // executors:true,[m
author:true,[m
project:true[m
}[m
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