100 lines
2.2 KiB
JavaScript
100 lines
2.2 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 individuals = sequelize.define(
|
|
'individuals',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
personal_number: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
rank: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
individuals.associate = (db) => {
|
|
db.individuals.belongsToMany(db.acclimatization_records, {
|
|
as: 'acclimatization_records',
|
|
foreignKey: {
|
|
name: 'individuals_acclimatization_recordsId',
|
|
},
|
|
constraints: false,
|
|
through: 'individualsAcclimatization_recordsAcclimatization_records',
|
|
});
|
|
|
|
db.individuals.belongsToMany(db.acclimatization_records, {
|
|
as: 'acclimatization_records_filter',
|
|
foreignKey: {
|
|
name: 'individuals_acclimatization_recordsId',
|
|
},
|
|
constraints: false,
|
|
through: 'individualsAcclimatization_recordsAcclimatization_records',
|
|
});
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
db.individuals.hasMany(db.acclimatization_records, {
|
|
as: 'acclimatization_records_individual',
|
|
foreignKey: {
|
|
name: 'individualId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
//end loop
|
|
|
|
db.individuals.belongsTo(db.units, {
|
|
as: 'unit',
|
|
foreignKey: {
|
|
name: 'unitId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.individuals.belongsTo(db.units, {
|
|
as: 'units',
|
|
foreignKey: {
|
|
name: 'unitsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.individuals.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.individuals.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return individuals;
|
|
};
|