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
99d6d937
Commit
99d6d937
authored
Nov 22, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'task-58-enhance/model_Member' into 'development'
Task 58 enhance/model member See merge request
!38
parents
cf98dee7
50f4e782
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
211 additions
and
84 deletions
+211
-84
app-data-source.ts
planner-api/src/app-data-source.ts
+2
-1
fixtures.ts
planner-api/src/fixtures.ts
+21
-6
Member.ts
planner-api/src/models/Member.ts
+50
-0
Project.ts
planner-api/src/models/Project.ts
+26
-17
Task.ts
planner-api/src/models/Task.ts
+12
-6
User.ts
planner-api/src/models/User.ts
+11
-8
projects.ts
planner-api/src/routers/projects.ts
+44
-11
tasks.ts
planner-api/src/routers/tasks.ts
+45
-35
No files found.
planner-api/src/app-data-source.ts
View file @
99d6d937
...
@@ -2,6 +2,7 @@ import { DataSource } from "typeorm";
...
@@ -2,6 +2,7 @@ import { DataSource } from "typeorm";
import
{
User
}
from
'./models/User'
;
import
{
User
}
from
'./models/User'
;
import
{
Task
}
from
'./models/Task'
;
import
{
Task
}
from
'./models/Task'
;
import
{
Project
}
from
"./models/Project"
;
import
{
Project
}
from
"./models/Project"
;
import
{
Member
}
from
"./models/Member"
;
export
const
myDataSource
=
new
DataSource
({
export
const
myDataSource
=
new
DataSource
({
type
:
"postgres"
,
type
:
"postgres"
,
...
@@ -10,7 +11,7 @@ export const myDataSource = new DataSource({
...
@@ -10,7 +11,7 @@ export const myDataSource = new DataSource({
username
:
"pluser"
,
username
:
"pluser"
,
password
:
"pluser"
,
password
:
"pluser"
,
database
:
"planner"
,
database
:
"planner"
,
entities
:
[
User
,
Task
,
Project
],
entities
:
[
User
,
Task
,
Project
,
Member
],
logging
:
true
,
logging
:
true
,
synchronize
:
true
,
// in build switch to false
synchronize
:
true
,
// in build switch to false
migrationsRun
:
false
migrationsRun
:
false
...
...
planner-api/src/fixtures.ts
View file @
99d6d937
...
@@ -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
)
...
@@ -13,6 +14,8 @@ const loadFixtures = async () => {
...
@@ -13,6 +14,8 @@ const loadFixtures = async () => {
myDataSource
myDataSource
.
initialize
()
.
initialize
()
.
then
(
async
()
=>
{
.
then
(
async
()
=>
{
const
repositoryMember
=
myDataSource
.
getRepository
(
Member
);
await
repositoryMember
.
delete
({})
const
repositoryTask
=
myDataSource
.
getRepository
(
Task
);
const
repositoryTask
=
myDataSource
.
getRepository
(
Task
);
await
repositoryTask
.
delete
({});
await
repositoryTask
.
delete
({});
const
repositoryProject
=
myDataSource
.
getRepository
(
Project
);
const
repositoryProject
=
myDataSource
.
getRepository
(
Project
);
...
@@ -50,9 +53,11 @@ const loadFixtures = async () => {
...
@@ -50,9 +53,11 @@ 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
.
dateTimeDeadLine
=
faker
.
date
.
soon
(
randomIntFromInterval
(
1
,
15
));
newTask
.
dateTimeFactDeadLine
=
faker
.
date
.
soon
(
randomIntFromInterval
(
1
,
15
));
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
accomplish
=
faker
.
helpers
.
arrayElement
(
accomplish
);
newTask
.
accomplish
=
faker
.
helpers
.
arrayElement
(
accomplish
);
newTask
.
priority
=
faker
.
helpers
.
arrayElement
(
priorities
);
newTask
.
priority
=
faker
.
helpers
.
arrayElement
(
priorities
);
...
@@ -62,9 +67,9 @@ const loadFixtures = async () => {
...
@@ -62,9 +67,9 @@ 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
);
newTask
.
accomplish
=
accomplish
[
0
];
newTask
.
accomplish
=
accomplish
[
0
];
newTask
.
priority
=
faker
.
helpers
.
arrayElement
(
priorities
);
newTask
.
priority
=
faker
.
helpers
.
arrayElement
(
priorities
);
...
@@ -73,14 +78,24 @@ const loadFixtures = async () => {
...
@@ -73,14 +78,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
.
roleProject
=
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
0 → 100644
View file @
99d6d937
import
{
Column
,
Entity
,
PrimaryGeneratedColumn
,
CreateDateColumn
,
BaseEntity
,
ManyToOne
,
ManyToMany
,
OneToMany
,
JoinTable
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
import
{
Project
}
from
'./Project'
;
import
{
Task
}
from
'./Task'
;
export
enum
MemberRole
{
USER
=
"user"
,
WATCHER
=
"watcher"
,
ADMIN
=
"admin"
}
interface
IMember
{
id
:
string
;
user
:
User
;
project
:
Project
;
createdAt
:
Date
;
roleProject
:
MemberRole
;
}
@
Entity
({
name
:
"Member"
})
export
class
Member
extends
BaseEntity
implements
IMember
{
@
PrimaryGeneratedColumn
(
"uuid"
)
id
!
:
string
;
@
CreateDateColumn
({
name
:
'createdAt'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
@
ManyToOne
(()
=>
User
,
(
user
:
{
members
:
Member
[];
})
=>
user
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
,
eager
:
true
})
user
!
:
User
;
@
ManyToOne
(()
=>
Project
,
(
project
:
{
members
:
Member
[];
})
=>
project
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
,
nullable
:
true
})
project
!
:
Project
;
@
Column
({
type
:
"enum"
,
enum
:
MemberRole
,
default
:
MemberRole
.
USER
})
roleProject
!
:
MemberRole
}
\ No newline at end of file
planner-api/src/models/Project.ts
View file @
99d6d937
...
@@ -9,8 +9,9 @@ import {
...
@@ -9,8 +9,9 @@ import {
OneToMany
,
OneToMany
,
JoinTable
JoinTable
}
from
'typeorm'
;
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
//
import {User} from './User';
import
{
Task
}
from
'./Task'
;
import
{
Task
}
from
'./Task'
;
import
{
Member
}
from
'./Member'
;
...
@@ -18,12 +19,14 @@ import {
...
@@ -18,12 +19,14 @@ import {
id
:
string
;
id
:
string
;
title
:
string
;
title
:
string
;
color
:
string
;
color
:
string
;
admin
:
User
;
//
admin:User;
workers
:
User
[];
//
workers:User[];
tasks
:
Task
[]
|
null
;
tasks
:
Task
[]
|
null
;
createdAt
:
Date
;
createdAt
:
Date
;
dateDue
:
Date
|
null
;
active
:
boolean
;
department
:
boolean
;
// dateDue: Date| null;
// department:boolean;
members
:
Member
[];
}
}
@
Entity
({
name
:
'Project'
})
@
Entity
({
name
:
'Project'
})
...
@@ -39,21 +42,27 @@ import {
...
@@ -39,21 +42,27 @@ import {
createdAt
!
:
Date
;
createdAt
!
:
Date
;
@
Column
({
name
:
'color'
,
type
:
'varchar'
,
length
:
100
,
nullable
:
true
})
@
Column
({
name
:
'color'
,
type
:
'varchar'
,
length
:
100
,
nullable
:
true
})
color
!
:
string
color
!
:
string
;
@
Column
({
name
:
'
dateDue'
,
type
:
Date
,
default
:
null
})
@
Column
({
name
:
'
active'
,
type
:
'boolean'
,
default
:
true
})
dateDue
!
:
Date
|
null
;
active
!
:
boolean
;
@
Column
({
name
:
'department'
,
type
:
Boolean
,
nullable
:
true
,
default
:
false
})
// @Column({ name: 'dateDue', type: Date, default: null
})
department
!
:
boolean
;
// dateDue!: Date| null
;
@
ManyToOne
(()
=>
User
,
(
user
:
{
projects
:
Project
[];
})
=>
user
.
projects
,{
eager
:
true
})
// @Column({ name: 'department', type: Boolean,nullable:true ,default: false})
admin
!
:
User
;
// department!: boolean;
// @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
// admin!: User;
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
)
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
,{
nullable
:
true
})
tasks
!
:
Task
[]
|
null
;
tasks
!
:
Task
[];
@
OneToMany
(()
=>
Member
,
(
member
:
{
project
:
Project
;
})
=>
member
.
project
)
members
!
:
Member
[];
@
ManyToMany
(()
=>
User
,
(
user
:
{
projects
:
Project
[];
})
=>
user
.
projects
,{
eager
:
true
,
cascade
:
true
,
onUpdate
:
'CASCADE'
,
onDelete
:
'CASCADE'
})
//
@ManyToMany(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true,cascade: true, onUpdate:'CASCADE',onDelete: 'CASCADE'})
@
JoinTable
()
//
@JoinTable()
workers
!
:
User
[];
//
workers!: User[];
}
}
\ No newline at end of file
planner-api/src/models/Task.ts
View file @
99d6d937
...
@@ -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'
;
...
@@ -21,11 +21,13 @@ import {
...
@@ -21,11 +21,13 @@ import {
createdAt
:
Date
;
createdAt
:
Date
;
dateTimeStart
:
Date
|
null
;
dateTimeStart
:
Date
|
null
;
dateTimeDue
:
Date
|
null
;
dateTimeDue
:
Date
|
null
;
dateTimeDeadLine
:
Date
|
null
;
dateTimeFactDeadLine
:
Date
|
null
;
accomplish
:
taskFinishType
;
accomplish
:
taskFinishType
;
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'
})
...
@@ -39,9 +41,13 @@ import {
...
@@ -39,9 +41,13 @@ import {
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
createdAt
!
:
Date
;
@
Column
({
name
:
'dateTimeStart'
,
type
:
Date
,
nullable
:
true
})
@
Column
({
name
:
'dateTimeStart'
,
type
:
Date
,
nullable
:
true
})
dateTimeStart
!
:
Date
|
null
;
dateTimeStart
!
:
Date
;
@
Column
({
name
:
'dateTimeDue'
,
type
:
Date
,
nullable
:
true
})
@
Column
({
name
:
'dateTimeDue'
,
type
:
Date
,
nullable
:
true
})
dateTimeDue
!
:
Date
|
null
;
dateTimeDue
!
:
Date
;
@
Column
({
name
:
'dateTimeDeadLine'
,
type
:
Date
,
nullable
:
true
})
dateTimeDeadLine
!
:
Date
;
@
Column
({
name
:
'dateTimeFactDeadLine'
,
type
:
Date
,
nullable
:
true
})
dateTimeFactDeadLine
!
:
Date
;
@
Column
({
@
Column
({
type
:
"enum"
,
type
:
"enum"
,
...
@@ -64,9 +70,9 @@ import {
...
@@ -64,9 +70,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 @
99d6d937
...
@@ -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"
;
...
@@ -16,6 +17,7 @@ import bcrypt from 'bcrypt';
...
@@ -16,6 +17,7 @@ import bcrypt from 'bcrypt';
import
{
nanoid
}
from
'nanoid'
;
import
{
nanoid
}
from
'nanoid'
;
import
{
Task
}
from
'./Task'
;
import
{
Task
}
from
'./Task'
;
import
{
Project
}
from
'./Project'
;
import
{
Project
}
from
'./Project'
;
import
{
Member
}
from
'./Member'
;
const
SALT_WORK_FACTOR
=
10
;
const
SALT_WORK_FACTOR
=
10
;
...
@@ -33,8 +35,9 @@ interface IUser {
...
@@ -33,8 +35,9 @@ interface IUser {
token
:
string
;
token
:
string
;
createdAt
:
Date
;
createdAt
:
Date
;
createdTasks
:
Task
[];
createdTasks
:
Task
[];
workerInProjects
:
Project
[];
// workerInProjects:Project[];
adminInProjects
:
Project
[];
// adminInProjects:Project[];
membership
:
Member
[];
}
}
...
@@ -80,16 +83,16 @@ export class User extends BaseEntity implements IUser {
...
@@ -80,16 +83,16 @@ 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
[];
@
OneToMany
(()
=>
Project
,
(
project
:
{
user
:
User
})
=>
project
.
user
)
@
OneToMany
(()
=>
Member
,
(
member
:
{
user
:
User
})
=>
member
.
user
)
adminInProjects
!
:
Project
[];
membership
!
:
Member
[];
@
ManyToMany
(()
=>
Project
,(
project
:
{
user
:
User
})
=>
project
.
user
)
//
@ManyToMany(() => Project,(project: { user: User }) => project.user)
@
JoinTable
()
//
@JoinTable()
workerInProjects
!
:
Project
[];
//
workerInProjects!: Project[];
@
BeforeInsert
()
@
BeforeInsert
()
...
...
planner-api/src/routers/projects.ts
View file @
99d6d937
...
@@ -2,6 +2,10 @@ import express,{Router, Request, Response} from 'express';
...
@@ -2,6 +2,10 @@ import express,{Router, Request, Response} from 'express';
import
{
Project
}
from
'../models/Project'
;
import
{
Project
}
from
'../models/Project'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
User
}
from
'../models/User'
;
import
{
User
}
from
'../models/User'
;
import
{
Member
,
MemberRole
}
from
'../models/Member'
;
import
{
userInfo
}
from
'os'
;
import
{
Task
}
from
'../models/Task'
;
import
{
getRepository
}
from
'typeorm'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
...
@@ -12,27 +16,40 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
...
@@ -12,27 +16,40 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
return
res
.
send
({
projects
})
return
res
.
send
({
projects
})
})
})
router
.
get
(
'/my'
,
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
projects
:
Project
[]
=
await
dataSource
.
manager
.
find
(
Project
)
return
res
.
send
({
projects
})
})
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
token
=
req
.
get
(
'Authorization'
);
const
token
=
req
.
get
(
'Authorization'
);
console
.
log
(
"token:"
+
token
)
const
{
title
,
color
}
=
req
.
body
;
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.token = :token"
,
{
token
:
token
})
.
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
member
:
Member
=
new
Member
;
member
.
user
=
user
;
member
.
roleProject
=
MemberRole
.
ADMIN
;
await
member
.
save
();
const
project
:
Project
=
new
Project
()
const
project
:
Project
=
new
Project
()
project
.
title
=
title
;
project
.
title
=
title
;
project
.
color
=
color
;
project
.
color
=
color
;
project
.
dateDue
=
dateDue
||
null
;
project
.
members
=
[
member
]
project
.
department
=
department
;
project
.
workers
=
workers
||
null
;
project
.
tasks
=
tasks
||
null
;
project
.
admin
=
user
;
await
project
.
save
()
await
project
.
save
()
return
res
.
send
({
project
})
return
res
.
send
({
project
})
})
})
...
@@ -42,14 +59,30 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
...
@@ -42,14 +59,30 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
"project"
)
.
select
(
"project"
)
.
from
(
Project
,
"project"
)
.
from
(
Project
,
"project"
)
.
leftJoinAndSelect
(
'project.admin'
,
'user'
)
.
leftJoinAndSelect
(
'project.members'
,
'member'
)
.
leftJoinAndSelect
(
'member.user'
,
'user'
)
.
where
(
"project.id = :id"
,
{
id
:
req
.
params
.
id
})
.
where
(
"project.id = :id"
,
{
id
:
req
.
params
.
id
})
.
getOne
()
.
getOne
()
if
(
!
project
)
return
res
.
status
(
404
).
send
({
Message
:
'no info on this project'
})
if
(
!
project
)
return
res
.
status
(
404
).
send
({
Message
:
'no info on this project'
})
return
res
.
send
({
project
})
const
tasks
=
await
dataSource
.
getRepository
(
'Task'
)
.
find
(
{
relations
:{
executor
:
true
,
author
:
true
,
},
where
:{
project
:{
id
:
req
.
params
.
id
}
}
}
)
return
res
.
send
({
project
,
tasks
})
})
})
router
.
get
(
'/userId/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
get
(
'/user/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
userId
:
string
=
req
.
params
.
userId
const
userId
:
string
=
req
.
params
.
userId
const
userProjects
=
await
dataSource
const
userProjects
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
...
...
planner-api/src/routers/tasks.ts
View file @
99d6d937
...
@@ -2,7 +2,6 @@ import express,{Router, Request, Response} from 'express';
...
@@ -2,7 +2,6 @@ import express,{Router, Request, Response} from 'express';
import
{
Task
}
from
'../models/Task'
;
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'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
...
@@ -10,14 +9,18 @@ const dataSource = myDataSource;
...
@@ -10,14 +9,18 @@ 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
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
getRepository
(
Task
)
.
find
()
.
find
({
relations
:{
executor
:
true
,
author
:
true
,
}})
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
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
,
priority
}
=
req
.
body
;
const
{
title
,
description
,
project
,
dateTimeDue
,
dateTimeStart
,
accomplish
,
priority
}
=
req
.
body
;
const
user
=
await
dataSource
const
user
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
"user"
)
.
select
(
"user"
)
...
@@ -28,7 +31,6 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
...
@@ -28,7 +31,6 @@ 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
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
author
=
user
;
newTask
.
author
=
user
;
...
@@ -38,14 +40,28 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
...
@@ -38,14 +40,28 @@ 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
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
getRepository
(
Task
)
.
createQueryBuilder
(
'task'
)
.
find
({
.
innerJoinAndSelect
(
'task.executors'
,
'user'
)
relations
:{
.
where
(
'user.id = :userId'
,
{
userId
:
userId
})
executor
:
true
,
.
getMany
()
author
:
true
,
},
where
:[
{
executor
:{
id
:
userId
}
},
{
author
:{
id
:
userId
}
},
]
})
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
...
@@ -60,10 +76,24 @@ router.get('/my', async (req: Request, res: Response):Promise<Response>=>{
...
@@ -60,10 +76,24 @@ router.get('/my', async (req: Request, res: Response):Promise<Response>=>{
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
const
tasks
=
await
dataSource
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
getRepository
(
Task
)
.
createQueryBuilder
(
'task'
)
.
find
({
.
innerJoinAndSelect
(
'task.executors'
,
'user'
)
relations
:{
.
where
(
'user.id = :userId'
,
{
userId
:
user
.
id
})
executor
:
true
,
.
getMany
()
author
:
true
,
},
where
:[
{
executor
:{
id
:
user
.
id
}
},
{
author
:{
id
:
user
.
id
}
},
]
})
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
...
@@ -104,7 +134,7 @@ router.put('/',async(req:Request, res:Response)=> {
...
@@ -104,7 +134,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 +151,7 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
...
@@ -121,7 +151,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
}
}
...
@@ -141,24 +171,4 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
...
@@ -141,24 +171,4 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
// router.post('/projects',async (req: Request, res: Response):Promise<Response>=>{
// let projectArray :string[]= req.body;
// console.log('projectArray ', projectArray)
// if (projectArray.length===0) {
// const tasks = await
// dataSource
// .getRepository(Task)
// .createQueryBuilder('task')
// // .innerJoinAndSelect('task.executors', 'user')
// .innerJoinAndSelect('task.executors AND task.author', 'user')
// .where('task.project IS NULL')
// .getMany()
// return res.send({tasks})
// }
// ///ssome code
// return res.send({message:"some other staff"})
// })
export
default
router
;
export
default
router
;
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