diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-09-13 14:18:56 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-09-13 14:18:56 -0400 |
| commit | 8a5825d52271d712ec7c8348447d433067e13ef2 (patch) | |
| tree | ba07c218c1b2d4e59c154f2059b69fd858ae65fe /finished-application/backend/src/resolvers/Query.js | |
| parent | b0d25a9ad3cc1df2fcc11ddb84e4603b94520b09 (diff) | |
DONE
Diffstat (limited to 'finished-application/backend/src/resolvers/Query.js')
| -rw-r--r-- | finished-application/backend/src/resolvers/Query.js | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/finished-application/backend/src/resolvers/Query.js b/finished-application/backend/src/resolvers/Query.js deleted file mode 100644 index a51ead5..0000000 --- a/finished-application/backend/src/resolvers/Query.js +++ /dev/null @@ -1,69 +0,0 @@ -const { hasPermission } = require('../utils'); - -const { forwardTo } = require('prisma-binding'); - -const Query = { - items: forwardTo('db'), - itemsConnection: forwardTo('db'), - async users(parent, args, ctx, info) { - if (!ctx.request.userId) { - throw new Error('Insufficient Permissions'); - } - - return ctx.db.query.users({}, info); - }, - - async order(parent, args, ctx, info) { - // 1. make sure they are signed in - if (!ctx.request.userId) { - throw new Error('You Must be signed in to view an order'); - } - - // 2. Create the query - const where = { - id: args.id, - user: { - id: ctx.request.userId, - }, - }; - // 3. Fire off the query - const [order] = await ctx.db.query.orders({ where }, info); - - // 4. Check that they are allowed to view the order - if (order.user.id !== ctx.request.userId || hasPermission(ctx.request.user, ['ADMIN'])) { - throw new Error("You don't have permission"); - } - // 5. If everything checks out, return the order - return order; - }, - - me(parent, args, ctx, info) { - if (!ctx.request.userId) { - return null; // don't error out, just return nothing - } - - return ctx.db.query.user( - { - where: { id: ctx.request.userId }, - }, - info - ); - }, - - async orders(parent, args, ctx, info) { - const { userId } = ctx.request; - if (!userId) { - throw new Error('You must be signed in to see your orders'); - } - return ctx.db.query.orders( - { - where: { - user: { id: userId }, - }, - }, - info - ); - }, -}; - -module.exports = Query; |
