101 lines
1.9 KiB
JavaScript
101 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 documents = sequelize.define(
|
|
'documents',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
document_type: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
category: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
values: ['active', 'expired', 'archived'],
|
|
},
|
|
|
|
expiry_date: {
|
|
type: DataTypes.DATE,
|
|
},
|
|
|
|
is_signed: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
documents.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.documents.belongsTo(db.participants, {
|
|
as: 'participant',
|
|
foreignKey: {
|
|
name: 'participantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.documents.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.documents.hasMany(db.file, {
|
|
as: 'file_path',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.documents.getTableName(),
|
|
belongsToColumn: 'file_path',
|
|
},
|
|
});
|
|
|
|
db.documents.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.documents.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return documents;
|
|
};
|