Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fahrtenbuch
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWP WS21_22 - Fahrtenbuch
Team Einhorn
fahrtenbuch
Commits
0c68bcf0
Commit
0c68bcf0
authored
3 years ago
by
alrwasheda
Browse files
Options
Downloads
Patches
Plain Diff
updateAccountById controller
parent
40d695b2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/src/controllers/accounts.controllers.ts
+42
-1
42 additions, 1 deletion
server/src/controllers/accounts.controllers.ts
with
42 additions
and
1 deletion
server/src/controllers/accounts.controllers.ts
+
42
−
1
View file @
0c68bcf0
...
@@ -64,7 +64,7 @@ const showAllAccounts = async (req: Request, res: Response) => {
...
@@ -64,7 +64,7 @@ const showAllAccounts = async (req: Request, res: Response) => {
}
}
};
};
//show a specific account using given id: email is the primary key for a worker
//show a specific account using given id: email is the primary key for a worker
const
showAccountById
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
showAccountById
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
try
{
if
(
!
(
res
.
locals
.
user
.
role
===
"
coordinator
"
))
{
if
(
!
(
res
.
locals
.
user
.
role
===
"
coordinator
"
))
{
...
@@ -83,10 +83,51 @@ const showAccountById = async (req: Request, res: Response) => {
...
@@ -83,10 +83,51 @@ const showAccountById = async (req: Request, res: Response) => {
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
}
};
};
//update account by id
const
updateAccount
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
if
(
!
(
res
.
locals
.
user
.
role
===
"
coordinator
"
))
{
return
res
.
status
(
403
)
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
//take what ever in req.body is, and pass it to update()
const
input
=
req
.
body
;
//camelCase json
let
givenId
=
req
.
params
.
id
;
//if given id not found
const
worker
=
await
Worker
.
findByPk
(
givenId
);
if
(
!
worker
)
{
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
accountNotFound
"
});
}
//update worker
await
Worker
.
update
(
input
,
{
where
:
{
email
:
givenId
,
//primary key in worker is email
},
});
if
(
req
.
body
.
email
!==
"
undefined
"
)
{
//if email was given in req.body -> update givenId (with new email) to find the updatedAccount and send its new data back
givenId
=
req
.
body
.
email
;
}
const
updatedWorker
=
await
Worker
.
findByPk
(
givenId
);
return
res
.
status
(
200
).
json
({
success
:
true
,
result
:
updatedWorker
});
}
catch
(
error
)
{
console
.
error
(
"
server error:
"
,
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
const
accountsControllers
=
{
const
accountsControllers
=
{
createAccountController
,
createAccountController
,
showAllAccounts
,
showAllAccounts
,
showAccountById
,
showAccountById
,
updateAccount
,
};
};
export
default
accountsControllers
;
export
default
accountsControllers
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment