Skip to content

Instantly share code, notes, and snippets.

@ktutnik
Last active June 7, 2019 21:52
Show Gist options
  • Select an option

  • Save ktutnik/da8e16fa52b43fc28123eee34aba694a to your computer and use it in GitHub Desktop.

Select an option

Save ktutnik/da8e16fa52b43fc28123eee34aba694a to your computer and use it in GitHub Desktop.
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