SHARE
TWEET

Untitled

a guest Jun 5th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import winston from 'winston'
  2. import {
  3.   GraphQLString,
  4.   GraphQLNonNull,
  5.   GraphQLBoolean,
  6.   GraphQlList
  7. } from 'graphql'
  8. import User from './userSchema'
  9. import UserMongoose from '../../../mongoose/user'
  10.  
  11. export default {
  12.   registerUser: {
  13.     type: GraphQLBoolean,
  14.     description: 'Register user and create db entry.',
  15.     args: {
  16.       firstName: {
  17.         type: new GraphQLNonNull(GraphQLString)
  18.       },
  19.       lastName: {
  20.         type: new GraphQLNonNull(GraphQLString)
  21.       },
  22.       email: {
  23.         type: new GraphQLNonNull(GraphQLString)
  24.       },
  25.       position: {
  26.         type: new GraphQLNonNull(GraphQLString)
  27.       },
  28.       company: {
  29.         type: new GraphQLNonNull(GraphQLString)
  30.       },
  31.       password: {
  32.         type: new GraphQLNonNull(GraphQLString)
  33.       },
  34.       permissions: {
  35.         type: new GraphQLList(GraphQLString)
  36.       },
  37.       products: {
  38.         type: new GraphQLList(GraphQLString)
  39.       },
  40.       accessGroups: {
  41.         type: new GraphQLList(GraphQLString)
  42.       },
  43.       role: {
  44.         type: new GraphQLNonNull(GraphQLString)
  45.       },
  46.       profileImage: {
  47.         type: GraphQLString
  48.       }
  49.     },
  50.     resolve: (parent, {
  51.       firstName,
  52.       lastName,
  53.       email,
  54.       position,
  55.       password,
  56.       company
  57.     }, ast) => {
  58.       var user = new UserMongoose({
  59.         firstName: firstName,
  60.         lastName: lastName,
  61.         email: email,
  62.         position: position,
  63.         company: company,
  64.         password: password,
  65.         permissions: permissions,
  66.         products: products,
  67.         accessGroups: accessGroups,
  68.         role: role,
  69.         profileImage: profileImage
  70.       })
  71.       user.save((err, user) => {
  72.         if (err) winston.log('error', err)
  73.         if (user) winston.log('info', 'Created user with id %s', user._id)
  74.       })
  75.     }
  76.   },
  77.   loginUser: {
  78.     type: GraphQLString,
  79.     description: 'Login user, match db password and return (time limited) JWT access token.',
  80.     args: {
  81.       email: new GraphQLNonNull(GraphQLString),
  82.       password: new GraphQLNonNull(GraphQLString)
  83.     },
  84.     resolve: (parent, {
  85.       email,
  86.       password
  87.     }, ast) => {
  88.       UserMongoose.findOne({
  89.         email: email
  90.       }, (err, user) => {
  91.         if (err) winston.log('error', err)
  92.  
  93.         user.comparePassword(password, (err, isMatch) => {
  94.           if (err) winston.log('error', err)
  95.  
  96.           if (!isMatch) return 'NoMatch'
  97.         })
  98.       })
  99.     }
  100.   }
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top