Skip to content

Instantly share code, notes, and snippets.

@LawJolla
Created February 26, 2018 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LawJolla/34111532f9e580584ff78873647ba882 to your computer and use it in GitHub Desktop.
Save LawJolla/34111532f9e580584ff78873647ba882 to your computer and use it in GitHub Desktop.
updateAskingPrice with permissions
const Mutation = {
updateVehicleAskingPrice: async (parent, { id, askingPrice }, context, info) => {
const userId = getUserId(context)
const isRequestingUserManager = await context.db.exists.User({
id: userId,
role: `MANAGER`
})
if (isRequestingUserManager) {
return await context.db.mutation.updateVehicle({
where: { id },
data: { askingPrice }
})
}
throw new Error(
`Invalid permissions, you must be a manager to update vehicle year`
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment