29950/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-17 07:13:54 +00:00

811 lines
19 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Activities = db.activities;
const Contacts = db.contacts;
const Leads = db.leads;
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
// 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
// type code here for "relation_one" field
},
{
description: 'Product demo 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
// type code here for "relation_one" field
},
{
description: 'Contract review 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
// type code here for "relation_one" field
},
];
const ContactsData = [
{
first_name: 'John',
last_name: 'Doe',
email: 'john.doe@acme.com',
phone: '555-0101',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Alice',
last_name: 'Smith',
email: 'alice.smith@globex.com',
phone: '555-0102',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Bob',
last_name: 'White',
email: 'bob.white@initech.com',
phone: '555-0103',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Charlie',
last_name: 'Johnson',
email: 'charlie.johnson@umbrella.com',
phone: '555-0104',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const LeadsData = [
{
name: 'Acme Corp',
status: 'Contacted',
category: 'Individual',
// 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: 'New',
category: 'Individual',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Initech',
status: 'New',
category: 'Government',
// 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: 'Contacted',
category: 'Individual',
// type code here for "relation_one" field
// type code here for "relation_many" 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
// type code here for "relation_one" field
},
{
content: 'Globex Inc requires a custom solution.',
// type code here for "relation_one" field
// 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
// type code here for "relation_one" field
},
{
content: 'Umbrella Corp has budget constraints.',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Ludwig Boltzmann',
},
{
name: 'J. Robert Oppenheimer',
},
{
name: 'Tycho Brahe',
},
{
name: 'Comte de Buffon',
},
];
// 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);
}
}
async function associateActivityWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Activity0?.setUser) {
await Activity0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Activity1?.setUser) {
await Activity1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Activity2?.setUser) {
await Activity2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Activity3?.setUser) {
await Activity3.setUser(relatedUser3);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
// 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);
}
}
async function associateNoteWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Note0 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Note0?.setUser) {
await Note0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Note1 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Note1?.setUser) {
await Note1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Note2 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Note2?.setUser) {
await Note2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Note3 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Note3?.setUser) {
await Note3.setUser(relatedUser3);
}
}
async function associateNoteWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note0 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Note0?.setLead) {
await Note0.setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note1 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Note1?.setLead) {
await Note1.setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note2 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Note2?.setLead) {
await Note2.setLead(relatedLead2);
}
const relatedLead3 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Note3 = await Notes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Note3?.setLead) {
await Note3.setLead(relatedLead3);
}
}
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);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Activities.bulkCreate(ActivitiesData);
await Contacts.bulkCreate(ContactsData);
await Leads.bulkCreate(LeadsData);
await Notes.bulkCreate(NotesData);
await Organizations.bulkCreate(OrganizationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateActivityWithUser(),
await associateActivityWithLead(),
await associateActivityWithOrganization(),
await associateContactWithLead(),
await associateContactWithOrganization(),
await associateLeadWithOwner(),
// Similar logic for "relation_many"
await associateLeadWithOrganization(),
await associateNoteWithUser(),
await associateNoteWithLead(),
await associateNoteWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('activities', null, {});
await queryInterface.bulkDelete('contacts', null, {});
await queryInterface.bulkDelete('leads', null, {});
await queryInterface.bulkDelete('notes', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};