76 lines
1.5 KiB
JavaScript
76 lines
1.5 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 maintenance_reports = sequelize.define(
|
|
'maintenance_reports',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
reported_at: {
|
|
type: DataTypes.DATE,
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
severity: {
|
|
type: DataTypes.ENUM,
|
|
|
|
values: ['low', 'medium', 'high'],
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
maintenance_reports.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.maintenance_reports.belongsTo(db.drones, {
|
|
as: 'drone',
|
|
foreignKey: {
|
|
name: 'droneId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.maintenance_reports.belongsTo(db.users, {
|
|
as: 'reported_by',
|
|
foreignKey: {
|
|
name: 'reported_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.maintenance_reports.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.maintenance_reports.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return maintenance_reports;
|
|
};
|