38759-vm/backend/src/db/models/client_history_entries.js
2026-02-25 08:35:59 +00:00

142 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 client_history_entries = sequelize.define(
'client_history_entries',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
entry_type: {
type: DataTypes.ENUM,
values: [
"activity",
"file",
"note",
"status_change"
],
},
occurred_at: {
type: DataTypes.DATE,
},
title: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
client_history_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.client_history_entries.belongsTo(db.clients, {
as: 'client',
foreignKey: {
name: 'clientId',
},
constraints: false,
});
db.client_history_entries.belongsTo(db.activities, {
as: 'activity',
foreignKey: {
name: 'activityId',
},
constraints: false,
});
db.client_history_entries.belongsTo(db.files, {
as: 'file',
foreignKey: {
name: 'fileId',
},
constraints: false,
});
db.client_history_entries.belongsTo(db.users, {
as: 'actor',
foreignKey: {
name: 'actorId',
},
constraints: false,
});
db.client_history_entries.belongsTo(db.users, {
as: 'createdBy',
});
db.client_history_entries.belongsTo(db.users, {
as: 'updatedBy',
});
};
return client_history_entries;
};