Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import winston from 'winston'
- import {
- GraphQLString,
- GraphQLNonNull,
- GraphQLBoolean,
- GraphQLList
- } from 'graphql'
- import User from './userSchema'
- import UserMongoose from '../../../mongoose/user'
- export default {
- registerUser: {
- type: GraphQLBoolean,
- description: 'Register user and create db entry.',
- args: {
- firstName: {
- type: GraphQLString
- },
- lastName: {
- type: GraphQLString
- },
- email: {
- type: GraphQLString
- },
- position: {
- type: GraphQLString
- },
- company: {
- type: GraphQLString
- },
- password: {
- type: GraphQLString
- },
- permissions: {
- type: new GraphQLList(GraphQLString)
- },
- products: {
- type: new GraphQLList(GraphQLString)
- },
- accessGroups: {
- type: new GraphQLList(GraphQLString)
- },
- profileImage: {
- type: GraphQLString
- },
- role: {
- type: GraphQLString
- }
- },
- async resolve: (parent, {
- firstName,
- lastName,
- email,
- position,
- company,
- password,
- role
- }, ast) => {
- var user = new UserMongoose({
- firstName: firstName,
- lastName: lastName,
- email: email,
- position: position,
- company: company,
- password: password,
- permissions: permissions,
- products: products,
- accessGroups: accessGroups,
- role: role,
- profileImage: profileImage
- })
- user.save((err, user) => {
- if (err) {
- winston.log('error', err)
- return false
- }
- return true
- })
- }
- },
- loginUser: {
- type: GraphQLString,
- description: 'Login user, match db password and return (time limited) JWT access token.',
- args: {
- email: {
- type: new GraphQLNonNull(GraphQLString)
- },
- password: {
- type: new GraphQLNonNull(GraphQLString)
- }
- },
- async resolve: (parent, {
- email,
- password
- }, ast) => {
- UserMongoose.findOne({
- email: email
- }, (err, user) => {
- if (err) winston.log('error', err)
- user.comparePassword(password, (err, isMatch) => {
- if (err) winston.log('error', err)
- if (!isMatch) return 'NoMatch'
- return 'Match'
- })
- })
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement