149 lines
1.7 KiB
JavaScript
149 lines
1.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 flight_statuses = sequelize.define(
|
|
'flight_statuses',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
movement: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"arrival",
|
|
|
|
|
|
"departure",
|
|
|
|
|
|
"turnaround",
|
|
|
|
|
|
"any"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
category: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"scheduled",
|
|
|
|
|
|
"operational",
|
|
|
|
|
|
"irregular",
|
|
|
|
|
|
"closed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
sort_order: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
active: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
flight_statuses.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.flight_statuses.hasMany(db.flights, {
|
|
as: 'flights_status',
|
|
foreignKey: {
|
|
name: 'statusId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.flight_statuses.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.flight_statuses.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return flight_statuses;
|
|
};
|
|
|
|
|