229 lines
2.9 KiB
JavaScript
229 lines
2.9 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 itineraries = sequelize.define(
|
|
'itineraries',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"shortlisted",
|
|
|
|
|
|
"recommended",
|
|
|
|
|
|
"archived"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
fare_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"cash",
|
|
|
|
|
|
"points",
|
|
|
|
|
|
"mixed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
total_price_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
currency: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
total_points: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
taxes_fees_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
estimated_value_per_point: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
observed_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
expires_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
booking_link: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
itineraries.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.itineraries.hasMany(db.flight_legs, {
|
|
as: 'flight_legs_itinerary',
|
|
foreignKey: {
|
|
name: 'itineraryId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.itineraries.hasMany(db.price_observations, {
|
|
as: 'price_observations_itinerary',
|
|
foreignKey: {
|
|
name: 'itineraryId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.itineraries.belongsTo(db.flight_searches, {
|
|
as: 'flight_search',
|
|
foreignKey: {
|
|
name: 'flight_searchId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.itineraries.belongsTo(db.data_sources, {
|
|
as: 'source',
|
|
foreignKey: {
|
|
name: 'sourceId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.itineraries.hasMany(db.file, {
|
|
as: 'attachments',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.itineraries.getTableName(),
|
|
belongsToColumn: 'attachments',
|
|
},
|
|
});
|
|
|
|
|
|
db.itineraries.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.itineraries.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return itineraries;
|
|
};
|
|
|
|
|