const db = require('../models'); const Users = db.users; const Communications = db.communications; const Leads = db.leads; const Reports = db.reports; const Firms = db.firms; const CommunicationsData = [ { // type code here for "relation_one" field message: 'Initial contact made via phone.', communication_type: 'sms', timestamp: new Date('2023-10-01T10:30:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field message: 'Email sent to client for more details.', communication_type: 'sms', timestamp: new Date('2023-10-02T11:30:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field message: 'SMS reminder sent for document submission.', communication_type: 'sms', timestamp: new Date('2023-10-03T12:30:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field message: 'Follow-up call scheduled.', communication_type: 'sms', timestamp: new Date('2023-10-04T13:30:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field message: 'Client emailed additional photos.', communication_type: 'sms', timestamp: new Date('2023-10-05T14:30:00Z'), // type code here for "relation_one" field }, ]; const LeadsData = [ { client_name: 'John Smith', incident_details: 'Car accident on Main St.', accident_type: 'personal_injury', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field status: 'case_rejected', // type code here for "relation_one" field }, { client_name: 'Jane Doe', incident_details: 'Slip and fall at work.', accident_type: 'workers_compensation', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field status: 'assigned', // type code here for "relation_one" field }, { client_name: 'Bob Johnson', incident_details: 'Bicycle accident in park.', accident_type: 'personal_injury', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field status: 'new_lead', // type code here for "relation_one" field }, { client_name: 'Alice Brown', incident_details: 'Workplace machinery injury.', accident_type: 'personal_injury', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field status: 'assigned', // type code here for "relation_one" field }, { client_name: 'Charlie Green', incident_details: 'Dog bite incident.', accident_type: 'personal_injury', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field status: 'new_lead', // type code here for "relation_one" field }, ]; const ReportsData = [ { title: 'Monthly Lead Overview', // type code here for "relation_many" field generated_at: new Date('2023-10-06T15:00:00Z'), // type code here for "relation_one" field }, { title: 'Weekly Performance Report', // type code here for "relation_many" field generated_at: new Date('2023-10-07T16:00:00Z'), // type code here for "relation_one" field }, { title: 'Case Conversion Analysis', // type code here for "relation_many" field generated_at: new Date('2023-10-08T17:00:00Z'), // type code here for "relation_one" field }, { title: 'Lead Source Breakdown', // type code here for "relation_many" field generated_at: new Date('2023-10-09T18:00:00Z'), // type code here for "relation_one" field }, { title: 'Lawyer Assignment Efficiency', // type code here for "relation_many" field generated_at: new Date('2023-10-10T19:00:00Z'), // type code here for "relation_one" field }, ]; const FirmsData = [ { name: 'Law & Order LLC', }, { name: 'Legal Eagles', }, { name: 'Injury Advocates', }, { name: "Workers' Rights Group", }, { name: 'Accident Attorneys', }, ]; // Similar logic for "relation_many" async function associateUserWithFirm() { const relatedFirm0 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setFirm) { await User0.setFirm(relatedFirm0); } const relatedFirm1 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setFirm) { await User1.setFirm(relatedFirm1); } const relatedFirm2 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setFirm) { await User2.setFirm(relatedFirm2); } const relatedFirm3 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setFirm) { await User3.setFirm(relatedFirm3); } const relatedFirm4 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setFirm) { await User4.setFirm(relatedFirm4); } } async function associateCommunicationWithLead() { const relatedLead0 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Communication0 = await Communications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Communication0?.setLead) { await Communication0.setLead(relatedLead0); } const relatedLead1 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Communication1 = await Communications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Communication1?.setLead) { await Communication1.setLead(relatedLead1); } const relatedLead2 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Communication2 = await Communications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Communication2?.setLead) { await Communication2.setLead(relatedLead2); } const relatedLead3 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Communication3 = await Communications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Communication3?.setLead) { await Communication3.setLead(relatedLead3); } const relatedLead4 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Communication4 = await Communications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Communication4?.setLead) { await Communication4.setLead(relatedLead4); } } async function associateCommunicationWithFirm() { const relatedFirm0 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Communication0 = await Communications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Communication0?.setFirm) { await Communication0.setFirm(relatedFirm0); } const relatedFirm1 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Communication1 = await Communications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Communication1?.setFirm) { await Communication1.setFirm(relatedFirm1); } const relatedFirm2 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Communication2 = await Communications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Communication2?.setFirm) { await Communication2.setFirm(relatedFirm2); } const relatedFirm3 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Communication3 = await Communications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Communication3?.setFirm) { await Communication3.setFirm(relatedFirm3); } const relatedFirm4 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Communication4 = await Communications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Communication4?.setFirm) { await Communication4.setFirm(relatedFirm4); } } async function associateLeadWithAssigned_lawyer() { const relatedAssigned_lawyer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lead0?.setAssigned_lawyer) { await Lead0.setAssigned_lawyer(relatedAssigned_lawyer0); } const relatedAssigned_lawyer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lead1?.setAssigned_lawyer) { await Lead1.setAssigned_lawyer(relatedAssigned_lawyer1); } const relatedAssigned_lawyer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lead2?.setAssigned_lawyer) { await Lead2.setAssigned_lawyer(relatedAssigned_lawyer2); } const relatedAssigned_lawyer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead3 = await Leads.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Lead3?.setAssigned_lawyer) { await Lead3.setAssigned_lawyer(relatedAssigned_lawyer3); } const relatedAssigned_lawyer4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead4 = await Leads.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Lead4?.setAssigned_lawyer) { await Lead4.setAssigned_lawyer(relatedAssigned_lawyer4); } } async function associateLeadWithIntake_specialist() { const relatedIntake_specialist0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lead0?.setIntake_specialist) { await Lead0.setIntake_specialist(relatedIntake_specialist0); } const relatedIntake_specialist1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lead1?.setIntake_specialist) { await Lead1.setIntake_specialist(relatedIntake_specialist1); } const relatedIntake_specialist2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lead2?.setIntake_specialist) { await Lead2.setIntake_specialist(relatedIntake_specialist2); } const relatedIntake_specialist3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead3 = await Leads.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Lead3?.setIntake_specialist) { await Lead3.setIntake_specialist(relatedIntake_specialist3); } const relatedIntake_specialist4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead4 = await Leads.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Lead4?.setIntake_specialist) { await Lead4.setIntake_specialist(relatedIntake_specialist4); } } async function associateLeadWithFirm() { const relatedFirm0 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lead0?.setFirm) { await Lead0.setFirm(relatedFirm0); } const relatedFirm1 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lead1?.setFirm) { await Lead1.setFirm(relatedFirm1); } const relatedFirm2 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lead2?.setFirm) { await Lead2.setFirm(relatedFirm2); } const relatedFirm3 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead3 = await Leads.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Lead3?.setFirm) { await Lead3.setFirm(relatedFirm3); } const relatedFirm4 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead4 = await Leads.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Lead4?.setFirm) { await Lead4.setFirm(relatedFirm4); } } async function associateLeadWithFirm() { const relatedFirm0 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lead0?.setFirm) { await Lead0.setFirm(relatedFirm0); } const relatedFirm1 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lead1?.setFirm) { await Lead1.setFirm(relatedFirm1); } const relatedFirm2 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lead2?.setFirm) { await Lead2.setFirm(relatedFirm2); } const relatedFirm3 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead3 = await Leads.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Lead3?.setFirm) { await Lead3.setFirm(relatedFirm3); } const relatedFirm4 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Lead4 = await Leads.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Lead4?.setFirm) { await Lead4.setFirm(relatedFirm4); } } // Similar logic for "relation_many" async function associateReportWithFirm() { const relatedFirm0 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Report0 = await Reports.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Report0?.setFirm) { await Report0.setFirm(relatedFirm0); } const relatedFirm1 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Report1 = await Reports.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Report1?.setFirm) { await Report1.setFirm(relatedFirm1); } const relatedFirm2 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Report2 = await Reports.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Report2?.setFirm) { await Report2.setFirm(relatedFirm2); } const relatedFirm3 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Report3 = await Reports.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Report3?.setFirm) { await Report3.setFirm(relatedFirm3); } const relatedFirm4 = await Firms.findOne({ offset: Math.floor(Math.random() * (await Firms.count())), }); const Report4 = await Reports.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Report4?.setFirm) { await Report4.setFirm(relatedFirm4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Communications.bulkCreate(CommunicationsData); await Leads.bulkCreate(LeadsData); await Reports.bulkCreate(ReportsData); await Firms.bulkCreate(FirmsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithFirm(), await associateCommunicationWithLead(), await associateCommunicationWithFirm(), await associateLeadWithAssigned_lawyer(), await associateLeadWithIntake_specialist(), await associateLeadWithFirm(), await associateLeadWithFirm(), // Similar logic for "relation_many" await associateReportWithFirm(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('communications', null, {}); await queryInterface.bulkDelete('leads', null, {}); await queryInterface.bulkDelete('reports', null, {}); await queryInterface.bulkDelete('firms', null, {}); }, };