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
60ef321f
Commit
60ef321f
authored
Nov 22, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#58
added model Member and related fields in related models
parent
6a213935
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
19 deletions
+77
-19
app-data-source.ts
planner-api/src/app-data-source.ts
+2
-1
Member.ts
planner-api/src/models/Member.ts
+50
-0
Project.ts
planner-api/src/models/Project.ts
+16
-11
User.ts
planner-api/src/models/User.ts
+9
-7
No files found.
planner-api/src/app-data-source.ts
View file @
60ef321f
...
@@ -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/models/Member.ts
0 → 100644
View file @
60ef321f
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
;
role
:
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'
})
user
!
:
User
;
@
ManyToOne
(()
=>
Project
,
(
project
:
{
members
:
Member
[];
})
=>
project
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
})
project
!
:
Project
;
@
Column
({
type
:
"enum"
,
enum
:
MemberRole
,
default
:
MemberRole
.
ADMIN
})
role
!
:
MemberRole
}
\ No newline at end of file
planner-api/src/models/Project.ts
View file @
60ef321f
...
@@ -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,13 @@ import {
...
@@ -18,12 +19,13 @@ 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
;
dateDue
:
Date
|
null
;
department
:
boolean
;
// department:boolean;
members
:
Member
[];
}
}
@
Entity
({
name
:
'Project'
})
@
Entity
({
name
:
'Project'
})
...
@@ -44,16 +46,19 @@ import {
...
@@ -44,16 +46,19 @@ import {
@
Column
({
name
:
'dateDue'
,
type
:
Date
,
default
:
null
})
@
Column
({
name
:
'dateDue'
,
type
:
Date
,
default
:
null
})
dateDue
!
:
Date
|
null
;
dateDue
!
:
Date
|
null
;
@
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
,{
eager
:
true
})
//
@ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
admin
!
:
User
;
//
admin!: User;
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
)
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
)
tasks
!
:
Task
[]
|
null
;
tasks
!
:
Task
[]
|
null
;
@
ManyToMany
(()
=>
User
,
(
user
:
{
projects
:
Project
[];
})
=>
user
.
projects
,{
eager
:
true
,
cascade
:
true
,
onUpdate
:
'CASCADE'
,
onDelete
:
'CASCADE'
})
@
OneToMany
(()
=>
Member
,
(
member
:
{
project
:
Project
;
})
=>
member
.
project
)
@
JoinTable
()
members
!
:
Member
[];
workers
!
:
User
[];
// @ManyToMany(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true,cascade: true, onUpdate:'CASCADE',onDelete: 'CASCADE'})
// @JoinTable()
// workers!: User[];
}
}
\ No newline at end of file
planner-api/src/models/User.ts
View file @
60ef321f
...
@@ -16,6 +16,7 @@ import bcrypt from 'bcrypt';
...
@@ -16,6 +16,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 +34,9 @@ interface IUser {
...
@@ -33,8 +34,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
[];
}
}
...
@@ -84,12 +86,12 @@ export class User extends BaseEntity implements IUser {
...
@@ -84,12 +86,12 @@ export class User extends BaseEntity implements IUser {
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
()
...
...
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