2025-08-17 08:04:31 +00:00

106 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 firma = sequelize.define(
'firma',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
firma.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.firma.hasMany(db.users, {
as: 'users_firma',
foreignKey: {
name: 'firmaId',
},
constraints: false,
});
db.firma.hasMany(db.features, {
as: 'features_firma',
foreignKey: {
name: 'firmaId',
},
constraints: false,
});
db.firma.hasMany(db.messages, {
as: 'messages_firma',
foreignKey: {
name: 'firmaId',
},
constraints: false,
});
db.firma.hasMany(db.notifications, {
as: 'notifications_firma',
foreignKey: {
name: 'firmaId',
},
constraints: false,
});
db.firma.hasMany(db.packages, {
as: 'packages_firma',
foreignKey: {
name: 'firmaId',
},
constraints: false,
});
db.firma.hasMany(db.stops, {
as: 'stops_firma',
foreignKey: {
name: 'firmaId',
},
constraints: false,
});
db.firma.hasMany(db.trips, {
as: 'trips_firma',
foreignKey: {
name: 'firmaId',
},
constraints: false,
});
//end loop
db.firma.belongsTo(db.users, {
as: 'createdBy',
});
db.firma.belongsTo(db.users, {
as: 'updatedBy',
});
};
return firma;
};