Skip to content
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

Merged
merged 5 commits into from
Nov 12, 2024
Merged

admin user #188

merged 5 commits into from
Nov 12, 2024

Conversation

RA341
Copy link
Collaborator

@RA341 RA341 commented Nov 11, 2024

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 apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist


Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of
them, don't hesitate to ask. This is simply a reminder of what we are going to look for before merging your code.

  • My changeset covers only what is described above (no extraneous changes)
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@NicholasMy NicholasMy changed the base branch from main to develop November 12, 2024 17:19
// 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
Copy link
Member

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')
Copy link
Member

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')
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking!

@RA341
Copy link
Collaborator Author

RA341 commented Nov 12, 2024

fixed it

@jessehartloff jessehartloff merged commit eccf8ad into develop Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants