Skip to content

Instantly share code, notes, and snippets.

@ktutnik
Last active June 6, 2019 01:36
Show Gist options
  • Select an option

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

Select an option

Save ktutnik/840d5f01f8d9cbb9e9f54e56bdf021dc to your computer and use it in GitHub Desktop.
export class UsersController {
// ----- other methods removed for clarity
@ownerOrAdmin()
@route.delete(":id")
async delete(id: number, @bind.user() user: LoginUser) {
const audit = <Audit>{
userId: user.userId,
action: "Delete",
resource: "Users",
data: JSON.stringify([id])
}
try {
const result = db("User").update({ deleted: 1 }).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