Warren Day
06/02/2020, 4:23 PMMike SOK
06/02/2020, 8:05 PMasync createRating(parent, {ratingSubject, ratingDescription, ratingImage, ratingStar, itemId}, ctx, info) {
const hasPermissions = ctx.request.user.permissions.some
(permission =>
['ADMIN', 'USER'].includes(permission)
);
if (!hasPermissions) {
throw new Error("You don't have permission to do that!");
}
if (!ctx.request.userId) {
throw new Error ('You must be logged in to do that!');
}
const rating = await ctx.db.mutation.createRating({
data: {
// This is how we create a relationship between the Item and the User
user: {
connect: {
id: ctx.request.userId
}
},
item: {
connect: { id: itemId }
},
ratingSubject,
ratingDescription,
ratingImage,
ratingStar,
},
},
info);
return rating;
},
Mike SOK
06/02/2020, 8:06 PMitem: {
connect: { id: itemId }
},
Warren Day
06/03/2020, 8:28 AM