31046/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-28 05:56:15 +00:00

825 lines
21 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const AfterSalesFollowups = db.after_sales_followups;
const Conversations = db.conversations;
const CrmEntries = db.crm_entries;
const Leads = db.leads;
const MarketingAutomations = db.marketing_automations;
const ProductSuggestions = db.product_suggestions;
const Sales = db.sales;
const Organizations = db.organizations;
const AfterSalesFollowupsData = [
{
// type code here for "relation_one" field
followup_notes: 'Checked in post-purchase.',
followup_date: new Date('2023-10-10T10:00:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
followup_notes: 'Provided additional product training.',
followup_date: new Date('2023-10-12T11:30:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
followup_notes: 'Discussed renewal options.',
followup_date: new Date('2023-10-15T09:15:00Z'),
// type code here for "relation_one" field
},
];
const ConversationsData = [
{
// type code here for "relation_one" field
content: 'Discussed potential partnership opportunities.',
timestamp: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
content: 'Followed up on previous meeting notes.',
timestamp: new Date('2023-10-02T11:30:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
content: 'Explored new product features.',
timestamp: new Date('2023-10-03T09:15:00Z'),
// type code here for "relation_one" field
},
];
const CrmEntriesData = [
{
// type code here for "relation_one" field
status: 'Interested',
last_contacted: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
status: 'In Negotiation',
last_contacted: new Date('2023-10-02T11:30:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
status: 'Closed Won',
last_contacted: new Date('2023-10-03T09:15:00Z'),
// type code here for "relation_one" field
},
];
const LeadsData = [
{
name: 'Acme Corp',
email: 'contact@acmecorp.com',
phone: '1234567890',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Globex Inc',
email: 'info@globex.com',
phone: '0987654321',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Initech',
email: 'support@initech.com',
phone: '1122334455',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const MarketingAutomationsData = [
{
campaign_name: 'Winter Sale',
start_date: new Date('2023-11-01T00:00:00Z'),
end_date: new Date('2023-12-31T23:59:59Z'),
// type code here for "relation_one" field
},
{
campaign_name: 'Spring Launch',
start_date: new Date('2024-03-01T00:00:00Z'),
end_date: new Date('2024-04-30T23:59:59Z'),
// type code here for "relation_one" field
},
{
campaign_name: 'Summer Special',
start_date: new Date('2024-06-01T00:00:00Z'),
end_date: new Date('2024-07-31T23:59:59Z'),
// type code here for "relation_one" field
},
];
const ProductSuggestionsData = [
{
// type code here for "relation_one" field
product_name: 'AI Assistant Pro',
suggestion_details: 'Recommended for enhancing customer support.',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
product_name: 'CRM Plus',
suggestion_details: 'Ideal for managing large client databases.',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
product_name: 'Marketing Suite',
suggestion_details: 'Perfect for automating marketing campaigns.',
// type code here for "relation_one" field
},
];
const SalesData = [
{
// type code here for "relation_one" field
amount: 5000,
sale_date: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
amount: 7500,
sale_date: new Date('2023-10-02T11:30:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
amount: 10000,
sale_date: new Date('2023-10-03T09:15:00Z'),
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Jonas Salk',
},
{
name: 'Max von Laue',
},
{
name: 'Frederick Gowland Hopkins',
},
];
// 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);
}
}
async function associateAfterSalesFollowupWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const AfterSalesFollowup0 = await AfterSalesFollowups.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (AfterSalesFollowup0?.setLead) {
await AfterSalesFollowup0.setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const AfterSalesFollowup1 = await AfterSalesFollowups.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (AfterSalesFollowup1?.setLead) {
await AfterSalesFollowup1.setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const AfterSalesFollowup2 = await AfterSalesFollowups.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (AfterSalesFollowup2?.setLead) {
await AfterSalesFollowup2.setLead(relatedLead2);
}
}
async function associateAfterSalesFollowupWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const AfterSalesFollowup0 = await AfterSalesFollowups.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (AfterSalesFollowup0?.setOrganization) {
await AfterSalesFollowup0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const AfterSalesFollowup1 = await AfterSalesFollowups.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (AfterSalesFollowup1?.setOrganization) {
await AfterSalesFollowup1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const AfterSalesFollowup2 = await AfterSalesFollowups.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (AfterSalesFollowup2?.setOrganization) {
await AfterSalesFollowup2.setOrganization(relatedOrganization2);
}
}
async function associateConversationWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Conversation0 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Conversation0?.setLead) {
await Conversation0.setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Conversation1 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Conversation1?.setLead) {
await Conversation1.setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Conversation2 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Conversation2?.setLead) {
await Conversation2.setLead(relatedLead2);
}
}
async function associateConversationWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Conversation0 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Conversation0?.setOrganization) {
await Conversation0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Conversation1 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Conversation1?.setOrganization) {
await Conversation1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Conversation2 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Conversation2?.setOrganization) {
await Conversation2.setOrganization(relatedOrganization2);
}
}
async function associateCrmEntryWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const CrmEntry0 = await CrmEntries.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (CrmEntry0?.setLead) {
await CrmEntry0.setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const CrmEntry1 = await CrmEntries.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (CrmEntry1?.setLead) {
await CrmEntry1.setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const CrmEntry2 = await CrmEntries.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (CrmEntry2?.setLead) {
await CrmEntry2.setLead(relatedLead2);
}
}
async function associateCrmEntryWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const CrmEntry0 = await CrmEntries.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (CrmEntry0?.setOrganization) {
await CrmEntry0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const CrmEntry1 = await CrmEntries.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (CrmEntry1?.setOrganization) {
await CrmEntry1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const CrmEntry2 = await CrmEntries.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (CrmEntry2?.setOrganization) {
await CrmEntry2.setOrganization(relatedOrganization2);
}
}
async function associateLeadWithAssigned_to() {
const relatedAssigned_to0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Lead0 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Lead0?.setAssigned_to) {
await Lead0.setAssigned_to(relatedAssigned_to0);
}
const relatedAssigned_to1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Lead1 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Lead1?.setAssigned_to) {
await Lead1.setAssigned_to(relatedAssigned_to1);
}
const relatedAssigned_to2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Lead2 = await Leads.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Lead2?.setAssigned_to) {
await Lead2.setAssigned_to(relatedAssigned_to2);
}
}
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);
}
}
async function associateMarketingAutomationWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const MarketingAutomation0 = await MarketingAutomations.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MarketingAutomation0?.setOrganization) {
await MarketingAutomation0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const MarketingAutomation1 = await MarketingAutomations.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MarketingAutomation1?.setOrganization) {
await MarketingAutomation1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const MarketingAutomation2 = await MarketingAutomations.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MarketingAutomation2?.setOrganization) {
await MarketingAutomation2.setOrganization(relatedOrganization2);
}
}
async function associateProductSuggestionWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const ProductSuggestion0 = await ProductSuggestions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (ProductSuggestion0?.setLead) {
await ProductSuggestion0.setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const ProductSuggestion1 = await ProductSuggestions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (ProductSuggestion1?.setLead) {
await ProductSuggestion1.setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const ProductSuggestion2 = await ProductSuggestions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (ProductSuggestion2?.setLead) {
await ProductSuggestion2.setLead(relatedLead2);
}
}
async function associateProductSuggestionWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ProductSuggestion0 = await ProductSuggestions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (ProductSuggestion0?.setOrganization) {
await ProductSuggestion0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ProductSuggestion1 = await ProductSuggestions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (ProductSuggestion1?.setOrganization) {
await ProductSuggestion1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ProductSuggestion2 = await ProductSuggestions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (ProductSuggestion2?.setOrganization) {
await ProductSuggestion2.setOrganization(relatedOrganization2);
}
}
async function associateSaleWithLead() {
const relatedLead0 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Sale0 = await Sales.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Sale0?.setLead) {
await Sale0.setLead(relatedLead0);
}
const relatedLead1 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Sale1 = await Sales.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Sale1?.setLead) {
await Sale1.setLead(relatedLead1);
}
const relatedLead2 = await Leads.findOne({
offset: Math.floor(Math.random() * (await Leads.count())),
});
const Sale2 = await Sales.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Sale2?.setLead) {
await Sale2.setLead(relatedLead2);
}
}
async function associateSaleWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sale0 = await Sales.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Sale0?.setOrganization) {
await Sale0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sale1 = await Sales.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Sale1?.setOrganization) {
await Sale1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sale2 = await Sales.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Sale2?.setOrganization) {
await Sale2.setOrganization(relatedOrganization2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await AfterSalesFollowups.bulkCreate(AfterSalesFollowupsData);
await Conversations.bulkCreate(ConversationsData);
await CrmEntries.bulkCreate(CrmEntriesData);
await Leads.bulkCreate(LeadsData);
await MarketingAutomations.bulkCreate(MarketingAutomationsData);
await ProductSuggestions.bulkCreate(ProductSuggestionsData);
await Sales.bulkCreate(SalesData);
await Organizations.bulkCreate(OrganizationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateAfterSalesFollowupWithLead(),
await associateAfterSalesFollowupWithOrganization(),
await associateConversationWithLead(),
await associateConversationWithOrganization(),
await associateCrmEntryWithLead(),
await associateCrmEntryWithOrganization(),
await associateLeadWithAssigned_to(),
await associateLeadWithOrganization(),
await associateMarketingAutomationWithOrganization(),
await associateProductSuggestionWithLead(),
await associateProductSuggestionWithOrganization(),
await associateSaleWithLead(),
await associateSaleWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('after_sales_followups', null, {});
await queryInterface.bulkDelete('conversations', null, {});
await queryInterface.bulkDelete('crm_entries', null, {});
await queryInterface.bulkDelete('leads', null, {});
await queryInterface.bulkDelete('marketing_automations', null, {});
await queryInterface.bulkDelete('product_suggestions', null, {});
await queryInterface.bulkDelete('sales', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};