171 lines
2.2 KiB
JavaScript
171 lines
2.2 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 tips = sequelize.define(
|
|
'tips',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
category: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"antes_de_salir",
|
|
|
|
|
|
"durante_el_chinchorreo",
|
|
|
|
|
|
"responsabilidad",
|
|
|
|
|
|
"glosario_boricua"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
content: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
short_snippet: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
tip_of_day_eligible: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
published: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
tips.associate = (db) => {
|
|
|
|
db.tips.belongsToMany(db.tags, {
|
|
as: 'tags',
|
|
foreignKey: {
|
|
name: 'tips_tagsId',
|
|
},
|
|
constraints: false,
|
|
through: 'tipsTagsTags',
|
|
});
|
|
|
|
db.tips.belongsToMany(db.tags, {
|
|
as: 'tags_filter',
|
|
foreignKey: {
|
|
name: 'tips_tagsId',
|
|
},
|
|
constraints: false,
|
|
through: 'tipsTagsTags',
|
|
});
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
db.tips.hasMany(db.file, {
|
|
as: 'images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.tips.getTableName(),
|
|
belongsToColumn: 'images',
|
|
},
|
|
});
|
|
|
|
|
|
db.tips.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.tips.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return tips;
|
|
};
|
|
|
|
|