kukukk

Content

Aug 14th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = (sequelize, DataTypes) => {
  2.     const Content = sequelize.define('Content', {
  3.         title: {
  4.             type: DataTypes.STRING,
  5.             allowNull: false,
  6.         },
  7.         description: {
  8.             type: DataTypes.STRING,
  9.             allowNull: false,
  10.         },
  11.         duration: {
  12.             type: DataTypes.INTEGER,
  13.             allowNull: false,
  14.         },
  15.         thumbnail: {
  16.             type: DataTypes.STRING,
  17.             allowNull: false,
  18.         },
  19.         visibility: {
  20.             type:   DataTypes.ENUM,
  21.             values: ['private', 'friends', 'public'],
  22.             defaultValue: 'private',
  23.         },
  24.         uid: {
  25.             type: DataTypes.STRING,
  26.             allowNull: false,
  27.         },
  28.         created: {
  29.             type: DataTypes.DATE,
  30.             allowNull: false,
  31.             defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
  32.         },
  33.     }, {
  34.         tableName: 'contents',
  35.         freezeTableName: true,
  36.         timestamps: false,
  37.     });
  38.  
  39.     Content.associate = (models) => {
  40.         Content.belongsTo(models.User, {
  41.             foreignKey: {
  42.                 name: 'user_id',
  43.                 allowNull: false,
  44.             },
  45.             onDelete: 'CASCADE',
  46.         });
  47.         Content.hasMany(models.Like, {
  48.             foreignKey: {
  49.                 name: 'content_id',
  50.                 allowNull: false,
  51.             },
  52.         });
  53.     };
  54.  
  55.     Content.prototype.toJSON = function () {
  56.         // Return a shallow clone so toJSON method of the nested models can be called recursively.
  57.         return Object.assign({}, this.get());
  58.     };
  59.  
  60.     return Content;
  61. };
Advertisement
Add Comment
Please, Sign In to add comment