Guest User

Untitled

a guest
Dec 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. module.exports = function(sequelize, DataTypes) {
  2. var Board = sequelize.define("Board", {
  3. name: {
  4. type: DataTypes.STRING,
  5. allowNull: false,
  6. validate: {
  7. len: [1]
  8. }
  9. },
  10. favorited: {
  11. type: DataTypes.BOOLEAN,
  12. allowNull: false,
  13. defaultValue: false
  14. }
  15. });
  16. Board.associate = function(models) {
  17. Board.belongsTo(models.User, {
  18. foreignKey: {
  19. name: "OwnerId"
  20. }
  21. });
  22. Board.belongsToMany(models.User, {
  23. through: "UserBoards"
  24. });
  25. };
  26. return Board;
  27. };
  28.  
  29. module.exports = function(sequelize, DataTypes) {
  30. var User = sequelize.define("User", {
  31. name: {
  32. type: DataTypes.STRING,
  33. allowNull: false,
  34. validate: {
  35. isAlphanumeric: true
  36. }
  37. },
  38. email: {
  39. type: DataTypes.STRING,
  40. allowNull: false,
  41. validate: {
  42. isEmail: true
  43. }
  44. },
  45. password: {
  46. type: DataTypes.STRING,
  47. allowNull: false
  48. }
  49. });
  50.  
  51. User.associate = function(models) {
  52. User.belongsToMany(models.Board, {
  53. through: "UserBoards"
  54. });
  55. };
  56.  
  57. return User;
  58.  
  59. };
  60.  
  61. Board {
  62. _customGetters: {},
  63. _customSetters: {},
  64. validators: { name: { len: [Object] } },
  65. _hasCustomGetters: 0,
  66. _hasCustomSetters: 0,
  67. rawAttributes:
  68. { id:
  69. { type: [Object],
  70. allowNull: false,
  71. primaryKey: true,
  72. autoIncrement: true,
  73. _autoGenerated: true,
  74. Model: Board,
  75. fieldName: 'id',
  76. _modelAttribute: true,
  77. field: 'id' },
  78. name:
  79. { type: [Object],
  80. allowNull: false,
  81. validate: [Object],
  82. Model: Board,
  83. fieldName: 'name',
  84. _modelAttribute: true,
  85. field: 'name' },
  86. favorited:
  87. { type: BOOLEAN {},
  88. allowNull: false,
  89. defaultValue: false,
  90. Model: Board,
  91. fieldName: 'favorited',
  92. _modelAttribute: true,
  93. field: 'favorited' },
  94. createdAt:
  95. { type: [Object],
  96. allowNull: false,
  97. _autoGenerated: true,
  98. Model: Board,
  99. fieldName: 'createdAt',
  100. _modelAttribute: true,
  101. field: 'createdAt' },
  102. updatedAt:
  103. { type: [Object],
  104. allowNull: false,
  105. _autoGenerated: true,
  106. Model: Board,
  107. fieldName: 'updatedAt',
  108. _modelAttribute: true,
  109. field: 'updatedAt' },
  110. OwnerId:
  111. { name: 'OwnerId',
  112. type: [Object],
  113. allowNull: true,
  114. references: [Object],
  115. onDelete: 'SET NULL',
  116. onUpdate: 'CASCADE',
  117. Model: Board,
  118. fieldName: 'OwnerId',
  119. _modelAttribute: true,
  120. field: 'OwnerId' } },
  121. attributes: [ 'id', 'name', 'favorited', 'createdAt', 'updatedAt', 'OwnerId' ],
  122. _isAttribute: { [Function: memoized] cache: MapCache { size: 0, __data__: [Object] } },
  123. getUser: [Function],
  124. setUser: [Function],
  125. createUser: [Function],
  126. getUsers: [Function],
  127. countUsers: [Function],
  128. hasUser: [Function],
  129. hasUsers: [Function],
  130. setUsers: [Function],
  131. addUser: [Function],
  132. addUsers: [Function],
  133. removeUser: [Function],
  134. removeUsers: [Function] }
  135.  
  136. router.get("/boards/:id/users/:uid", function(req, res) {
  137. var query = {};
  138. if (req.params.id) {
  139. query.id = req.params.id;
  140. db.Board.findAll({
  141. where: query
  142. }).then(function(dbBoard) {
  143. dbBoard.addUser(req.params.uid);
  144. res.json(dbBoards);
  145. });
  146. }
  147.  
  148. });
Add Comment
Please, Sign In to add comment