89 lines
1.9 KiB
JavaScript
89 lines
1.9 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 archival_items = sequelize.define(
|
|
'archival_items',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
label: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
isPublished: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
archival_items.associate = (db) => {
|
|
db.archival_items.belongsToMany(db.tags, {
|
|
as: 'tags',
|
|
foreignKey: {
|
|
name: 'archival_items_tagsId',
|
|
},
|
|
constraints: false,
|
|
through: 'archival_itemsTagsTags',
|
|
});
|
|
|
|
db.archival_items.belongsToMany(db.tags, {
|
|
as: 'tags_filter',
|
|
foreignKey: {
|
|
name: 'archival_items_tagsId',
|
|
},
|
|
constraints: false,
|
|
through: 'archival_itemsTagsTags',
|
|
});
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
//end loop
|
|
|
|
db.archival_items.hasMany(db.file, {
|
|
as: 'media',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.archival_items.getTableName(),
|
|
belongsToColumn: 'media',
|
|
},
|
|
});
|
|
|
|
db.archival_items.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.archival_items.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return archival_items;
|
|
};
|