38276-vm/backend/src/db/models/case_parties.js
2026-02-07 20:13:29 +00:00

160 lines
1.7 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 case_parties = sequelize.define(
'case_parties',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
party_role: {
type: DataTypes.ENUM,
values: [
"client",
"subject",
"witness",
"opposing_party",
"attorney",
"other"
],
},
full_name: {
type: DataTypes.TEXT,
},
organization: {
type: DataTypes.TEXT,
},
email: {
type: DataTypes.TEXT,
},
phone: {
type: DataTypes.TEXT,
},
address: {
type: DataTypes.TEXT,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
case_parties.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.case_parties.belongsTo(db.cases, {
as: 'case',
foreignKey: {
name: 'caseId',
},
constraints: false,
});
db.case_parties.belongsTo(db.users, {
as: 'createdBy',
});
db.case_parties.belongsTo(db.users, {
as: 'updatedBy',
});
};
return case_parties;
};