37742-vm/backend/src/db/seeders/20231127130745-sample-data.js
Flatlogic Bot d4a5e6b45c v1
2026-01-23 12:14:34 +00:00

2495 lines
48 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const PipelineStages = db.pipeline_stages;
const Leads = db.leads;
const Contacts = db.contacts;
const Deals = db.deals;
const Activities = db.activities;
const PipelineStagesData = [
{
"title": "Qualification",
"order": 1,
"probability": 20,
"is_default": true,
},
{
"title": "Proposal",
"order": 2,
"probability": 50,
"is_default": false,
},
{
"title": "Negotiation",
"order": 3,
"probability": 70,
"is_default": true,
},
{
"title": "Closed Won",
"order": 4,
"probability": 100,
"is_default": false,
},
{
"title": "Closed Lost",
"order": 5,
"probability": 0,
"is_default": true,
},
];
const LeadsData = [
{
"name": "Emma Stone",
"company": "BrightWave Solutions",
"email": "emma.stone@brightwave.com",
"phone": "+1-415-555-0201",
"source": "Referral",
"status": "Contacted",
// type code here for "relation_one" field
"estimated_value": 7500.0,
"notes": "Requested demo and pricing details for Q2 rollout.",
},
{
"name": "Liam Chen",
"company": "Apex Retail",
"email": "liam.chen@apexretail.com",
"phone": "+1-415-555-0202",
"source": "SocialMedia",
"status": "New",
// type code here for "relation_one" field
"estimated_value": 42000.0,
"notes": "Referred by partner; interested in multi-store license.",
},
{
"name": "Olivia Martinez",
"company": "GreenFields Agri",
"email": "olivia.martinez@greenfields.com",
"phone": "+1-415-555-0203",
"source": "SocialMedia",
"status": "Contacted",
// type code here for "relation_one" field
"estimated_value": 18000.0,
"notes": "Budget approved; evaluating implementation timeline.",
},
{
"name": "Noah Patel",
"company": "VoltTech",
"email": "noah.patel@volttech.io",
"phone": "+1-415-555-0204",
"source": "Website",
"status": "Unqualified",
// type code here for "relation_one" field
"estimated_value": 0.0,
"notes": "Not a fit due to product constraints at this time.",
},
{
"name": "Ava Johnson",
"company": "Blue Harbor Media",
"email": "ava.johnson@blueharbor.com",
"phone": "+1-415-555-0205",
"source": "ColdCall",
"status": "New",
// type code here for "relation_one" field
"estimated_value": 9600.0,
"notes": "Requested case studies and reference customers.",
},
];
const ContactsData = [
{
"name": "Daniel Kim",
"email": "daniel.kim@brightwave.com",
"phone": "+1-415-555-0301",
"title": "Head of Operations",
"company": "BrightWave Solutions",
// type code here for "relation_one" field
"notes": "Primary contact for implementation discussions.",
},
{
"name": "Maya Singh",
"email": "maya.singh@apexretail.com",
"phone": "+1-415-555-0302",
"title": "Procurement Manager",
"company": "Apex Retail",
// type code here for "relation_one" field
"notes": "Handles contracts and procurement approvals.",
},
{
"name": "Carlos Gomez",
"email": "carlos.gomez@greenfields.com",
"phone": "+1-415-555-0303",
"title": "IT Director",
"company": "GreenFields Agri",
// type code here for "relation_one" field
"notes": "Interested in integration details and API support.",
},
{
"name": "Hannah Park",
"email": "hannah.park@volttech.io",
"phone": "+1-415-555-0304",
"title": "CTO",
"company": "VoltTech",
// type code here for "relation_one" field
"notes": "Decided not to pursue due to competing priorities.",
},
{
"name": "Ethan Brooks",
"email": "ethan.brooks@blueharbor.com",
"phone": "+1-415-555-0305",
"title": "Marketing Director",
"company": "Blue Harbor Media",
// type code here for "relation_one" field
"notes": "Interested in a pilot for Q3 marketing campaigns.",
},
];
const DealsData = [
{
"title": "BrightWave Platform Expansion",
"deal_number": "DW-1001",
"value": 7500.0,
"currency": "USD",
// type code here for "relation_one" field
"status": "Lost",
"close_date": new Date('2026-03-15T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
"description": "Expansion of existing deployment to include analytics module.",
},
{
"title": "Apex National Rollout",
"deal_number": "DW-1002",
"value": 42000.0,
"currency": "USD",
// type code here for "relation_one" field
"status": "Won",
"close_date": new Date('2026-05-01T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
"description": "Multi-store license with priority support and integrations.",
},
{
"title": "GreenFields Proof of Concept",
"deal_number": "DW-1003",
"value": 18000.0,
"currency": "USD",
// type code here for "relation_one" field
"status": "Open",
"close_date": new Date('2026-02-28T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
"description": "6 week POC to validate workflows and integrations.",
},
{
"title": "VoltTech Evaluation",
"deal_number": "DW-1004",
"value": 0.0,
"currency": "USD",
// type code here for "relation_one" field
"status": "Lost",
"close_date": new Date('2026-01-10T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
"description": "Opportunity closed lost due to feature mismatch.",
},
{
"title": "Blue Harbor Pilot",
"deal_number": "DW-1005",
"value": 9600.0,
"currency": "USD",
// type code here for "relation_one" field
"status": "Lost",
"close_date": new Date('2026-04-20T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
"description": "Pilot program for marketing automation integration.",
},
];
const ActivitiesData = [
{
"subject": "Introductory Demo with BrightWave",
"activity_type": "Meeting",
"start": new Date('2026-01-28T15:00:00Z'),
"end": new Date('2026-01-28T16:00:00Z'),
"completed": false,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"notes": "Demo scheduled to showcase analytics capabilities.",
},
{
"subject": "Contract Review with Apex",
"activity_type": "Email",
"start": new Date('2026-02-10T14:00:00Z'),
"end": new Date('2026-02-10T14:30:00Z'),
"completed": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"notes": "Discussion on procurement terms and SLAs.",
},
{
"subject": "POC Kickoff for GreenFields",
"activity_type": "Email",
"start": new Date('2026-02-02T09:00:00Z'),
"end": new Date('2026-02-02T10:00:00Z'),
"completed": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"notes": "Define success criteria and integration points.",
},
{
"subject": "Post-loss Feedback for VoltTech",
"activity_type": "Meeting",
"start": new Date('2026-01-15T11:00:00Z'),
"end": new Date('2026-01-15T11:30:00Z'),
"completed": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"notes": "Captured feedback for product roadmap consideration.",
},
{
"subject": "Pilot Planning with Blue Harbor",
"activity_type": "Call",
"start": new Date('2026-03-05T08:00:00Z'),
"end": new Date('2026-03-05T08:05:00Z'),
"completed": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"notes": "Shared pilot plan and next steps via email.",
},
];
// Similar logic for "relation_many"
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 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 PipelineStages.findOne({
offset: Math.floor(Math.random() * (await PipelineStages.count())),
});
const Deal0 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Deal0?.setStage)
{
await
Deal0.
setStage(relatedStage0);
}
const relatedStage1 = await PipelineStages.findOne({
offset: Math.floor(Math.random() * (await PipelineStages.count())),
});
const Deal1 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Deal1?.setStage)
{
await
Deal1.
setStage(relatedStage1);
}
const relatedStage2 = await PipelineStages.findOne({
offset: Math.floor(Math.random() * (await PipelineStages.count())),
});
const Deal2 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Deal2?.setStage)
{
await
Deal2.
setStage(relatedStage2);
}
const relatedStage3 = await PipelineStages.findOne({
offset: Math.floor(Math.random() * (await PipelineStages.count())),
});
const Deal3 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Deal3?.setStage)
{
await
Deal3.
setStage(relatedStage3);
}
const relatedStage4 = await PipelineStages.findOne({
offset: Math.floor(Math.random() * (await PipelineStages.count())),
});
const Deal4 = await Deals.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Deal4?.setStage)
{
await
Deal4.
setStage(relatedStage4);
}
}
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 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 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 associateActivityWithRelated_deal() {
const relatedRelated_deal0 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Activity0?.setRelated_deal)
{
await
Activity0.
setRelated_deal(relatedRelated_deal0);
}
const relatedRelated_deal1 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Activity1?.setRelated_deal)
{
await
Activity1.
setRelated_deal(relatedRelated_deal1);
}
const relatedRelated_deal2 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Activity2?.setRelated_deal)
{
await
Activity2.
setRelated_deal(relatedRelated_deal2);
}
const relatedRelated_deal3 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Activity3?.setRelated_deal)
{
await
Activity3.
setRelated_deal(relatedRelated_deal3);
}
const relatedRelated_deal4 = await Deals.findOne({
offset: Math.floor(Math.random() * (await Deals.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Activity4?.setRelated_deal)
{
await
Activity4.
setRelated_deal(relatedRelated_deal4);
}
}
async function associateActivityWithRelated_lead() {
const relatedRelated_lead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Activity0?.setRelated_lead)
{
await
Activity0.
setRelated_lead(relatedRelated_lead0);
}
const relatedRelated_lead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Activity1?.setRelated_lead)
{
await
Activity1.
setRelated_lead(relatedRelated_lead1);
}
const relatedRelated_lead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Activity2?.setRelated_lead)
{
await
Activity2.
setRelated_lead(relatedRelated_lead2);
}
const relatedRelated_lead3 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Activity3?.setRelated_lead)
{
await
Activity3.
setRelated_lead(relatedRelated_lead3);
}
const relatedRelated_lead4 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Activity4?.setRelated_lead)
{
await
Activity4.
setRelated_lead(relatedRelated_lead4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await PipelineStages.bulkCreate(PipelineStagesData);
await Leads.bulkCreate(LeadsData);
await Contacts.bulkCreate(ContactsData);
await Deals.bulkCreate(DealsData);
await Activities.bulkCreate(ActivitiesData);
await Promise.all([
// Similar logic for "relation_many"
await associateLeadWithOwner(),
await associateContactWithOwner(),
await associateDealWithStage(),
await associateDealWithOwner(),
await associateDealWithPrimary_contact(),
await associateActivityWithOwner(),
await associateActivityWithRelated_deal(),
await associateActivityWithRelated_lead(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('pipeline_stages', null, {});
await queryInterface.bulkDelete('leads', null, {});
await queryInterface.bulkDelete('contacts', null, {});
await queryInterface.bulkDelete('deals', null, {});
await queryInterface.bulkDelete('activities', null, {});
},
};