Created
February 26, 2018 23:24
-
-
Save LawJolla/34111532f9e580584ff78873647ba882 to your computer and use it in GitHub Desktop.
updateAskingPrice with permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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