// // const mongoose = require('mongoose'); // // // Connect to MongoDB // // const connectDB = async () => { // // try { // // await mongoose.connect(process.env.MONGODB_URI); // // console.log('✅ MongoDB connected successfully'); // // } catch (error) { // // console.error('❌ MongoDB connection failed:', error.message); // // process.exit(1); // // } // // }; // // // Admin Schema // // const adminSchema = new mongoose.Schema({ // // admin_id: { type: String, required: true, unique: true }, // // name: { type: String, required: true }, // // email: { type: String, required: true, unique: true }, // // password: { type: String, required: true }, // // created_at: { type: Date, default: Date.now }, // // last_login: Date // // }); // // // Agent Schema // // const agentSchema = new mongoose.Schema({ // // agent_id: { type: String, required: true, unique: true }, // // agent_name: { type: String, required: true }, // // agent_email: { type: String, required: true, unique: true }, // // contact_number: { type: String, required: true }, // // password: { type: String, required: true }, // // status: { type: String, default: 'active', enum: ['active', 'inactive'] }, // // created_at: { type: Date, default: Date.now }, // // last_login: Date // // }); // // // Case Schema with all sections // // const caseSchema = new mongoose.Schema({ // // case_id: { type: String, required: true, unique: true }, // // case_applicant_name: { type: String, required: true }, // // case_applicant_contact: { type: String, required: true }, // // address: { type: String, required: true }, // // case_type: { // // type: String, // // required: true, // // enum: ['Business Loan', 'Personal Loan', 'Credit Card', 'Home Loan'] // // }, // // loan_amount: { type: Number, default: 0 }, // // priority: { // // type: String, // // default: 'MED', // // enum: ['LOW', 'MED', 'HIGH'] // // }, // // assigned_agent: { type: String, default: null }, // // status: { // // type: String, // // default: 'Unassigned', // // enum: ['Completed', 'In Progress', 'Pending', 'Unassigned'] // // }, // // // Demographic Details // // demographic_details: { // // aadhaar_photo_match: { type: Boolean, default: null }, // // contact_information: { // // email_id: String, // // mobile_number: String // // }, // // personal_details: { // // gender: { type: String, enum: ['Male', 'Female', 'Others'] }, // // education: String, // // number_of_family_members: Number // // }, // // customer_photo_id: String, // // address_details: { // // residence_address_type: { type: String, enum: ['Own', 'Rent'] }, // // residential_address: String, // // city: String, // // state: String, // // district: String, // // pincode: String // // }, // // residence_photo_id: String // // }, // // // Business Details // // business_details: { // // enterprise_information: { // // enterprise_name: String, // // type_of_organization: String // // }, // // business_location_details: { // // business_address_type: { type: String, enum: ['Own', 'Rent'] }, // // business_location: { type: String, enum: ['Fixed', 'Mobile'] } // // }, // // business_address: { // // address: String, // // city: String, // // district: String, // // state: String, // // pincode: String, // // landmark: String // // }, // // business_address_photo_id: String, // // business_activity: { // // business_activity: { type: String, enum: ['Manufacturing', 'Services', 'Trading'] }, // // activity_type: { type: String, enum: ['Demand', 'Regular'] } // // }, // // business_info: { // // employee_count: Number, // // years_of_running_business: Number, // // additional_business: { type: String, enum: ['Yes', 'No'] } // // } // // }, // // // Financial Details // // financial_details: { // // business_financial_information: { // // monthly_income_from_business: Number, // // monthly_expense_of_business: Number // // }, // // loans_and_emis: { // // current_loans_emis: String // // }, // // family_financial_information: { // // monthly_family_income: Number, // // number_of_working_members: Number, // // monthly_family_expense: Number // // } // // }, // // created_at: { type: Date, default: Date.now }, // // assigned_at: Date, // // accepted_at: Date, // // completed_at: Date, // // updated_at: { type: Date, default: Date.now }, // // remarks: String // // }); // // // File Schema // // const fileSchema = new mongoose.Schema({ // // file_id: { type: String, required: true, unique: true }, // // case_id: { type: String, required: true }, // // filename: { type: String, required: true }, // // original_name: { type: String, required: true }, // // file_type: { type: String, required: true }, // // mime_type: { type: String, required: true }, // // file_size: { type: Number, required: true }, // // file_data: { type: Buffer, required: true }, // // geo_location: { // // lat: Number, // // lng: Number // // }, // // uploaded_at: { type: Date, default: Date.now }, // // uploaded_by: String // // }); // // const Admin = mongoose.model('Admin', adminSchema); // // const Agent = mongoose.model('Agent', agentSchema); // // const Case = mongoose.model('Case', caseSchema); // // const File = mongoose.model('File', fileSchema); // // module.exports = { connectDB, Admin, Agent, Case, File }; // const mongoose = require('mongoose'); // // Connect to MongoDB // const connectDB = async () => { // try { // await mongoose.connect(process.env.MONGODB_URI); // console.log('✅ MongoDB connected successfully'); // } catch (error) { // console.error('❌ MongoDB connection failed:', error.message); // process.exit(1); // } // }; // // Admin Schema // const adminSchema = new mongoose.Schema({ // admin_id: { type: String, required: true, unique: true }, // name: { type: String, required: true }, // email: { type: String, required: true, unique: true }, // password: { type: String, required: true }, // created_at: { type: Date, default: Date.now }, // last_login: Date // }); // // Agent Schema // const agentSchema = new mongoose.Schema({ // agent_id: { type: String, required: true, unique: true }, // agent_name: { type: String, required: true }, // agent_email: { type: String, required: true, unique: true }, // contact_number: { type: String, required: true }, // password: { type: String, required: true }, // agency: { type: String, required: true }, // status: { type: String, default: 'active', enum: ['active', 'inactive'] }, // created_at: { type: Date, default: Date.now }, // last_login: Date // }); // // Case Schema with all sections // const caseSchema = new mongoose.Schema({ // case_id: { type: String, required: true, unique: true }, // case_applicant_name: { type: String, required: true }, // case_applicant_contact: { type: String, required: true }, // address: { type: String, required: true }, // case_type: { // type: String, // required: true // }, // loan_amount: { type: Number, default: 0 }, // priority: { // type: String, // default: 'MED', // enum: ['LOW', 'MED', 'HIGH'] // }, // assigned_agent: { type: String, default: null }, // status: { // type: String, // default: 'Unassigned', // enum: ['Completed', 'In Progress', 'Pending', 'Unassigned'] // }, // // Demographic Details // demographic_details: { // aadhaar_photo_match: { type: Boolean, default: null }, // contact_information: { // email_id: String, // mobile_number: String // }, // personal_details: { // gender: { type: String, enum: ['Male', 'Female', 'Others'] }, // education: String, // number_of_family_members: Number // }, // customer_photo_id: String, // address_details: { // residence_address_type: { type: String, enum: ['Own', 'Rent'] }, // residential_address: String, // city: String, // state: String, // district: String, // pincode: String // }, // residence_photo_id: String // }, // // Business Details // business_details: { // enterprise_information: { // enterprise_name: String, // type_of_organization: String // }, // business_location_details: { // business_address_type: { type: String, enum: ['Own', 'Rent'] }, // business_location: { type: String, enum: ['Fixed', 'Mobile'] } // }, // business_address: { // address: String, // city: String, // district: String, // state: String, // pincode: String, // landmark: String // }, // business_address_photo_id: String, // business_activity: { // business_activity: { type: String, enum: ['Manufacturing', 'Services', 'Trading'] }, // activity_type: { type: String, enum: ['Demand', 'Regular'] } // }, // business_info: { // employee_count: Number, // years_of_running_business: Number, // additional_business: { type: String, enum: ['Yes', 'No'] } // } // }, // // Financial Details // financial_details: { // business_financial_information: { // monthly_income_from_business: Number, // monthly_expense_of_business: Number // }, // loans_and_emis: { // current_loans_emis: String // }, // family_financial_information: { // monthly_family_income: Number, // number_of_working_members: Number, // monthly_family_expense: Number // } // }, // created_at: { type: Date, default: Date.now }, // assigned_at: Date, // accepted_at: Date, // completed_at: Date, // updated_at: { type: Date, default: Date.now }, // remarks: String // }); // // File Schema // const fileSchema = new mongoose.Schema({ // file_id: { type: String, required: true, unique: true }, // case_id: { type: String, required: true }, // filename: { type: String, required: true }, // original_name: { type: String, required: true }, // file_type: { type: String, required: true }, // mime_type: { type: String, required: true }, // file_size: { type: Number, required: true }, // file_data: { type: Buffer, required: true }, // geo_location: { // lat: Number, // lng: Number // }, // uploaded_at: { type: Date, default: Date.now }, // uploaded_by: String // }); // const caseCreationWebhookSchema = new mongoose.Schema({ // webhook_id: { type: String, required: true, unique: true }, // request_data: { type: mongoose.Schema.Types.Mixed, required: true }, // received_at: { type: Date, default: Date.now }, // source_ip: String, // user_agent: String // }); // const CaseCreationWebhook = mongoose.model('CaseCreationWebhook', caseCreationWebhookSchema); // const Admin = mongoose.model('Admin', adminSchema); // const Agent = mongoose.model('Agent', agentSchema); // const Case = mongoose.model('Case', caseSchema); // const File = mongoose.model('File', fileSchema); // module.exports = { connectDB, Admin, Agent, Case, File, CaseCreationWebhook }; const mongoose = require('mongoose'); // Connect to MongoDB const connectDB = async () => { try { await mongoose.connect(process.env.MONGODB_URI); console.log('✅ MongoDB connected successfully'); } catch (error) { console.error('❌ MongoDB connection failed:', error.message); process.exit(1); } }; // Admin Schema const adminSchema = new mongoose.Schema({ admin_id: { type: String, required: true, unique: true }, name: { type: String, required: true }, email: { type: String, required: true, unique: true }, password: { type: String, required: true }, created_at: { type: Date, default: Date.now }, last_login: Date }); // Agent Schema const agentSchema = new mongoose.Schema({ agent_id: { type: String, required: true, unique: true }, agent_name: { type: String, required: true }, agent_email: { type: String, required: true, unique: true }, contact_number: { type: String, required: true }, password: { type: String, required: true }, agency: { type: String, required: true }, status: { type: String, default: 'active', enum: ['active', 'inactive'] }, created_at: { type: Date, default: Date.now }, last_login: Date }); // Case Schema with all sections const caseSchema = new mongoose.Schema({ case_id: { type: String, required: true, unique: true }, application_id: { type: String, default: 'N/A' }, case_applicant_name: { type: String, default: 'N/A' }, case_applicant_contact: { type: String, default: 'N/A' }, address: { type: String, default: 'N/A' }, case_type: { type: String, default: 'Business Loan' }, loan_amount: { type: Number, default: 0 }, priority: { type: String, default: 'MED', enum: ['LOW', 'MED', 'HIGH'] }, assigned_agent: { type: String, default: null }, status: { type: String, default: 'Unassigned', enum: ['Completed', 'In Progress', 'Pending', 'Unassigned'] }, // Legacy fields removed: demographic_details, business_details, financial_details created_at: { type: Date, default: Date.now }, assigned_at: Date, accepted_at: Date, completed_at: Date, updated_at: { type: Date, default: Date.now }, remarks: String, // New fields for UAPMP API integration applicantDetail: { type: mongoose.Schema.Types.Mixed }, residenceDetail: { type: mongoose.Schema.Types.Mixed }, coApplicantDetail: { type: mongoose.Schema.Types.Mixed }, businessDetail: { type: mongoose.Schema.Types.Mixed }, incomeExpenditure: { type: mongoose.Schema.Types.Mixed }, familyExpenses: { type: mongoose.Schema.Types.Mixed }, metaData: { type: mongoose.Schema.Types.Mixed } }, { strict: false }); // File Schema const fileSchema = new mongoose.Schema({ file_id: { type: String, required: true, unique: true }, case_id: { type: String, required: true }, filename: { type: String, required: true }, original_name: { type: String, required: true }, file_type: { type: String, required: true }, mime_type: { type: String, required: true }, file_size: { type: Number, required: true }, file_data: { type: Buffer, required: true }, geo_location: { lat: Number, lng: Number }, uploaded_at: { type: Date, default: Date.now }, uploaded_by: String }); // Case Creation Webhook Schema const caseCreationWebhookSchema = new mongoose.Schema({ webhook_id: { type: String, required: true, unique: true }, request_data: { type: mongoose.Schema.Types.Mixed, required: true }, received_at: { type: Date, default: Date.now }, source_ip: String, user_agent: String }); const CaseCreationWebhook = mongoose.model('CaseCreationWebhook', caseCreationWebhookSchema); const Admin = mongoose.model('Admin', adminSchema); const Agent = mongoose.model('Agent', agentSchema); const Case = mongoose.model('Case', caseSchema); const File = mongoose.model('File', fileSchema); module.exports = { connectDB, Admin, Agent, Case, File, CaseCreationWebhook };