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
296994dc
Commit
296994dc
authored
Nov 28, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#69
create new personal project while create new user
parent
3d1e05fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
21 deletions
+16
-21
Project.ts
planner-api/src/models/Project.ts
+1
-17
User.ts
planner-api/src/models/User.ts
+0
-1
users.ts
planner-api/src/routers/users.ts
+15
-3
No files found.
planner-api/src/models/Project.ts
View file @
296994dc
...
@@ -19,13 +19,9 @@ import {
...
@@ -19,13 +19,9 @@ import {
id
:
string
;
id
:
string
;
title
:
string
;
title
:
string
;
color
:
string
;
color
:
string
;
// admin:User;
// workers:User[];
tasks
:
Task
[]
|
null
;
tasks
:
Task
[]
|
null
;
createdAt
:
Date
;
createdAt
:
Date
;
active
:
boolean
;
active
:
boolean
;
// dateDue: Date| null;
// department:boolean;
members
:
Member
[];
members
:
Member
[];
}
}
...
@@ -47,22 +43,10 @@ import {
...
@@ -47,22 +43,10 @@ import {
@
Column
({
name
:
'active'
,
type
:
'boolean'
,
default
:
true
})
@
Column
({
name
:
'active'
,
type
:
'boolean'
,
default
:
true
})
active
!
:
boolean
;
active
!
:
boolean
;
// @Column({ name: 'dateDue', type: Date, default: null })
// dateDue!: Date| null;
// @Column({ name: 'department', type: Boolean,nullable:true ,default: false})
// department!: boolean;
// @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
// admin!: User;
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
,{
nullable
:
true
})
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
,{
nullable
:
true
})
tasks
!
:
Task
[];
tasks
!
:
Task
[];
@
OneToMany
(()
=>
Member
,
(
member
:
{
project
:
Project
;
})
=>
member
.
project
)
@
OneToMany
(()
=>
Member
,
(
member
:
{
project
:
Project
;
})
=>
member
.
project
)
members
!
:
Member
[];
members
!
:
Member
[];
// @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 @
296994dc
...
@@ -16,7 +16,6 @@ import { Exclude, instanceToPlain } from "class-transformer";
...
@@ -16,7 +16,6 @@ import { Exclude, instanceToPlain } from "class-transformer";
import
bcrypt
from
'bcrypt'
;
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
{
Member
}
from
'./Member'
;
import
{
Member
}
from
'./Member'
;
const
SALT_WORK_FACTOR
=
10
;
const
SALT_WORK_FACTOR
=
10
;
...
...
planner-api/src/routers/users.ts
View file @
296994dc
...
@@ -5,6 +5,8 @@ import { nanoid } from 'nanoid';
...
@@ -5,6 +5,8 @@ import { nanoid } from 'nanoid';
import
multer
from
'multer'
;
import
multer
from
'multer'
;
import
path
from
'path'
;
import
path
from
'path'
;
import
{
config
}
from
"../config"
import
{
config
}
from
"../config"
import
{
Project
}
from
'../models/Project'
;
import
{
Member
,
MemberRole
}
from
'../models/Member'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
...
@@ -24,7 +26,7 @@ const storage = multer.diskStorage({
...
@@ -24,7 +26,7 @@ const storage = multer.diskStorage({
const
upload
=
multer
({
storage
})
const
upload
=
multer
({
storage
})
//** return all users of DB */
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
const
users
=
await
dataSource
const
users
=
await
dataSource
.
getRepository
(
User
)
.
getRepository
(
User
)
...
@@ -33,7 +35,7 @@ const users = await dataSource
...
@@ -33,7 +35,7 @@ const users = await dataSource
return
res
.
send
({
users
})
return
res
.
send
({
users
})
})
})
/**create new user*/
router
.
post
(
'/'
,
upload
.
single
(
"avatar"
),
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
router
.
post
(
'/'
,
upload
.
single
(
"avatar"
),
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
const
{
name
,
surname
,
password
,
email
,
role
}
=
req
.
body
;
const
{
name
,
surname
,
password
,
email
,
role
}
=
req
.
body
;
const
displayName
=
surname
+
' '
+
name
[
0
]
+
'.'
const
displayName
=
surname
+
' '
+
name
[
0
]
+
'.'
...
@@ -44,8 +46,18 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response):
...
@@ -44,8 +46,18 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response):
user
.
displayName
=
displayName
;
user
.
displayName
=
displayName
;
user
.
email
=
email
;
user
.
email
=
email
;
user
.
role
=
role
;
user
.
role
=
role
;
user
.
generateToken
()
user
.
generateToken
()
;
await
user
.
save
();
await
user
.
save
();
const
newProject
=
new
Project
();
newProject
.
title
=
'Личные дела'
;
newProject
.
color
=
'Green'
;
await
newProject
.
save
()
const
newMember
=
new
Member
();
newMember
.
user
=
user
;
newMember
.
project
=
newProject
;
newMember
.
roleProject
=
MemberRole
.
ADMIN
;
await
newMember
.
save
();
const
userToFront
:
User
|
null
=
await
dataSource
.
manager
.
findOneBy
(
User
,
{
const
userToFront
:
User
|
null
=
await
dataSource
.
manager
.
findOneBy
(
User
,
{
email
:
user
.
email
email
:
user
.
email
})
})
...
...
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