105 lines
2.8 KiB
JavaScript
105 lines
2.8 KiB
JavaScript
const { APPLICATION_STAGES, APPLICATION_STATUS, BUSINESS_TYPES } = require('../config/constants');
|
|
|
|
module.exports = (sequelize, DataTypes) => {
|
|
const Application = sequelize.define('Application', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true
|
|
},
|
|
applicationId: {
|
|
type: DataTypes.STRING,
|
|
unique: true,
|
|
allowNull: false
|
|
},
|
|
applicantName: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
email: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
validate: { isEmail: true }
|
|
},
|
|
phone: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
businessType: {
|
|
type: DataTypes.ENUM(Object.values(BUSINESS_TYPES)),
|
|
allowNull: false
|
|
},
|
|
preferredLocation: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
city: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
state: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
experienceYears: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false
|
|
},
|
|
investmentCapacity: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
currentStage: {
|
|
type: DataTypes.ENUM(Object.values(APPLICATION_STAGES)),
|
|
defaultValue: APPLICATION_STAGES.DD
|
|
},
|
|
overallStatus: {
|
|
type: DataTypes.ENUM(Object.values(APPLICATION_STATUS)),
|
|
defaultValue: APPLICATION_STATUS.PENDING
|
|
},
|
|
progressPercentage: {
|
|
type: DataTypes.INTEGER,
|
|
defaultValue: 0
|
|
},
|
|
submittedBy: {
|
|
type: DataTypes.UUID,
|
|
allowNull: true,
|
|
references: {
|
|
model: 'users',
|
|
key: 'id'
|
|
}
|
|
},
|
|
documents: {
|
|
type: DataTypes.JSON,
|
|
defaultValue: []
|
|
},
|
|
timeline: {
|
|
type: DataTypes.JSON,
|
|
defaultValue: []
|
|
}
|
|
}, {
|
|
tableName: 'applications',
|
|
timestamps: true,
|
|
indexes: [
|
|
{ fields: ['applicationId'] },
|
|
{ fields: ['email'] },
|
|
{ fields: ['currentStage'] },
|
|
{ fields: ['overallStatus'] }
|
|
]
|
|
});
|
|
|
|
Application.associate = (models) => {
|
|
Application.belongsTo(models.User, {
|
|
foreignKey: 'submittedBy',
|
|
as: 'submitter'
|
|
});
|
|
Application.hasMany(models.Document, {
|
|
foreignKey: 'requestId',
|
|
as: 'uploadedDocuments',
|
|
scope: { requestType: 'application' }
|
|
});
|
|
};
|
|
|
|
return Application;
|
|
};
|