84 lines
1.5 KiB
JavaScript
84 lines
1.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 records = sequelize.define(
|
|
'records',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
rating: {
|
|
type: DataTypes.INTEGER,
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
snippet: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
scanned_from_url: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
captured_by: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
capture_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
values: ['Manual', 'Automatic'],
|
|
},
|
|
|
|
tags: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
records.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.records.belongsTo(db.projects, {
|
|
as: 'project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.records.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.records.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return records;
|
|
};
|