186 lines
2.1 KiB
JavaScript
186 lines
2.1 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 vendors = sequelize.define(
|
|
'vendors',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
category: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"catering",
|
|
|
|
|
|
"audio_visual",
|
|
|
|
|
|
"decor",
|
|
|
|
|
|
"entertainment",
|
|
|
|
|
|
"photography",
|
|
|
|
|
|
"videography",
|
|
|
|
|
|
"security",
|
|
|
|
|
|
"transportation",
|
|
|
|
|
|
"rentals",
|
|
|
|
|
|
"staffing",
|
|
|
|
|
|
"printing",
|
|
|
|
|
|
"other"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
primary_contact_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
primary_contact_email: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
primary_contact_phone: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
website: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
address: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
vendors.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.vendors.hasMany(db.event_vendor_bookings, {
|
|
as: 'event_vendor_bookings_vendor',
|
|
foreignKey: {
|
|
name: 'vendorId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
db.vendors.hasMany(db.file, {
|
|
as: 'files',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.vendors.getTableName(),
|
|
belongsToColumn: 'files',
|
|
},
|
|
});
|
|
|
|
|
|
db.vendors.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.vendors.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return vendors;
|
|
};
|
|
|
|
|