75 lines
1.4 KiB
JavaScript
75 lines
1.4 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 bins = sequelize.define(
|
|
'bins',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
location: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
values: ['dry', 'wet', 'metal'],
|
|
},
|
|
|
|
is_full: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
},
|
|
|
|
last_checked: {
|
|
type: DataTypes.DATE,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
bins.associate = (db) => {
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
db.bins.hasMany(db.alerts, {
|
|
as: 'alerts_bin',
|
|
foreignKey: {
|
|
name: 'binId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
//end loop
|
|
|
|
db.bins.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.bins.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return bins;
|
|
};
|