Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. 'use strict'
  2.  
  3. export default (sequelize, DataTypes) => {
  4.  
  5. const Account = sequelize.define('Account', {
  6. firstName: {
  7. type: DataTypes.STRING,
  8. allowNull: false,
  9. validate: {
  10. not: /[`~@#$^*&!,<>;':"/[\]|{}()=+_-]/,
  11. is: /^[a-zA-Z\s]*$/
  12. }
  13. },
  14. lastName: {
  15. type: DataTypes.STRING,
  16. allowNull: false,
  17. validate: {
  18. not: /[`~@#$^*&!,<>;':"/[\]|{}()=+_-]/,
  19. isAlpha: true,
  20.  
  21. }
  22. },
  23. email: {
  24. type: DataTypes.STRING,
  25. allowNull: false,
  26. unique: true,
  27. validate: {
  28. isEmail: true,
  29. }
  30. },
  31. phoneNumber: {
  32. type: DataTypes.STRING,
  33. allowNull: false,
  34. unique: true,
  35. validate: {
  36. isNumeric: true,
  37. not: /[`~@#$^*&!,<>;':"/[\]|{}()=+_-]/,
  38. }
  39. },
  40. username: {
  41. type: DataTypes.STRING,
  42. allowNull: false,
  43. unique: true,
  44. validate: {
  45. not: /[`~@#$^*&!,<>;':"/[\]|{}()=+]/,
  46. }
  47. },
  48. password: {
  49. type: DataTypes.STRING,
  50. allowNull: false,
  51. validate: {
  52. isAlphanumeric: true,
  53. }
  54. },
  55. isPending: {
  56. type: DataTypes.BOOLEAN,
  57. defaultValue: true
  58. },
  59. isSuspended: {
  60. type: DataTypes.BOOLEAN,
  61. defaultValue: false
  62. }
  63.  
  64. },
  65. {
  66. classMethods: {
  67. associate: function (models) {
  68.  
  69. // =====================
  70. // Settings Associations
  71. // =====================
  72.  
  73. Account.hasOne(models.Address);
  74. Account.hasOne(models.WorkExperience);
  75. Account.hasOne(models.EdExperience);
  76. Account.hasOne(models.Role)
  77.  
  78. // =====================
  79. // Chat Associations
  80. // =====================
  81.  
  82. // .hasMany(models.Chat)
  83. Account.belongsToMany(models.Chat, {
  84. through: {
  85. model: models.ParticipantsInChat,
  86. unique: false
  87. }
  88. })
  89. Account.hasMany(models.Message)
  90.  
  91. // =====================
  92. // x Associations
  93. // =====================
  94. }
  95. }
  96. })
  97.  
  98. return Account;
  99. }
  100.  
  101. // module.exports = function(sequelize, DataTypes) {
  102. // const Account = sequelize.define('Account', {
  103. // email: {
  104. // type: DataTypes.STRING
  105. // }
  106. // }, {
  107. // classMethods: {
  108. // associate: function(models) {
  109. // // Account.hasMany(models.Chat);
  110.  
  111. // Account.belongsToMany(models.Chat, {
  112. // through: {
  113. // model: models.ParticipantsInChat,
  114. // unique: false
  115. // },
  116. // });
  117. // Account.hasMany(models.Message);
  118. // }
  119. // }
  120. // });
  121.  
  122. // return Account;
  123. // };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement