ahebwa49
04/11/2019, 6:53 AMasync order(root, args, context, info) {
//1. make sure they are logged in.
if (!context.request.userId) {
throw new Error("You must be logged in.");
}
//2. query the current order.
const order = await context.prisma.order({
id: args.id
}).$fragment(`{
user{
id
}
}`);
//3. check if they ahve the permissions to see this order
const ownsOrder = order.user.id === context.request.userId;
const hasPermissionToSeeOrder = context.request.user.permissions.includes(
"ADMIN"
);
if (!ownsOrder || !hasPermissionToSeeOrder) {
throw new Error("You don't have permissions to see this.");
}
//4. return the order.
return order;
}
nuno
04/11/2019, 9:12 AM{
id
charge
total
createdAt
user {
id
}
items {
id
title
description
price
image
quantity
}
}
At least the fields you request on the frontendnuno
04/11/2019, 10:04 AMahebwa49
04/11/2019, 10:04 AMahebwa49
04/11/2019, 10:06 AMahebwa49
04/11/2019, 10:12 AMahebwa49
04/11/2019, 10:12 AMJared
04/11/2019, 1:55 PMahebwa49
04/11/2019, 2:13 PM