102 lines
1.9 KiB
JavaScript
102 lines
1.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 projects = sequelize.define(
|
|
'projects',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
projectName: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
projectAddress1: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
projectAddress2: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
projectCity: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
projectState: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
projectZIP: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
siteContactName: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
siteContactPhone: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
projects.associate = (db) => {
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
db.projects.hasMany(db.orders, {
|
|
as: 'orders_projectName',
|
|
foreignKey: {
|
|
name: 'projectNameId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.projects.hasMany(db.billofladings, {
|
|
as: 'billofladings_projectID',
|
|
foreignKey: {
|
|
name: 'projectIDId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
//end loop
|
|
|
|
db.projects.belongsTo(db.recievers, {
|
|
as: 'recieverName',
|
|
foreignKey: {
|
|
name: 'recieverNameId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return projects;
|
|
};
|