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 site_settings = sequelize.define( 'site_settings', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, site_name: { type: DataTypes.TEXT, }, primary_color: { type: DataTypes.TEXT, }, secondary_color: { type: DataTypes.TEXT, }, contact_email: { type: DataTypes.TEXT, }, contact_phone: { type: DataTypes.TEXT, }, address: { type: DataTypes.TEXT, }, footer_text: { type: DataTypes.TEXT, }, enable_cookie_notice: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, cookie_notice_text: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); site_settings.associate = (db) => { /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity //end loop db.site_settings.hasMany(db.file, { as: 'logo_images', foreignKey: 'belongsToId', constraints: false, scope: { belongsTo: db.site_settings.getTableName(), belongsToColumn: 'logo_images', }, }); db.site_settings.hasMany(db.file, { as: 'favicon_images', foreignKey: 'belongsToId', constraints: false, scope: { belongsTo: db.site_settings.getTableName(), belongsToColumn: 'favicon_images', }, }); db.site_settings.belongsTo(db.users, { as: 'createdBy', }); db.site_settings.belongsTo(db.users, { as: 'updatedBy', }); }; return site_settings; };