Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = function(sequelize, DataTypes) {
- var Board = sequelize.define("Board", {
- name: {
- type: DataTypes.STRING,
- allowNull: false,
- validate: {
- len: [1]
- }
- },
- favorited: {
- type: DataTypes.BOOLEAN,
- allowNull: false,
- defaultValue: false
- }
- });
- Board.associate = function(models) {
- Board.belongsTo(models.User, {
- foreignKey: {
- name: "OwnerId"
- }
- });
- Board.belongsToMany(models.User, {
- through: "UserBoards"
- });
- };
- return Board;
- };
- module.exports = function(sequelize, DataTypes) {
- var User = sequelize.define("User", {
- name: {
- type: DataTypes.STRING,
- allowNull: false,
- validate: {
- isAlphanumeric: true
- }
- },
- email: {
- type: DataTypes.STRING,
- allowNull: false,
- validate: {
- isEmail: true
- }
- },
- password: {
- type: DataTypes.STRING,
- allowNull: false
- }
- });
- User.associate = function(models) {
- User.belongsToMany(models.Board, {
- through: "UserBoards"
- });
- };
- return User;
- };
- Board {
- _customGetters: {},
- _customSetters: {},
- validators: { name: { len: [Object] } },
- _hasCustomGetters: 0,
- _hasCustomSetters: 0,
- rawAttributes:
- { id:
- { type: [Object],
- allowNull: false,
- primaryKey: true,
- autoIncrement: true,
- _autoGenerated: true,
- Model: Board,
- fieldName: 'id',
- _modelAttribute: true,
- field: 'id' },
- name:
- { type: [Object],
- allowNull: false,
- validate: [Object],
- Model: Board,
- fieldName: 'name',
- _modelAttribute: true,
- field: 'name' },
- favorited:
- { type: BOOLEAN {},
- allowNull: false,
- defaultValue: false,
- Model: Board,
- fieldName: 'favorited',
- _modelAttribute: true,
- field: 'favorited' },
- createdAt:
- { type: [Object],
- allowNull: false,
- _autoGenerated: true,
- Model: Board,
- fieldName: 'createdAt',
- _modelAttribute: true,
- field: 'createdAt' },
- updatedAt:
- { type: [Object],
- allowNull: false,
- _autoGenerated: true,
- Model: Board,
- fieldName: 'updatedAt',
- _modelAttribute: true,
- field: 'updatedAt' },
- OwnerId:
- { name: 'OwnerId',
- type: [Object],
- allowNull: true,
- references: [Object],
- onDelete: 'SET NULL',
- onUpdate: 'CASCADE',
- Model: Board,
- fieldName: 'OwnerId',
- _modelAttribute: true,
- field: 'OwnerId' } },
- attributes: [ 'id', 'name', 'favorited', 'createdAt', 'updatedAt', 'OwnerId' ],
- _isAttribute: { [Function: memoized] cache: MapCache { size: 0, __data__: [Object] } },
- getUser: [Function],
- setUser: [Function],
- createUser: [Function],
- getUsers: [Function],
- countUsers: [Function],
- hasUser: [Function],
- hasUsers: [Function],
- setUsers: [Function],
- addUser: [Function],
- addUsers: [Function],
- removeUser: [Function],
- removeUsers: [Function] }
- router.get("/boards/:id/users/:uid", function(req, res) {
- var query = {};
- if (req.params.id) {
- query.id = req.params.id;
- db.Board.findAll({
- where: query
- }).then(function(dbBoard) {
- dbBoard.addUser(req.params.uid);
- res.json(dbBoards);
- });
- }
- });
Add Comment
Please, Sign In to add comment