177 lines
2.5 KiB
JavaScript
177 lines
2.5 KiB
JavaScript
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 grids = sequelize.define(
|
|
'grids',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
columns_count: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
rows_count: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_responsive: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
interaction_mode: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"hover_only",
|
|
|
|
|
|
"touch_only",
|
|
|
|
|
|
"hover_and_touch",
|
|
|
|
|
|
"selectable"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
grids.associate = (db) => {
|
|
|
|
db.grids.belongsToMany(db.grid_tiles, {
|
|
as: 'tiles',
|
|
foreignKey: {
|
|
name: 'grids_tilesId',
|
|
},
|
|
constraints: false,
|
|
through: 'gridsTilesGrid_tiles',
|
|
});
|
|
|
|
db.grids.belongsToMany(db.grid_tiles, {
|
|
as: 'tiles_filter',
|
|
foreignKey: {
|
|
name: 'grids_tilesId',
|
|
},
|
|
constraints: false,
|
|
through: 'gridsTilesGrid_tiles',
|
|
});
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.grids.hasMany(db.grid_tiles, {
|
|
as: 'grid_tiles_grid',
|
|
foreignKey: {
|
|
name: 'gridId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.grids.hasMany(db.tile_interactions, {
|
|
as: 'tile_interactions_grid',
|
|
foreignKey: {
|
|
name: 'gridId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.grids.belongsTo(db.users, {
|
|
as: 'owner',
|
|
foreignKey: {
|
|
name: 'ownerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.grids.belongsTo(db.color_themes, {
|
|
as: 'theme',
|
|
foreignKey: {
|
|
name: 'themeId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.grids.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.grids.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return grids;
|
|
};
|
|
|
|
|