Last active
June 7, 2019 21:52
-
-
Save ktutnik/da8e16fa52b43fc28123eee34aba694a 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 UserActivityMiddleware implements Middleware { | |
| async execute(next: Readonly<Invocation>): Promise<ActionResult> { | |
| if (next.context.route && next.context.state.user) { | |
| const audit = createAudit(next.context) | |
| try { | |
| const result = await next.proceed() | |
| await db("Audit").insert(<Audit>{...audit, status: "Success"}) | |
| return result | |
| } | |
| catch (e) { | |
| await db("Audit").insert(<Audit>{...audit, status: "Error"}) | |
| throw e; | |
| } | |
| } | |
| else return next.proceed() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment