31164/backend/src/db/seeders/20231127130745-sample-data.js
2025-05-02 03:46:40 +00:00

1006 lines
24 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Activities = db.activities;
const Contacts = db.contacts;
const Leads = db.leads;
const Metrics = db.metrics;
const Notes = db.notes;
const Organizations = db.organizations;
const ActivitiesData = [
{
description: 'Initial meeting with Acme Corp',
start_date: new Date('2023-10-01T09:00:00Z'),
end_date: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Follow-up call with Globex Inc',
start_date: new Date('2023-10-02T11:00:00Z'),
end_date: new Date('2023-10-02T11:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Proposal review for Initech',
start_date: new Date('2023-10-03T14:00:00Z'),
end_date: new Date('2023-10-03T15:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Contract negotiation with Umbrella Corp',
start_date: new Date('2023-10-04T16:00:00Z'),
end_date: new Date('2023-10-04T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Final presentation to Hooli',
start_date: new Date('2023-10-05T13:00:00Z'),
end_date: new Date('2023-10-05T14:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ContactsData = [
{
first_name: 'Alice',
last_name: 'Johnson',
email: 'alice.johnson@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Bob',
last_name: 'Williams',
email: 'bob.williams@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Charlie',
last_name: 'Davis',
email: 'charlie.davis@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Diana',
last_name: 'Miller',
email: 'diana.miller@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Ethan',
last_name: 'Wilson',
email: 'ethan.wilson@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const LeadsData = [
{
name: 'Acme Corp',
status: 'won',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Globex Inc',
status: 'qualified',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Initech',
status: 'proposal_sent',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Umbrella Corp',
status: 'new',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Hooli',
status: 'won',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const MetricsData = [
{
name: 'Lead Conversion Rate',
value: 0.25,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Customer Satisfaction Score',
value: 4.5,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Average Deal Size',
value: 50000,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Sales Cycle Length',
value: 30,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Churn Rate',
value: 0.05,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const NotesData = [
{
content: 'Acme Corp is interested in our premium package.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
content: 'Globex Inc needs a follow-up on pricing.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
content: 'Initech is considering a long-term contract.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
content: 'Umbrella Corp requested additional information.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
content: 'Hooli is ready to sign the contract.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Isaac Newton',
},
{
name: 'Joseph J. Thomson',
},
{
name: 'Jean Baptiste Lamarck',
},
{
name: 'Albrecht von Haller',
},
{
name: 'Pierre Simon de Laplace',
},
];
// Similar logic for "relation_many"
async function associateUserWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setOrganization) {
await User0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setOrganization) {
await User1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setOrganization) {
await User2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setOrganization) {
await User3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User4 = await Users.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (User4?.setOrganization) {
await User4.setOrganization(relatedOrganization4);
}
}
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);
}
}
async function associateActivityWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Activity0?.setOrganization) {
await Activity0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Activity1?.setOrganization) {
await Activity1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Activity2?.setOrganization) {
await Activity2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Activity3?.setOrganization) {
await Activity3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Activity4?.setOrganization) {
await Activity4.setOrganization(relatedOrganization4);
}
}
async function associateContactWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Contact0 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Contact0?.setLead) {
await Contact0.setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Contact1 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Contact1?.setLead) {
await Contact1.setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Contact2 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Contact2?.setLead) {
await Contact2.setLead(relatedLead2);
}
const relatedLead3 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Contact3 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Contact3?.setLead) {
await Contact3.setLead(relatedLead3);
}
const relatedLead4 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Contact4 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Contact4?.setLead) {
await Contact4.setLead(relatedLead4);
}
}
async function associateContactWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Contact0 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Contact0?.setOrganization) {
await Contact0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Contact1 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Contact1?.setOrganization) {
await Contact1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Contact2 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Contact2?.setOrganization) {
await Contact2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Contact3 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Contact3?.setOrganization) {
await Contact3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Contact4 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Contact4?.setOrganization) {
await Contact4.setOrganization(relatedOrganization4);
}
}
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);
}
}
// Similar logic for "relation_many"
async function associateLeadWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Lead0 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Lead0?.setOrganization) {
await Lead0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Lead1 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Lead1?.setOrganization) {
await Lead1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Lead2 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Lead2?.setOrganization) {
await Lead2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Lead3 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Lead3?.setOrganization) {
await Lead3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Lead4 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Lead4?.setOrganization) {
await Lead4.setOrganization(relatedOrganization4);
}
}
async function associateMetricWithRelated_entity() {
const relatedRelated_entity0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Metric0 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Metric0?.setRelated_entity) {
await Metric0.setRelated_entity(relatedRelated_entity0);
}
const relatedRelated_entity1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Metric1 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Metric1?.setRelated_entity) {
await Metric1.setRelated_entity(relatedRelated_entity1);
}
const relatedRelated_entity2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Metric2 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Metric2?.setRelated_entity) {
await Metric2.setRelated_entity(relatedRelated_entity2);
}
const relatedRelated_entity3 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Metric3 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Metric3?.setRelated_entity) {
await Metric3.setRelated_entity(relatedRelated_entity3);
}
const relatedRelated_entity4 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Metric4 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Metric4?.setRelated_entity) {
await Metric4.setRelated_entity(relatedRelated_entity4);
}
}
async function associateMetricWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Metric0 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Metric0?.setOrganization) {
await Metric0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Metric1 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Metric1?.setOrganization) {
await Metric1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Metric2 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Metric2?.setOrganization) {
await Metric2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Metric3 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Metric3?.setOrganization) {
await Metric3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Metric4 = await Metrics.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Metric4?.setOrganization) {
await Metric4.setOrganization(relatedOrganization4);
}
}
async function associateNoteWithRelated_entity() {
const relatedRelated_entity0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note0 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Note0?.setRelated_entity) {
await Note0.setRelated_entity(relatedRelated_entity0);
}
const relatedRelated_entity1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note1 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Note1?.setRelated_entity) {
await Note1.setRelated_entity(relatedRelated_entity1);
}
const relatedRelated_entity2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note2 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Note2?.setRelated_entity) {
await Note2.setRelated_entity(relatedRelated_entity2);
}
const relatedRelated_entity3 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note3 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Note3?.setRelated_entity) {
await Note3.setRelated_entity(relatedRelated_entity3);
}
const relatedRelated_entity4 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note4 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Note4?.setRelated_entity) {
await Note4.setRelated_entity(relatedRelated_entity4);
}
}
async function associateNoteWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Note0 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Note0?.setOrganization) {
await Note0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Note1 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Note1?.setOrganization) {
await Note1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Note2 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Note2?.setOrganization) {
await Note2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Note3 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Note3?.setOrganization) {
await Note3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Note4 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Note4?.setOrganization) {
await Note4.setOrganization(relatedOrganization4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Activities.bulkCreate(ActivitiesData);
await Contacts.bulkCreate(ContactsData);
await Leads.bulkCreate(LeadsData);
await Metrics.bulkCreate(MetricsData);
await Notes.bulkCreate(NotesData);
await Organizations.bulkCreate(OrganizationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateActivityWithRelated_lead(),
await associateActivityWithOrganization(),
await associateContactWithLead(),
await associateContactWithOrganization(),
await associateLeadWithOwner(),
// Similar logic for "relation_many"
await associateLeadWithOrganization(),
await associateMetricWithRelated_entity(),
await associateMetricWithOrganization(),
await associateNoteWithRelated_entity(),
await associateNoteWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('activities', null, {});
await queryInterface.bulkDelete('contacts', null, {});
await queryInterface.bulkDelete('leads', null, {});
await queryInterface.bulkDelete('metrics', null, {});
await queryInterface.bulkDelete('notes', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};