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
2a167edd
Commit
2a167edd
authored
Jan 17, 2023
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#151
added try blocks to helpers.ts
parent
8e20da5c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
helpers.ts
planner-api/src/helpers.ts
+16
-0
No files found.
planner-api/src/helpers.ts
View file @
2a167edd
...
...
@@ -12,6 +12,7 @@ const dataSource = myDataSource;
/** Check if user with given token exists , return user */
export
const
auth
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
Response
>>=>
{
try
{
const
token
=
req
.
get
(
'Authorization'
);
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
const
user
=
await
dataSource
...
...
@@ -23,10 +24,14 @@ export const auth = async(req: Request,res: Response, next:NextFunction):Promise
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
req
.
body
=
{...
req
.
body
,
user
:
user
}
next
()
}
catch
(
e
)
{
return
res
.
status
(
502
).
send
({
message
:(
e
as
Error
).
message
})
}
};
/**Check if user with the given token is executor or author of task with the given Id(taskId) */
export
const
authAuthorOrExecutorOfTask
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
Response
>>=>
{
try
{
const
token
=
req
.
get
(
'Authorization'
);
const
{
user
}
=
req
.
body
let
taskId
=
null
...
...
@@ -65,11 +70,15 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
}
req
.
body
=
{...
req
.
body
,
task
:
task
}
next
()
}
catch
(
e
)
{
return
res
.
status
(
502
).
send
({
message
:(
e
as
Error
).
message
})
}
};
/**Check if user with the given token is executor or author of task with the given dateTimeTaskId */
export
const
authAuthorOrExecutorOfDateTimeTask
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
Response
>>=>
{
try
{
const
token
=
req
.
get
(
'Authorization'
);
let
dateTimeTaskId
=
null
req
.
body
=
{...
req
.
body
,
executorStatus
:
false
}
...
...
@@ -105,11 +114,15 @@ export const authAuthorOrExecutorOfDateTimeTask = async(req: Request,res: Respon
}
if
(
req
.
body
.
authorStatus
===
false
&&
req
.
body
.
executorStatus
===
false
)
return
res
.
status
(
403
).
send
({
Message
:
'user is not uathorized'
})
next
()
}
catch
(
e
)
{
return
res
.
status
(
502
).
send
({
message
:(
e
as
Error
).
message
})
}
}
/**check if user is admin of the project, receives userId and projectId*/
export
const
authAdminProject
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
):
Promise
<
void
|
express
.
Response
<
Response
>>=>
{
try
{
const
token
=
req
.
get
(
'Authorization'
);
const
{
projectId
}
=
req
.
body
;
const
adminOfProject
=
await
dataSource
...
...
@@ -127,6 +140,9 @@ export const authAdminProject = async(req: Request,res: Response, next:NextFunct
}
req
.
body
=
{...
req
.
body
,
adminStatus
:
true
}
next
()
}
catch
(
e
)
{
return
res
.
status
(
502
).
send
({
message
:(
e
as
Error
).
message
})
}
}
...
...
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