const config = require('../../config'); const providers = config.providers; const crypto = require('crypto'); const bcrypt = require('bcrypt'); const moment = require('moment'); module.exports = function(sequelize, DataTypes) { const products = sequelize.define( 'products', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, name: { type: DataTypes.TEXT, }, category: { type: DataTypes.ENUM, values: [ "iptv_subscription", "streaming_service", "digital_service", "other" ], }, value_proposition: { type: DataTypes.TEXT, }, website_url: { type: DataTypes.TEXT, }, supports_4k: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, supports_8k: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, approx_channel_count: { type: DataTypes.INTEGER, }, approx_vod_titles: { type: DataTypes.INTEGER, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); products.associate = (db) => { /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity db.products.hasMany(db.email_templates, { as: 'email_templates_product', foreignKey: { name: 'productId', }, constraints: false, }); db.products.hasMany(db.generation_requests, { as: 'generation_requests_product', foreignKey: { name: 'productId', }, constraints: false, }); //end loop db.products.belongsTo(db.brands, { as: 'brand', foreignKey: { name: 'brandId', }, constraints: false, }); db.products.belongsTo(db.users, { as: 'createdBy', }); db.products.belongsTo(db.users, { as: 'updatedBy', }); }; return products; };