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
98b1a3d0
Commit
98b1a3d0
authored
Nov 08, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'task-32-fix/fix_date_login_role' into 'development'
Task 32 fix/fix date login role See merge request
!14
parents
d10cdbd9
3bd0027b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
27 deletions
+37
-27
package-lock.json
planner-api/package-lock.json
+11
-0
package.json
planner-api/package.json
+1
-0
Task.ts
planner-api/src/models/Task.ts
+8
-8
User.ts
planner-api/src/models/User.ts
+12
-15
tasks.ts
planner-api/src/routers/tasks.ts
+2
-1
users.ts
planner-api/src/routers/users.ts
+3
-3
No files found.
planner-api/package-lock.json
View file @
98b1a3d0
...
...
@@ -13,6 +13,7 @@
"@types/cors"
:
"^2.8.12"
,
"@types/express"
:
"^4.17.14"
,
"bcrypt"
:
"^5.1.0"
,
"class-transformer"
:
"^0.5.1"
,
"class-validator"
:
"^0.13.2"
,
"cors"
:
"^2.8.5"
,
"express"
:
"^4.18.2"
,
...
...
@@ -2491,6 +2492,11 @@
"node"
:
">=10"
}
},
"node_modules/class-transformer"
:
{
"version"
:
"0.5.1"
,
"resolved"
:
"https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz"
,
"integrity"
:
"sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw=="
},
"node_modules/class-validator"
:
{
"version"
:
"0.13.2"
,
"resolved"
:
"https://registry.npmjs.org/class-validator/-/class-validator-0.13.2.tgz"
,
...
...
@@ -7724,6 +7730,11 @@
"resolved"
:
"https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz"
,
"integrity"
:
"sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ=="
},
"class-transformer"
:
{
"version"
:
"0.5.1"
,
"resolved"
:
"https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz"
,
"integrity"
:
"sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw=="
},
"class-validator"
:
{
"version"
:
"0.13.2"
,
"resolved"
:
"https://registry.npmjs.org/class-validator/-/class-validator-0.13.2.tgz"
,
...
...
planner-api/package.json
View file @
98b1a3d0
...
...
@@ -26,6 +26,7 @@
"@types/cors"
:
"^2.8.12"
,
"@types/express"
:
"^4.17.14"
,
"bcrypt"
:
"^5.1.0"
,
"class-transformer"
:
"^0.5.1"
,
"class-validator"
:
"^0.13.2"
,
"cors"
:
"^2.8.5"
,
"express"
:
"^4.18.2"
,
...
...
planner-api/src/models/Task.ts
View file @
98b1a3d0
...
...
@@ -36,10 +36,6 @@ import {
description
!
:
string
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
@
Column
({
name
:
'dateTimeStart'
,
type
:
'varchar'
,
nullable
:
true
})
dateTimeStart
!
:
Date
|
null
;
@
Column
({
name
:
'dateTimeDue'
,
type
:
'varchar'
,
nullable
:
true
})
dateTimeDue
!
:
Date
|
null
;
@
Column
({
type
:
"enum"
,
enum
:
[
"opened"
,
"done"
,
"failed"
],
...
...
@@ -47,6 +43,10 @@ import {
})
accomplish
!
:
taskFinishType
@
Column
({
name
:
'dateTimeStart'
,
type
:
Date
,
nullable
:
true
})
dateTimeStart
!
:
Date
|
null
;
@
Column
({
name
:
'dateTimeDue'
,
type
:
Date
,
nullable
:
true
})
dateTimeDue
!
:
Date
|
null
;
@
ManyToOne
(()
=>
User
,
(
user
:
{
tasks
:
Task
[];
})
=>
user
.
tasks
,{
eager
:
true
})
author
!
:
User
;
...
...
planner-api/src/models/User.ts
View file @
98b1a3d0
...
...
@@ -7,11 +7,11 @@ import {
BaseEntity
,
ManyToMany
,
OneToMany
,
JoinTable
JoinTable
,
}
from
'typeorm'
;
import
{
IsEmail
}
from
"class-validator"
;
import
{
Exclude
,
instanceToPlain
}
from
"class-transformer"
;
import
bcrypt
from
'bcrypt'
;
import
{
nanoid
}
from
'nanoid'
;
import
{
Task
}
from
'./Task'
;
...
...
@@ -20,17 +20,17 @@ import {Project} from './Project';
const
SALT_WORK_FACTOR
=
10
;
type
userRoleType
=
"worker"
|
"director"
;
export
enum
UserRole
{
USER
=
"user"
,
DIRECTOR
=
"director"
,
SUPERUSER
=
"superuser"
}
interface
IUser
{
id
:
string
;
role
:
UserRole
;
name
:
string
;
surname
:
string
;
email
:
string
;
displayName
:
string
;
password
:
string
;
token
:
string
;
role
:
userRoleType
;
createdAt
:
Date
;
createdTasks
:
Task
[];
workerInProjects
:
Project
[];
...
...
@@ -67,12 +67,13 @@ export class User extends BaseEntity implements IUser {
@
Column
({
type
:
"enum"
,
enum
:
[
"worker"
,
"director"
]
,
default
:
"worker"
enum
:
UserRole
,
default
:
UserRole
.
USER
})
role
!
:
userRoleTyp
e
role
!
:
UserRol
e
@
Column
({
type
:
'varchar'
,
nullable
:
false
,
select
:
false
})
@
Column
({
type
:
'varchar'
,
nullable
:
false
,
select
:
true
})
@
Exclude
({
toPlainOnly
:
true
})
password
!
:
string
...
...
@@ -106,20 +107,16 @@ export class User extends BaseEntity implements IUser {
public
async
checkPassword
(
candidatePassword
:
string
,
):
Promise
<
boolean
>
{
console
.
log
(
"Checking password"
,
candidatePassword
,
'this.password'
,
this
.
password
)
return
await
bcrypt
.
compare
(
candidatePassword
,
this
.
password
);
}
toJSON
()
{
return
instanceToPlain
(
this
);
}
}
...
...
planner-api/src/routers/tasks.ts
View file @
98b1a3d0
...
...
@@ -17,7 +17,7 @@ export default router;
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
newTask
=
new
Task
();
const
{
title
,
description
,
project
,
executors
,
dateTimeDue
,
dateTimeStart
}
=
req
.
body
;
const
{
title
,
description
,
project
,
executors
,
dateTimeDue
,
dateTimeStart
,
accomplish
}
=
req
.
body
;
const
user
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"user"
)
...
...
@@ -32,6 +32,7 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
newTask
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
author
=
user
;
newTask
.
accomplish
=
accomplish
;
await
newTask
.
save
();
return
res
.
send
({
newTask
})
})
...
...
planner-api/src/routers/users.ts
View file @
98b1a3d0
...
...
@@ -17,7 +17,7 @@ return res.send({users})
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
const
{
name
,
surname
,
password
,
email
}
=
req
.
body
;
const
{
name
,
surname
,
password
,
email
,
role
}
=
req
.
body
;
const
displayName
=
surname
+
' '
+
name
[
0
]
+
'.'
const
user
=
new
User
();
user
.
name
=
name
;
...
...
@@ -25,6 +25,7 @@ router.post('/', async (req : Request, res : Response):Promise<object> => {
user
.
password
=
password
;
user
.
displayName
=
displayName
;
user
.
email
=
email
;
user
.
role
=
role
;
user
.
generateToken
()
await
user
.
save
();
const
userToFront
:
User
|
null
=
await
dataSource
.
manager
.
findOneBy
(
User
,
{
...
...
@@ -41,9 +42,9 @@ router.post('/sessions/', async (req : Request, res : Response):Promise<object>
.
select
(
"user"
)
.
from
(
User
,
"user"
)
.
where
(
"user.email = :email"
,
{
email
:
email
})
.
addSelect
(
'password'
)
.
getOne
()
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
const
isMatch
:
boolean
=
await
user
.
checkPassword
(
password
);
if
(
!
isMatch
)
return
res
.
status
(
400
).
send
({
error
:
"Wrong Password"
...
...
@@ -67,7 +68,6 @@ router.delete('/sessions', async(req: Request, res: Response):Promise<void | obj
token
:
token
})
if
(
!
user
)
return
res
.
send
({
successMsg
});
console
.
log
(
'token: '
+
token
)
user
.
token
=
nanoid
();
await
user
.
save
();
...
...
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