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 meter_readings = sequelize.define( 'meter_readings', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, reading_value: { type: DataTypes.DECIMAL, }, unit_label: { type: DataTypes.TEXT, }, reading_date: { type: DataTypes.DATE, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); meter_readings.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.meter_readings.belongsTo(db.units, { as: 'unit', foreignKey: { name: 'unitId', }, constraints: false, }); db.meter_readings.belongsTo(db.utility_providers, { as: 'provider', foreignKey: { name: 'providerId', }, constraints: false, }); db.meter_readings.belongsTo(db.company, { as: 'company', foreignKey: { name: 'companyId', }, constraints: false, }); db.meter_readings.belongsTo(db.users, { as: 'createdBy', }); db.meter_readings.belongsTo(db.users, { as: 'updatedBy', }); }; return meter_readings; };