201 lines
2.6 KiB
JavaScript
201 lines
2.6 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 time_entries = sequelize.define(
|
|
'time_entries',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
started_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
ended_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
duration_hours: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
billable: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
bill_rate: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
cost_rate: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"approved",
|
|
|
|
|
|
"invoiced",
|
|
|
|
|
|
"rejected"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
time_entries.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.time_entries.belongsTo(db.tenants, {
|
|
as: 'tenant',
|
|
foreignKey: {
|
|
name: 'tenantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.time_entries.belongsTo(db.projects, {
|
|
as: 'project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.time_entries.belongsTo(db.clients, {
|
|
as: 'client',
|
|
foreignKey: {
|
|
name: 'clientId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.time_entries.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.time_entries.belongsTo(db.freelancer_assignments, {
|
|
as: 'freelancer_assignment',
|
|
foreignKey: {
|
|
name: 'freelancer_assignmentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.time_entries.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.time_entries.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.time_entries.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return time_entries;
|
|
};
|
|
|
|
|