Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. const Sequelize = require('sequelize');
  2.  
  3. module.exports = function(app) {
  4. const sequelizeClient = app.get('sequelizeClient');
  5. const user = sequelizeClient.define('users', {
  6. first_name: {
  7. type: Sequelize.STRING
  8. },
  9. last_name: {
  10. type: Sequelize.STRING
  11. },
  12. gender: {
  13. type: Sequelize.STRING
  14. },
  15. date_of_birth: {
  16. type: Sequelize.STRING
  17. },
  18. mobilePhone: {
  19. type: Sequelize.STRING,
  20. unique: true
  21. },
  22.  
  23. email: {
  24. type: Sequelize.STRING,
  25. unique: true
  26. },
  27. password: {
  28. type: Sequelize.STRING,
  29. allowNull: true
  30. },
  31.  
  32. facebookId: {
  33. type: Sequelize.STRING,
  34. unique: true,
  35. allowNull: true
  36. },
  37.  
  38. facebook: {
  39. type: Sequelize.ARRAY(Sequelize.STRING),
  40. allowNull: true
  41. },
  42.  
  43. avatar: {
  44. type: Sequelize.STRING,
  45. allowNull: true
  46. },
  47.  
  48. ownerId: {
  49. type: Sequelize.STRING,
  50. allowNull: true
  51. },
  52. }, {
  53. freezeTableName: true
  54. });
  55.  
  56. user.sync();
  57.  
  58. return user;
  59. };
  60.  
  61. const { authenticate } = require('feathers-authentication').hooks;
  62. const commonHooks = require('feathers-hooks-common');
  63. const { restrictToOwner } = require('feathers-authentication-hooks');
  64. const { lowerCase } = require('feathers-hooks-common');
  65. const { validateSchema } = require('feathers-hooks-common');
  66. const { hashPassword } = require('feathers-authentication-local').hooks;
  67. const { facebookRegister } = require('../../hooks/facebook-data');
  68. const { getEmailFromFacebook } = require('../../hooks/get-email-from-facebook');
  69. //const addOwnerId = require('../../hooks/add-owner-id');
  70. const { iff, isNot, discard, setCreatedAt, setUpdatedAt } = require('feathers-hooks-common');
  71.  
  72.  
  73.  
  74. const restrict = [
  75. authenticate('jwt')
  76. ];
  77.  
  78.  
  79. const Ajv = require('ajv');
  80. const ajv = new Ajv({ allErrors: true, $data: true });
  81. ajv.addFormat('allNumbers', '^d+$');
  82. const createSchema = {
  83. title: 'User Schema',
  84. // $schema: '../schemas/schema-01#',
  85. type: 'object',
  86. required: [ 'first_name', 'last_name', 'gender', 'date_of_birth', 'email', 'password', 'mobilePhone' ],
  87. additionalProperties: false,
  88. properties: {
  89. first_name : { type: 'string', maxLength: 100, minLength: 3 },
  90. last_name: { type: 'string', maxLength: 100, minLength: 3 },
  91. gender: { type: 'string', maxLength: 100, minLength: 4 },
  92. date_of_birth: { type: 'string', maxLength: 100, minLength: 6 },
  93. email: { type: 'string', maxLength: 100, minLength: 6 },
  94. password: { type: 'string', maxLength: 30, minLength: 4 },
  95. mobilePhone: { type: 'string' },
  96. facebookId: { type: 'string', maxLength: 500, minLength: 6 },
  97. facebook: { type: 'string', maxLength: 900, minLength: 6 }
  98.  
  99. }
  100. };
  101.  
  102.  
  103. module.exports = {
  104. before: {
  105. all: [],
  106. find: [...restrict ],
  107. get: [ ...restrict ],
  108. create: [ facebookRegister(), hashPassword() ],
  109. update: [ restrictToOwner() ],
  110. patch: [ ...restrict, hashPassword() ],
  111. remove: [ ...restrict ]
  112. },
  113.  
  114. after: {
  115. all: [
  116. commonHooks.when(
  117. hook => hook.params.provider,
  118. commonHooks.discard('password')
  119. )
  120. ],
  121. find: [],
  122. get: [],
  123. create: [],
  124. update: [setUpdatedAt()],
  125. patch: [],
  126. remove: []
  127. },
  128.  
  129. error: {
  130. all: [],
  131. find: [],
  132. get: [],
  133. create: [],
  134. update: [],
  135. patch: [],
  136. remove: []
  137. }
  138. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement