Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  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: GraphQLString
  18. },
  19. lastName: {
  20. type: GraphQLString
  21. },
  22. email: {
  23. type: GraphQLString
  24. },
  25. position: {
  26. type: GraphQLString
  27. },
  28. company: {
  29. type: GraphQLString
  30. },
  31. password: {
  32. type: 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. profileImage: {
  44. type: GraphQLString
  45. },
  46. role: {
  47. type: GraphQLString
  48. }
  49. },
  50. async resolve: (parent, {
  51. firstName,
  52. lastName,
  53. email,
  54. position,
  55. company,
  56. password,
  57. role
  58. }, ast) => {
  59. var user = new UserMongoose({
  60. firstName: firstName,
  61. lastName: lastName,
  62. email: email,
  63. position: position,
  64. company: company,
  65. password: password,
  66. permissions: permissions,
  67. products: products,
  68. accessGroups: accessGroups,
  69. role: role,
  70. profileImage: profileImage
  71. })
  72. user.save((err, user) => {
  73. if (err) {
  74. winston.log('error', err)
  75. return false
  76. }
  77. return true
  78. })
  79. }
  80. },
  81. loginUser: {
  82. type: GraphQLString,
  83. description: 'Login user, match db password and return (time limited) JWT access token.',
  84. args: {
  85. email: {
  86. type: new GraphQLNonNull(GraphQLString)
  87. },
  88. password: {
  89. type: new GraphQLNonNull(GraphQLString)
  90. }
  91. },
  92. async resolve: (parent, {
  93. email,
  94. password
  95. }, ast) => {
  96. UserMongoose.findOne({
  97. email: email
  98. }, (err, user) => {
  99. if (err) winston.log('error', err)
  100.  
  101. user.comparePassword(password, (err, isMatch) => {
  102. if (err) winston.log('error', err)
  103.  
  104. if (!isMatch) return 'NoMatch'
  105. return 'Match'
  106. })
  107. })
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement