133 lines
2.0 KiB
JavaScript
133 lines
2.0 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 work_logs = sequelize.define(
|
|
'work_logs',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
started_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
ended_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
summary: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
work_logs.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.work_logs.belongsTo(db.assignments, {
|
|
as: 'assignment',
|
|
foreignKey: {
|
|
name: 'assignmentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.work_logs.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.work_logs.hasMany(db.file, {
|
|
as: 'progress_images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.work_logs.getTableName(),
|
|
belongsToColumn: 'progress_images',
|
|
},
|
|
});
|
|
|
|
db.work_logs.hasMany(db.file, {
|
|
as: 'report_files',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.work_logs.getTableName(),
|
|
belongsToColumn: 'report_files',
|
|
},
|
|
});
|
|
|
|
|
|
db.work_logs.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.work_logs.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return work_logs;
|
|
};
|
|
|
|
|