187 lines
2.6 KiB
JavaScript
187 lines
2.6 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 hubs = sequelize.define(
|
|
'hubs',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
region: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"central_city",
|
|
|
|
|
|
"western",
|
|
|
|
|
|
"northern",
|
|
|
|
|
|
"south_eastern",
|
|
|
|
|
|
"inner_south"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
is_active: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
default_prep_minutes: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
heavy_packing_buffer_minutes: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
hubs.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.hubs.hasMany(db.hub_service_areas, {
|
|
as: 'hub_service_areas_hub',
|
|
foreignKey: {
|
|
name: 'hubId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.hubs.hasMany(db.customer_addresses, {
|
|
as: 'customer_addresses_matched_hub',
|
|
foreignKey: {
|
|
name: 'matched_hubId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.hubs.hasMany(db.carts, {
|
|
as: 'carts_hub',
|
|
foreignKey: {
|
|
name: 'hubId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.hubs.hasMany(db.orders, {
|
|
as: 'orders_hub',
|
|
foreignKey: {
|
|
name: 'hubId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.hubs.hasMany(db.drivers, {
|
|
as: 'drivers_home_hub',
|
|
foreignKey: {
|
|
name: 'home_hubId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.hubs.hasMany(db.driver_sessions, {
|
|
as: 'driver_sessions_hub',
|
|
foreignKey: {
|
|
name: 'hubId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.hubs.hasMany(db.dispatch_jobs, {
|
|
as: 'dispatch_jobs_hub',
|
|
foreignKey: {
|
|
name: 'hubId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.hubs.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.hubs.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return hubs;
|
|
};
|
|
|
|
|