201 lines
2.7 KiB
JavaScript
201 lines
2.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 flocks = sequelize.define(
|
|
'flocks',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
flock_code: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
breed: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
loading_date: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
beginning_population_male: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
beginning_population_female: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
ending_population_male: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
ending_population_female: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
livability_percent: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
depletion_rate_percent: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_closed: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
closed_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
flocks.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.flocks.hasMany(db.feed_consumptions, {
|
|
as: 'feed_consumptions_flock',
|
|
foreignKey: {
|
|
name: 'flockId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.flocks.hasMany(db.mortality_records, {
|
|
as: 'mortality_records_flock',
|
|
foreignKey: {
|
|
name: 'flockId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.flocks.hasMany(db.egg_production_records, {
|
|
as: 'egg_production_records_flock',
|
|
foreignKey: {
|
|
name: 'flockId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.flocks.belongsTo(db.farms, {
|
|
as: 'farm',
|
|
foreignKey: {
|
|
name: 'farmId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.flocks.belongsTo(db.farm_houses, {
|
|
as: 'house',
|
|
foreignKey: {
|
|
name: 'houseId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.flocks.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.flocks.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return flocks;
|
|
};
|
|
|
|
|