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
4d9e7864
Commit
4d9e7864
authored
Nov 02, 2022
by
“Yevgeniy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Task model and relations
parent
9678e654
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
20 deletions
+96
-20
app-data-source.ts
planner-api/src/app-data-source.ts
+4
-3
Task.ts
planner-api/src/models/Task.ts
+54
-0
User.ts
planner-api/src/models/User.ts
+38
-17
No files found.
planner-api/src/app-data-source.ts
View file @
4d9e7864
import
{
DataSource
}
from
"typeorm"
;
import
{
DataSource
}
from
"typeorm"
;
import
{
User
}
from
'./models/User'
;
import
{
User
}
from
'./models/User'
;
import
{
Task
}
from
'./models/Task'
;
export
const
myDataSource
=
new
DataSource
({
export
const
myDataSource
=
new
DataSource
({
type
:
"postgres"
,
type
:
"postgres"
,
...
@@ -8,8 +9,8 @@ export const myDataSource = new DataSource({
...
@@ -8,8 +9,8 @@ export const myDataSource = new DataSource({
username
:
"pluser"
,
username
:
"pluser"
,
password
:
"pluser"
,
password
:
"pluser"
,
database
:
"planner"
,
database
:
"planner"
,
// entities: ["./models/*.ts"],
entities
:
[
User
,
Task
],
entities
:
[
User
],
logging
:
true
,
logging
:
true
,
synchronize
:
true
,
synchronize
:
true
,
// in build switch to false
migrationsRun
:
false
})
})
\ No newline at end of file
planner-api/src/models/Task.ts
0 → 100644
View file @
4d9e7864
import
{
Column
,
Entity
,
PrimaryGeneratedColumn
,
CreateDateColumn
,
BaseEntity
,
ManyToOne
,
ManyToMany
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
type
taskFinishType
=
"open"
|
"done"
|
"failed"
;
interface
ITask
{
id
:
string
;
title
:
string
;
// description: string;
createdAt
:
Date
|
undefined
;
// dateTimeStart:Date| null;
// dateTimeDue:Date| null;
assignedTo
:
User
[];
accomplish
:
taskFinishType
;
author
:
User
;
}
@
Entity
({
name
:
'Task'
})
export
class
Task
extends
BaseEntity
implements
ITask
{
@
PrimaryGeneratedColumn
(
'uuid'
)
id
!
:
string
@
Column
({
name
:
'title'
,
type
:
'varchar'
,
length
:
50
,
nullable
:
false
})
title
!
:
string
// @Column({ name: 'description', type: 'varchar', length:50,nullable: false })
// description!: string
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
:
Date
|
undefined
;
// @CreateDateColumn({ name: 'dateTimeStart', type: Date,nullable: true })
// dateTimeStart!: Date | null;
// @CreateDateColumn({ name: 'dateTimeDue', type: Date,nullable: true })
// dateTimeDue!: Date | null;
@
Column
({
type
:
"enum"
,
enum
:
[
"opened"
,
"done"
,
"failed"
],
default
:
"opened"
})
accomplish
!
:
taskFinishType
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
)
author
!
:
User
;
@
ManyToMany
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
)
assignedTo
!
:
User
[];
}
planner-api/src/models/User.ts
View file @
4d9e7864
...
@@ -6,17 +6,18 @@ import {
...
@@ -6,17 +6,18 @@ import {
BeforeInsert
,
BeforeInsert
,
BeforeUpdate
,
BeforeUpdate
,
BaseEntity
,
BaseEntity
,
ManyToOne
ManyToMany
,
OneToMany
}
from
'typeorm'
;
}
from
'typeorm'
;
import
bcrypt
from
'bcrypt'
;
import
bcrypt
from
'bcrypt'
;
import
{
nanoid
}
from
'nanoid'
;
import
{
Task
}
from
'./Task'
;
const
SALT_WORK_FACTOR
=
10
;
const
SALT_WORK_FACTOR
=
10
;
// enum UserRole {
// DIRECTOR = "director",
type
userRoleType
=
"worker"
|
"director"
;
// WORKER = "worker",
// }
type
UserRoleType
=
"worker"
|
"director"
;
interface
IUser
{
interface
IUser
{
id
:
string
;
id
:
string
;
...
@@ -25,48 +26,55 @@ interface IUser {
...
@@ -25,48 +26,55 @@ interface IUser {
email
:
string
;
email
:
string
;
displayName
:
string
;
displayName
:
string
;
password
:
string
;
password
:
string
;
role
:
UserRoleType
;
token
:
string
;
createdAt
:
Date
|
undefined
;
role
:
userRoleType
;
createdAt
:
Date
;
createdTasks
:
Task
[]
|
null
;
}
}
@
Entity
()
@
Entity
(
{
name
:
'User'
}
)
export
class
User
extends
BaseEntity
implements
IUser
{
export
class
User
extends
BaseEntity
implements
IUser
{
@
PrimaryGeneratedColumn
(
'uuid'
)
@
PrimaryGeneratedColumn
(
'uuid'
)
id
!
:
string
id
!
:
string
@
Column
({
name
:
'
first_
name'
,
type
:
'varchar'
,
length
:
20
,
nullable
:
false
})
@
Column
({
name
:
'name'
,
type
:
'varchar'
,
length
:
20
,
nullable
:
false
})
name
!
:
string
name
!
:
string
@
Column
({
name
:
'
last_
name'
,
type
:
'varchar'
,
length
:
30
,
nullable
:
false
})
@
Column
({
name
:
'
sur
name'
,
type
:
'varchar'
,
length
:
30
,
nullable
:
false
})
surname
!
:
string
surname
!
:
string
@
Column
({
name
:
'displayName'
,
type
:
'varchar'
,
length
:
30
,
nullable
:
false
})
@
Column
({
name
:
'displayName'
,
type
:
'varchar'
,
length
:
30
,
nullable
:
false
})
displayName
!
:
string
displayName
!
:
string
@
Column
({
type
:
'varchar'
,
length
:
20
,
unique
:
true
,
nullable
:
false
})
@
Column
({
name
:
'email'
,
type
:
'varchar'
,
length
:
20
,
unique
:
true
,
nullable
:
false
})
email
!
:
string
email
!
:
string
@
Column
({
type
:
'varchar'
,
length
:
10
,
unique
:
true
,
nullable
:
true
})
@
Column
({
name
:
'phone'
,
type
:
'varchar'
,
length
:
10
,
unique
:
true
,
nullable
:
true
})
phone
?:
string
phone
?:
string
@
Column
({
name
:
'token'
,
type
:
'varchar'
,
length
:
100
,
unique
:
true
,
nullable
:
false
})
// @CreateDateColumn()
token
!
:
string
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
:
Date
|
undefined
;
createdAt
!
:
Date
;
@
Column
({
@
Column
({
type
:
"enum"
,
type
:
"enum"
,
enum
:
[
"worker"
,
"director"
],
enum
:
[
"worker"
,
"director"
],
default
:
"worker"
default
:
"worker"
})
})
role
!
:
U
serRoleType
role
!
:
u
serRoleType
@
Column
({
type
:
'varchar'
,
nullable
:
false
,
select
:
false
})
@
Column
({
type
:
'varchar'
,
nullable
:
false
,
select
:
false
})
password
!
:
string
password
!
:
string
@
OneToMany
(()
=>
Task
,
(
task
:
{
user
:
User
})
=>
task
.
user
)
createdTasks
!
:
Task
[];
@
ManyToMany
(()
=>
Task
,
(
task
:
{
users
:
User
[]
})
=>
task
.
users
)
tasksToMake
!
:
Task
[];
@
BeforeInsert
()
@
BeforeInsert
()
protected
async
beforeInserthashPassword
():
Promise
<
void
>
{
protected
async
beforeInserthashPassword
():
Promise
<
void
>
{
...
@@ -80,6 +88,19 @@ export class User extends BaseEntity implements IUser {
...
@@ -80,6 +88,19 @@ export class User extends BaseEntity implements IUser {
this
.
password
=
await
bcrypt
.
hash
(
this
.
password
,
salt
);
this
.
password
=
await
bcrypt
.
hash
(
this
.
password
,
salt
);
}
}
public
generateToken
():
void
{
this
.
token
=
nanoid
()
return
}
static
async
comparePasswords
(
candidatePassword
:
string
,
hashedPassword
:
string
):
Promise
<
boolean
>
{
return
await
bcrypt
.
compare
(
candidatePassword
,
hashedPassword
);
}
}
}
...
...
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