Skip to content

Instantly share code, notes, and snippets.

@LawJolla
Created February 26, 2018 23:24
Show Gist options
  • 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