132 lines
1.8 KiB
JavaScript
132 lines
1.8 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 message_attachments = sequelize.define(
|
|
'message_attachments',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
filename: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
mime_type: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
size_bytes: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
attachment_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"file",
|
|
|
|
|
|
"image"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
message_attachments.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.message_attachments.belongsTo(db.messages, {
|
|
as: 'message',
|
|
foreignKey: {
|
|
name: 'messageId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.message_attachments.hasMany(db.file, {
|
|
as: 'file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.message_attachments.getTableName(),
|
|
belongsToColumn: 'file',
|
|
},
|
|
});
|
|
|
|
|
|
db.message_attachments.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.message_attachments.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return message_attachments;
|
|
};
|
|
|
|
|