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

Endpoint(?) for managing roles a user has #2190

Open
easherma opened this issue Dec 22, 2020 · 1 comment
Open

Endpoint(?) for managing roles a user has #2190

easherma opened this issue Dec 22, 2020 · 1 comment

Comments

@easherma
Copy link
Collaborator

easherma commented Dec 22, 2020

We need a callable method that can update the 'roles' given to a user.

'roles' are flags that are then used by the frontend to expose different kinds of functionality.

Should be pretty simple, and rely heavily on Sequelize functionality

Params

  • user
  • role

Most of this can probably be broken out from the code here:

try {
const { data, roles } = user
const newRole = planMap[tier1PlanId].value
// if we already have the role, skip adding it
if (!roles.includes(newRole)) {
roles.push(newRole)
user.roles = roles
}
const now = new Date()
const newData = {
...data,
subscribed: now,
subscriptionId: subscription.id,
customerId: customer.id,
planId: tier1PlanId
}
user.data = newData
user.save().then((upgradedUser) => {
logger.info({ upgradedUser, subscription }, 'added user subscription')
res.status(200).json({ user: upgradedUser, subscription })
})

But changing the role separate from adding payments or subscriptions will be a better design

Blockers

Implementing this quickly in a fully testable way is somewhat blocked by #2192

@easherma
Copy link
Collaborator Author

easherma commented Dec 22, 2020

Wondering if we can update roles via user PUT? We can handle updating data via that PUT param; though I can't play around with this locally very easily since authentication for users isn't quite the same locally (aka we dont have test users locally)

We could also have the role adding be an method on the model itself, potentially as a validator (check sequelize docs)

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

No branches or pull requests

2 participants