diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-09-14 12:18:12 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-09-14 12:18:12 -0400 |
| commit | 2d145b026cfdf54a63bef0b9d6324b6785390307 (patch) | |
| tree | f6c1d8f987437803a5c026e70535bf9ff244e885 /stepped-solutions/FINISHED/backend/src/resolvers/Query.js | |
| parent | 8a5825d52271d712ec7c8348447d433067e13ef2 (diff) | |
move finished folder
Diffstat (limited to 'stepped-solutions/FINISHED/backend/src/resolvers/Query.js')
| -rw-r--r-- | stepped-solutions/FINISHED/backend/src/resolvers/Query.js | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/stepped-solutions/FINISHED/backend/src/resolvers/Query.js b/stepped-solutions/FINISHED/backend/src/resolvers/Query.js deleted file mode 100644 index 22a6414..0000000 --- a/stepped-solutions/FINISHED/backend/src/resolvers/Query.js +++ /dev/null @@ -1,69 +0,0 @@ -const { forwardTo } = require('prisma-binding'); -const { hasPermission } = require('../utils'); - -const Query = { - items: forwardTo('db'), - item: forwardTo('db'), - itemsConnection: forwardTo('db'), - me(parent, args, ctx, info) { - // check if there is a current user ID - if (!ctx.request.userId) { - return null; - } - return ctx.db.query.user( - { - where: { id: ctx.request.userId }, - }, - info - ); - }, - async users(parent, args, ctx, info) { - // 1. Check if they are logged in - if (!ctx.request.userId) { - throw new Error('You must be logged in!'); - } - console.log(ctx.request.userId); - // 2. Check if the user has the permissions to query all the users - hasPermission(ctx.request.user, ['ADMIN', 'PERMISSIONUPDATE']); - - // 2. if they do, query all the users! - return ctx.db.query.users({}, info); - }, - async order(parent, args, ctx, info) { - // 1. Make sure they are logged in - if (!ctx.request.userId) { - throw new Error('You arent logged in!'); - } - // 2. Query the current order - const order = await ctx.db.query.order( - { - where: { id: args.id }, - }, - info - ); - // 3. Check if the have the permissions to see this order - const ownsOrder = order.user.id === ctx.request.userId; - const hasPermissionToSeeOrder = ctx.request.user.permissions.includes('ADMIN'); - if (!ownsOrder || !hasPermission) { - throw new Error('You cant see this buddd'); - } - // 4. Return the order - return order; - }, - async orders(parent, args, ctx, info) { - const { userId } = ctx.request; - if (!userId) { - throw new Error('you must be signed in!'); - } - return ctx.db.query.orders( - { - where: { - user: { id: userId }, - }, - }, - info - ); - }, -}; - -module.exports = Query; |
