Last active
June 6, 2019 01:35
-
-
Save ktutnik/74623d445c39f50e4171c27103182b74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class UsersController { | |
| // --------- other methods removed for clarity | |
| @ownerOrAdmin() | |
| @route.put(":id") | |
| async modify(id: number, data: User, @bind.user() user:LoginUser) { | |
| const audit = <Audit>{ | |
| userId: user.userId, | |
| action: "Modify", | |
| resource: "Users", | |
| data: JSON.stringify([id, <User>{ ...data, password: "*****", email: "*****" }]) | |
| } | |
| try { | |
| const password = await bcrypt.hash(data.password, 10) | |
| const result = await db("User").update({ ...data, password }).where({ id }) | |
| await db("Audit").insert(<Audit>{ ...audit, status: "Success" }) | |
| return result; | |
| } | |
| catch (e) { | |
| await db("Audit").insert(<Audit>{ ...audit, status: "Error" }) | |
| throw e; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment