-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
admin user #188
admin user #188
Conversation
// delete an admin, only an admin can delete an admin | ||
export async function deleteAdmin(req: Request, res: Response, next: NextFunction) { | ||
try { | ||
let newAdminUserId = req.body.newAdminUserId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a more appropriate variable name
return res.status(404).send('Not found') | ||
} | ||
await UserService.softDeleteAdmin(newAdminUserId) | ||
res.status(204).send('User is no longer admin') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A 204 shouldn't have a body
} | ||
|
||
const isAdmin = await UserService.isAdmin(userId) | ||
if (!isAdmin!.isAdmin!) return res.status(403).send('unauthorized') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to be consistent with capitalization on "Unauthorized"
export async function softDeleteAdmin(id: number) { | ||
let res = await connect().count({ take: 2, where: { isAdmin: true } }) | ||
// check if this deletes the last admin | ||
// there must always be at least 1 admin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking!
fixed it |
Proposed changes
Implements #168, but instead of adding the user in the config file, the first account created automatically becomes the admin
Types of changes
What types of changes does your code introduce?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any ofthem, don't hesitate to ask. This is simply a reminder of what we are going to look for before merging your code.