39658-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-04-15 16:15:09 +00:00

5003 lines
99 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const LeadSources = db.lead_sources;
const Leads = db.leads;
const Accounts = db.accounts;
const Contacts = db.contacts;
const DealStages = db.deal_stages;
const Deals = db.deals;
const Activities = db.activities;
const Tasks = db.tasks;
const LeadSourcesData = [
{
"name": "Website Form",
"description": "Inbound submissions from the marketing site contact form",
"is_active": true,
},
{
"name": "Referral",
"description": "Introductions from customers and partners",
"is_active": true,
},
{
"name": "LinkedIn Outreach",
"description": "Prospecting and direct messages on LinkedIn",
"is_active": true,
},
{
"name": "Conference Booth",
"description": "Badge scans and conversations from events",
"is_active": true,
},
{
"name": "Outbound Email",
"description": "Cold email sequences and replies",
"is_active": true,
},
];
const LeadsData = [
{
"first_name": "Jordan",
"last_name": "Lee",
"company": "Summit Retail Co",
"job_title": "Marketing Lead",
"email": "jordan.lee@summitretail.co",
"phone": "+1 408 555 0171",
"website": "https://summitretail.co",
"address": "San Jose, CA",
"status": "contacted",
"rating": "cold",
"estimated_value": 12000.5,
// type code here for "relation_one" field
// type code here for "relation_one" field
"last_contacted_at": new Date('2026-03-30T16:10:00Z'),
"next_follow_up_at": new Date('2026-04-18T16:00:00Z'),
"notes": "Requested pricing for small team plan",
},
{
"first_name": "Hannah",
"last_name": "Moore",
"company": "Atlas Property Group",
"job_title": "Operations Manager",
"email": "hannah.moore@atlaspropertygroup.com",
"phone": "+1 702 555 0146",
"website": "https://atlaspropertygroup.com",
"address": "Las Vegas, NV",
"status": "converted",
"rating": "hot",
"estimated_value": 28000,
// type code here for "relation_one" field
// type code here for "relation_one" field
"last_contacted_at": new Date('2026-04-02T19:20:00Z'),
"next_follow_up_at": new Date('2026-04-17T18:00:00Z'),
"notes": "Open to a quick demo next week",
},
{
"first_name": "Omar",
"last_name": "Singh",
"company": "BlueHarbor Financial",
"job_title": "Business Analyst",
"email": "omar.singh@blueharborfinancial.com",
"phone": "+1 617 555 0199",
"website": "https://blueharborfinancial.com",
"address": "Cambridge, MA",
"status": "contacted",
"rating": "warm",
"estimated_value": 45000,
// type code here for "relation_one" field
// type code here for "relation_one" field
"last_contacted_at": new Date('2026-04-05T15:00:00Z'),
"next_follow_up_at": new Date('2026-04-19T15:00:00Z'),
"notes": "Interested in pipeline reporting for managers",
},
{
"first_name": "Chloe",
"last_name": "Bennett",
"company": "Kinetic Manufacturing",
"job_title": "Sales Coordinator",
"email": "chloe.bennett@kineticmfg.com",
"phone": "+1 216 555 0136",
"website": "https://kineticmfg.com",
"address": "Cleveland, OH",
"status": "unqualified",
"rating": "hot",
"estimated_value": 9000,
// type code here for "relation_one" field
// type code here for "relation_one" field
"last_contacted_at": new Date('2026-04-01T14:30:00Z'),
"next_follow_up_at": new Date('2026-04-22T14:00:00Z'),
"notes": "Needs approval from sales director",
},
{
"first_name": "Diego",
"last_name": "Alvarez",
"company": "Greenline Energy",
"job_title": "Partnerships",
"email": "diego.alvarez@greenlineenergy.com",
"phone": "+1 713 555 0111",
"website": "https://greenlineenergy.com",
"address": "Houston, TX",
"status": "lost",
"rating": "hot",
"estimated_value": 32000,
// type code here for "relation_one" field
// type code here for "relation_one" field
"last_contacted_at": new Date('2026-04-06T17:05:00Z'),
"next_follow_up_at": new Date('2026-04-20T17:00:00Z'),
"notes": "Met at conference booth, asked for case study",
},
];
const AccountsData = [
{
"name": "BrightPeak Logistics",
"domain": "brightpeaklogistics.com",
"industry": "Logistics",
"size": "201-500",
"phone": "+1 303 555 0164",
"website": "https://brightpeaklogistics.com",
"billing_address": "1100 Wynkoop St, Denver, CO",
"shipping_address": "1100 Wynkoop St, Denver, CO",
// type code here for "relation_one" field
"notes": "Evaluating CRM integration with their TMS",
},
{
"name": "Cedar & Stone Construction",
"domain": "cedarstonebuild.com",
"industry": "Construction",
"size": "51-200",
"phone": "+1 512 555 0128",
"website": "https://cedarstonebuild.com",
"billing_address": "220 Congress Ave, Austin, TX",
"shipping_address": "2450 E Ben White Blvd, Austin, TX",
// type code here for "relation_one" field
"notes": "Interested in reporting and mobile access",
},
{
"name": "HelioHealth Clinics",
"domain": "heliohealthclinics.com",
"industry": "Healthcare",
"size": "501-1000",
"phone": "+1 617 555 0176",
"website": "https://heliohealthclinics.com",
"billing_address": "75 State St, Boston, MA",
"shipping_address": "75 State St, Boston, MA",
// type code here for "relation_one" field
"notes": "Security review required before rollout",
},
{
"name": "NimbusHR Software",
"domain": "nimbushr.io",
"industry": "Software",
"size": "11-50",
"phone": "+1 415 555 0121",
"website": "https://nimbushr.io",
"billing_address": "550 Market St, San Francisco, CA",
"shipping_address": "550 Market St, San Francisco, CA",
// type code here for "relation_one" field
"notes": "Small team, fast sales cycle",
},
{
"name": "Riverbend University",
"domain": "riverbend.edu",
"industry": "Education",
"size": "1001-5000",
"phone": "+1 919 555 0182",
"website": "https://riverbend.edu",
"billing_address": "1 College Way, Raleigh, NC",
"shipping_address": "1 College Way, Raleigh, NC",
// type code here for "relation_one" field
"notes": "Procurement process is formal and time-bound",
},
];
const ContactsData = [
{
"first_name": "Priya",
"last_name": "Nair",
"full_name": "Priya Nair",
"email": "priya.nair@brightpeaklogistics.com",
"phone": "+1 303 555 0102",
"job_title": "Operations Director",
// type code here for "relation_one" field
// type code here for "relation_one" field
"lifecycle_stage": "lead",
"address": "Denver, CO",
"last_contacted_at": new Date('2026-03-20T16:00:00Z'),
"notes": "Wants visibility into team activity and follow-ups",
},
{
"first_name": "Marcus",
"last_name": "Reed",
"full_name": "Marcus Reed",
"email": "marcus.reed@cedarstonebuild.com",
"phone": "+1 512 555 0109",
"job_title": "IT Manager",
// type code here for "relation_one" field
// type code here for "relation_one" field
"lifecycle_stage": "customer",
"address": "Austin, TX",
"last_contacted_at": new Date('2026-03-22T18:30:00Z'),
"notes": "Asked for SSO and audit logging details",
},
{
"first_name": "Elena",
"last_name": "Vasquez",
"full_name": "Elena Vasquez",
"email": "elena.vasquez@heliohealthclinics.com",
"phone": "+1 617 555 0118",
"job_title": "VP of Patient Services",
// type code here for "relation_one" field
// type code here for "relation_one" field
"lifecycle_stage": "former_customer",
"address": "Boston, MA",
"last_contacted_at": new Date('2026-03-25T14:15:00Z'),
"notes": "Interested in workflow automation and reminders",
},
{
"first_name": "Noah",
"last_name": "Fischer",
"full_name": "Noah Fischer",
"email": "noah.fischer@nimbushr.io",
"phone": "+1 415 555 0158",
"job_title": "Head of Sales",
// type code here for "relation_one" field
// type code here for "relation_one" field
"lifecycle_stage": "former_customer",
"address": "San Francisco, CA",
"last_contacted_at": new Date('2026-03-28T17:45:00Z'),
"notes": "Renewal planning for next quarter",
},
{
"first_name": "Grace",
"last_name": "Olsen",
"full_name": "Grace Olsen",
"email": "grace.olsen@riverbend.edu",
"phone": "+1 919 555 0139",
"job_title": "Procurement Specialist",
// type code here for "relation_one" field
// type code here for "relation_one" field
"lifecycle_stage": "prospect",
"address": "Raleigh, NC",
"last_contacted_at": new Date('2026-03-26T13:00:00Z'),
"notes": "Needs W-9 and vendor onboarding packet",
},
];
const DealStagesData = [
{
"name": "Qualification",
"sort_order": 1,
"is_won": true,
"is_lost": true,
"is_active": true,
},
{
"name": "Discovery",
"sort_order": 2,
"is_won": false,
"is_lost": true,
"is_active": true,
},
{
"name": "Proposal",
"sort_order": 3,
"is_won": true,
"is_lost": false,
"is_active": true,
},
{
"name": "Negotiation",
"sort_order": 4,
"is_won": true,
"is_lost": true,
"is_active": true,
},
{
"name": "Closed Won",
"sort_order": 5,
"is_won": true,
"is_lost": false,
"is_active": true,
},
];
const DealsData = [
{
"name": "BrightPeak Team CRM Rollout",
"amount": 42000,
"currency": "USD",
"probability": 60,
"expected_close_at": new Date('2026-05-10T00:00:00Z'),
"closed_at": new Date('2026-05-10T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"deal_status": "open",
"loss_reason": "",
"description": "Pilot for operations and sales coordination",
},
{
"name": "Cedar & Stone Reporting Upgrade",
"amount": 18000,
"currency": "USD",
"probability": 50,
"expected_close_at": new Date('2026-05-20T00:00:00Z'),
"closed_at": new Date('2026-05-20T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"deal_status": "won",
"loss_reason": "",
"description": "Add advanced reporting and activity tracking",
},
{
"name": "HelioHealth Security Reviewed Purchase",
"amount": 95000,
"currency": "USD",
"probability": 40,
"expected_close_at": new Date('2026-06-15T00:00:00Z'),
"closed_at": new Date('2026-06-15T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"deal_status": "won",
"loss_reason": "",
"description": "Enterprise rollout pending security review",
},
{
"name": "NimbusHR Renewal Q3",
"amount": 24000,
"currency": "USD",
"probability": 80,
"expected_close_at": new Date('2026-04-30T00:00:00Z'),
"closed_at": new Date('2026-04-30T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"deal_status": "open",
"loss_reason": "",
"description": "Annual renewal with expanded seats",
},
{
"name": "Riverbend Vendor Onboarding",
"amount": 60000,
"currency": "USD",
"probability": 35,
"expected_close_at": new Date('2026-06-30T00:00:00Z'),
"closed_at": new Date('2026-06-30T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"deal_status": "lost",
"loss_reason": "",
"description": "Procurement driven timeline with onboarding docs",
},
];
const ActivitiesData = [
{
"activity_type": "call",
"direction": "outbound",
"occurred_at": new Date('2026-04-08T16:00:00Z'),
"next_step_at": new Date('2026-04-17T16:00:00Z'),
"outcome": "follow_up_needed",
"subject": "Discovery call with BrightPeak",
"summary": "Discussed current process and pain points; agreed to send integration overview",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
},
{
"activity_type": "call",
"direction": "inbound",
"occurred_at": new Date('2026-04-09T13:30:00Z'),
"next_step_at": new Date('2026-04-18T13:30:00Z'),
"outcome": "not_interested",
"subject": "SSO and audit logging details",
"summary": "Sent documentation and offered to loop in security team",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
},
{
"activity_type": "demo",
"direction": "inbound",
"occurred_at": new Date('2026-04-10T15:00:00Z'),
"next_step_at": new Date('2026-04-19T15:00:00Z'),
"outcome": "no_answer",
"subject": "HelioHealth workflow review",
"summary": "Reviewed reminder workflows and reporting needs; awaiting security questionnaire",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
},
{
"activity_type": "note",
"direction": "outbound",
"occurred_at": new Date('2026-04-11T17:20:00Z'),
"next_step_at": new Date('2026-04-18T17:00:00Z'),
"outcome": "not_interested",
"subject": "NimbusHR renewal check-in",
"summary": "Confirmed renewal terms; scheduled final sign-off meeting",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
},
{
"activity_type": "email",
"direction": "outbound",
"occurred_at": new Date('2026-04-12T14:10:00Z'),
"next_step_at": new Date('2026-04-22T14:00:00Z'),
"outcome": "not_interested",
"subject": "Vendor packet for Riverbend",
"summary": "Sent W-9 and onboarding packet; requested timeline for committee review",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
},
];
const TasksData = [
{
"title": "Send BrightPeak integration overview",
"description": "Email integration outline and confirm next meeting attendees",
"task_type": "email",
"priority": "high",
"status": "completed",
"due_at": new Date('2026-04-17T16:00:00Z'),
"completed_at": new Date('2020-01-01T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Schedule Cedar & Stone security review",
"description": "Coordinate 30-minute call with IT and manager",
"task_type": "call",
"priority": "urgent",
"status": "open",
"due_at": new Date('2026-04-18T13:30:00Z'),
"completed_at": new Date('2020-01-01T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Complete HelioHealth security questionnaire",
"description": "Gather required compliance answers and return the form",
"task_type": "to_do",
"priority": "urgent",
"status": "in_progress",
"due_at": new Date('2026-04-19T15:00:00Z'),
"completed_at": new Date('2020-01-01T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Prepare NimbusHR renewal order form",
"description": "Generate order form and route for signature",
"task_type": "email",
"priority": "low",
"status": "canceled",
"due_at": new Date('2026-04-18T17:00:00Z'),
"completed_at": new Date('2026-04-16T12:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Follow up on Riverbend procurement timeline",
"description": "Ask for committee dates and any missing vendor items",
"task_type": "email",
"priority": "high",
"status": "completed",
"due_at": new Date('2026-04-22T14:00:00Z'),
"completed_at": new Date('2020-01-01T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
async function associateLeadWithSource() {
const relatedSource0 = await LeadSources.findOne({
offset: Math.floor(Math.random() * (await LeadSources.count())),
});
const Lead0 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Lead0?.setSource)
{
await
Lead0.
setSource(relatedSource0);
}
const relatedSource1 = await LeadSources.findOne({
offset: Math.floor(Math.random() * (await LeadSources.count())),
});
const Lead1 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Lead1?.setSource)
{
await
Lead1.
setSource(relatedSource1);
}
const relatedSource2 = await LeadSources.findOne({
offset: Math.floor(Math.random() * (await LeadSources.count())),
});
const Lead2 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Lead2?.setSource)
{
await
Lead2.
setSource(relatedSource2);
}
const relatedSource3 = await LeadSources.findOne({
offset: Math.floor(Math.random() * (await LeadSources.count())),
});
const Lead3 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Lead3?.setSource)
{
await
Lead3.
setSource(relatedSource3);
}
const relatedSource4 = await LeadSources.findOne({
offset: Math.floor(Math.random() * (await LeadSources.count())),
});
const Lead4 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Lead4?.setSource)
{
await
Lead4.
setSource(relatedSource4);
}
}
async function associateLeadWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Lead0 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Lead0?.setOwner)
{
await
Lead0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Lead1 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Lead1?.setOwner)
{
await
Lead1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Lead2 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Lead2?.setOwner)
{
await
Lead2.
setOwner(relatedOwner2);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Lead3 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Lead3?.setOwner)
{
await
Lead3.
setOwner(relatedOwner3);
}
const relatedOwner4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Lead4 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Lead4?.setOwner)
{
await
Lead4.
setOwner(relatedOwner4);
}
}
async function associateAccountWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Account0 = await Accounts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Account0?.setOwner)
{
await
Account0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Account1 = await Accounts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Account1?.setOwner)
{
await
Account1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Account2 = await Accounts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Account2?.setOwner)
{
await
Account2.
setOwner(relatedOwner2);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Account3 = await Accounts.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Account3?.setOwner)
{
await
Account3.
setOwner(relatedOwner3);
}
const relatedOwner4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Account4 = await Accounts.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Account4?.setOwner)
{
await
Account4.
setOwner(relatedOwner4);
}
}
async function associateContactWithAccount() {
const relatedAccount0 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Contact0 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Contact0?.setAccount)
{
await
Contact0.
setAccount(relatedAccount0);
}
const relatedAccount1 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Contact1 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Contact1?.setAccount)
{
await
Contact1.
setAccount(relatedAccount1);
}
const relatedAccount2 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Contact2 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Contact2?.setAccount)
{
await
Contact2.
setAccount(relatedAccount2);
}
const relatedAccount3 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Contact3 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Contact3?.setAccount)
{
await
Contact3.
setAccount(relatedAccount3);
}
const relatedAccount4 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Contact4 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Contact4?.setAccount)
{
await
Contact4.
setAccount(relatedAccount4);
}
}
async function associateContactWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Contact0 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Contact0?.setOwner)
{
await
Contact0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Contact1 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Contact1?.setOwner)
{
await
Contact1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Contact2 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Contact2?.setOwner)
{
await
Contact2.
setOwner(relatedOwner2);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Contact3 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Contact3?.setOwner)
{
await
Contact3.
setOwner(relatedOwner3);
}
const relatedOwner4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Contact4 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Contact4?.setOwner)
{
await
Contact4.
setOwner(relatedOwner4);
}
}
async function associateDealWithStage() {
const relatedStage0 = await DealStages.findOne({
offset: Math.floor(Math.random() * (await DealStages.count())),
});
const Deal0 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Deal0?.setStage)
{
await
Deal0.
setStage(relatedStage0);
}
const relatedStage1 = await DealStages.findOne({
offset: Math.floor(Math.random() * (await DealStages.count())),
});
const Deal1 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Deal1?.setStage)
{
await
Deal1.
setStage(relatedStage1);
}
const relatedStage2 = await DealStages.findOne({
offset: Math.floor(Math.random() * (await DealStages.count())),
});
const Deal2 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Deal2?.setStage)
{
await
Deal2.
setStage(relatedStage2);
}
const relatedStage3 = await DealStages.findOne({
offset: Math.floor(Math.random() * (await DealStages.count())),
});
const Deal3 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Deal3?.setStage)
{
await
Deal3.
setStage(relatedStage3);
}
const relatedStage4 = await DealStages.findOne({
offset: Math.floor(Math.random() * (await DealStages.count())),
});
const Deal4 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Deal4?.setStage)
{
await
Deal4.
setStage(relatedStage4);
}
}
async function associateDealWithPrimary_contact() {
const relatedPrimary_contact0 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Deal0 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Deal0?.setPrimary_contact)
{
await
Deal0.
setPrimary_contact(relatedPrimary_contact0);
}
const relatedPrimary_contact1 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Deal1 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Deal1?.setPrimary_contact)
{
await
Deal1.
setPrimary_contact(relatedPrimary_contact1);
}
const relatedPrimary_contact2 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Deal2 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Deal2?.setPrimary_contact)
{
await
Deal2.
setPrimary_contact(relatedPrimary_contact2);
}
const relatedPrimary_contact3 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Deal3 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Deal3?.setPrimary_contact)
{
await
Deal3.
setPrimary_contact(relatedPrimary_contact3);
}
const relatedPrimary_contact4 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Deal4 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Deal4?.setPrimary_contact)
{
await
Deal4.
setPrimary_contact(relatedPrimary_contact4);
}
}
async function associateDealWithAccount() {
const relatedAccount0 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Deal0 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Deal0?.setAccount)
{
await
Deal0.
setAccount(relatedAccount0);
}
const relatedAccount1 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Deal1 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Deal1?.setAccount)
{
await
Deal1.
setAccount(relatedAccount1);
}
const relatedAccount2 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Deal2 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Deal2?.setAccount)
{
await
Deal2.
setAccount(relatedAccount2);
}
const relatedAccount3 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Deal3 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Deal3?.setAccount)
{
await
Deal3.
setAccount(relatedAccount3);
}
const relatedAccount4 = await Accounts.findOne({
offset: Math.floor(Math.random() * (await Accounts.count())),
});
const Deal4 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Deal4?.setAccount)
{
await
Deal4.
setAccount(relatedAccount4);
}
}
async function associateDealWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Deal0 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Deal0?.setOwner)
{
await
Deal0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Deal1 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Deal1?.setOwner)
{
await
Deal1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Deal2 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Deal2?.setOwner)
{
await
Deal2.
setOwner(relatedOwner2);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Deal3 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Deal3?.setOwner)
{
await
Deal3.
setOwner(relatedOwner3);
}
const relatedOwner4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Deal4 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Deal4?.setOwner)
{
await
Deal4.
setOwner(relatedOwner4);
}
}
async function associateActivityWithContact() {
const relatedContact0 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Activity0?.setContact)
{
await
Activity0.
setContact(relatedContact0);
}
const relatedContact1 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Activity1?.setContact)
{
await
Activity1.
setContact(relatedContact1);
}
const relatedContact2 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Activity2?.setContact)
{
await
Activity2.
setContact(relatedContact2);
}
const relatedContact3 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Activity3?.setContact)
{
await
Activity3.
setContact(relatedContact3);
}
const relatedContact4 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Activity4?.setContact)
{
await
Activity4.
setContact(relatedContact4);
}
}
async function associateActivityWithDeal() {
const relatedDeal0 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Activity0?.setDeal)
{
await
Activity0.
setDeal(relatedDeal0);
}
const relatedDeal1 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Activity1?.setDeal)
{
await
Activity1.
setDeal(relatedDeal1);
}
const relatedDeal2 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Activity2?.setDeal)
{
await
Activity2.
setDeal(relatedDeal2);
}
const relatedDeal3 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Activity3?.setDeal)
{
await
Activity3.
setDeal(relatedDeal3);
}
const relatedDeal4 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Activity4?.setDeal)
{
await
Activity4.
setDeal(relatedDeal4);
}
}
async function associateActivityWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Activity0?.setLead)
{
await
Activity0.
setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Activity1?.setLead)
{
await
Activity1.
setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Activity2?.setLead)
{
await
Activity2.
setLead(relatedLead2);
}
const relatedLead3 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Activity3?.setLead)
{
await
Activity3.
setLead(relatedLead3);
}
const relatedLead4 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Activity4?.setLead)
{
await
Activity4.
setLead(relatedLead4);
}
}
async function associateActivityWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Activity0?.setOwner)
{
await
Activity0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Activity1?.setOwner)
{
await
Activity1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Activity2?.setOwner)
{
await
Activity2.
setOwner(relatedOwner2);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Activity3?.setOwner)
{
await
Activity3.
setOwner(relatedOwner3);
}
const relatedOwner4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Activity4?.setOwner)
{
await
Activity4.
setOwner(relatedOwner4);
}
}
async function associateTaskWithAssignee() {
const relatedAssignee0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Task0?.setAssignee)
{
await
Task0.
setAssignee(relatedAssignee0);
}
const relatedAssignee1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Task1?.setAssignee)
{
await
Task1.
setAssignee(relatedAssignee1);
}
const relatedAssignee2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Task2?.setAssignee)
{
await
Task2.
setAssignee(relatedAssignee2);
}
const relatedAssignee3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Task3?.setAssignee)
{
await
Task3.
setAssignee(relatedAssignee3);
}
const relatedAssignee4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task4 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Task4?.setAssignee)
{
await
Task4.
setAssignee(relatedAssignee4);
}
}
async function associateTaskWithContact() {
const relatedContact0 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Task0?.setContact)
{
await
Task0.
setContact(relatedContact0);
}
const relatedContact1 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Task1?.setContact)
{
await
Task1.
setContact(relatedContact1);
}
const relatedContact2 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Task2?.setContact)
{
await
Task2.
setContact(relatedContact2);
}
const relatedContact3 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Task3?.setContact)
{
await
Task3.
setContact(relatedContact3);
}
const relatedContact4 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const Task4 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Task4?.setContact)
{
await
Task4.
setContact(relatedContact4);
}
}
async function associateTaskWithDeal() {
const relatedDeal0 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Task0?.setDeal)
{
await
Task0.
setDeal(relatedDeal0);
}
const relatedDeal1 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Task1?.setDeal)
{
await
Task1.
setDeal(relatedDeal1);
}
const relatedDeal2 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Task2?.setDeal)
{
await
Task2.
setDeal(relatedDeal2);
}
const relatedDeal3 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Task3?.setDeal)
{
await
Task3.
setDeal(relatedDeal3);
}
const relatedDeal4 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Task4 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Task4?.setDeal)
{
await
Task4.
setDeal(relatedDeal4);
}
}
async function associateTaskWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Task0?.setLead)
{
await
Task0.
setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Task1?.setLead)
{
await
Task1.
setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Task2?.setLead)
{
await
Task2.
setLead(relatedLead2);
}
const relatedLead3 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Task3?.setLead)
{
await
Task3.
setLead(relatedLead3);
}
const relatedLead4 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Task4 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Task4?.setLead)
{
await
Task4.
setLead(relatedLead4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await LeadSources.bulkCreate(LeadSourcesData);
await Leads.bulkCreate(LeadsData);
await Accounts.bulkCreate(AccountsData);
await Contacts.bulkCreate(ContactsData);
await DealStages.bulkCreate(DealStagesData);
await Deals.bulkCreate(DealsData);
await Activities.bulkCreate(ActivitiesData);
await Tasks.bulkCreate(TasksData);
await Promise.all([
// Similar logic for "relation_many"
await associateLeadWithSource(),
await associateLeadWithOwner(),
await associateAccountWithOwner(),
await associateContactWithAccount(),
await associateContactWithOwner(),
await associateDealWithStage(),
await associateDealWithPrimary_contact(),
await associateDealWithAccount(),
await associateDealWithOwner(),
await associateActivityWithContact(),
await associateActivityWithDeal(),
await associateActivityWithLead(),
await associateActivityWithOwner(),
await associateTaskWithAssignee(),
await associateTaskWithContact(),
await associateTaskWithDeal(),
await associateTaskWithLead(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('lead_sources', null, {});
await queryInterface.bulkDelete('leads', null, {});
await queryInterface.bulkDelete('accounts', null, {});
await queryInterface.bulkDelete('contacts', null, {});
await queryInterface.bulkDelete('deal_stages', null, {});
await queryInterface.bulkDelete('deals', null, {});
await queryInterface.bulkDelete('activities', null, {});
await queryInterface.bulkDelete('tasks', null, {});
},
};