33217/backend/src/db/seeders/20231127130745-sample-data.js
2025-08-04 11:23:04 +00:00

368 lines
7.3 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Activities = db.activities;
const Bookings = db.bookings;
const Customers = db.customers;
const Leads = db.leads;
const Packages = db.packages;
const Tasks = db.tasks;
const ActivitiesData = [
{
name: 'City Tour',
description: "A guided tour of the city's main attractions.",
// type code here for "images" field
},
{
name: 'Museum Visit',
description: 'Explore the history and art in the local museum.',
// type code here for "images" field
},
{
name: 'Hiking Adventure',
description: 'A thrilling hike through scenic trails.',
// type code here for "images" field
},
];
const BookingsData = [
{
// type code here for "relation_one" field
// type code here for "relation_many" field
booking_date: new Date('2023-11-01T10:00:00Z'),
total_amount: 2999.99,
payment_status: 'Partial',
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
booking_date: new Date('2023-11-05T14:00:00Z'),
total_amount: 1999.99,
payment_status: 'Paid',
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
booking_date: new Date('2023-11-10T09:00:00Z'),
total_amount: 3999.99,
payment_status: 'Pending',
},
];
const CustomersData = [
{
first_name: 'Alice',
last_name: 'Johnson',
email: 'alice.johnson@example.com',
phone: '555-0101',
},
{
first_name: 'Bob',
last_name: 'Williams',
email: 'bob.williams@example.com',
phone: '555-0102',
},
{
first_name: 'Charlie',
last_name: 'Brown',
email: 'charlie.brown@example.com',
phone: '555-0103',
},
];
const LeadsData = [
{
name: 'Acme Corp',
status: 'New',
// type code here for "relation_one" field
notes: 'Initial contact made.',
follow_up_date: new Date('2023-11-01T10:00:00Z'),
},
{
name: 'Globex Inc',
status: 'New',
// type code here for "relation_one" field
notes: 'Sent proposal.',
follow_up_date: new Date('2023-11-05T14:00:00Z'),
},
{
name: 'Initech',
status: 'Confirmed',
// type code here for "relation_one" field
notes: 'Awaiting contract.',
follow_up_date: new Date('2023-11-10T09:00:00Z'),
},
];
const PackagesData = [
{
title: 'European Adventure',
description: 'Explore the best of Europe with this comprehensive tour.',
price: 2999.99,
// type code here for "relation_many" field
},
{
title: 'Asian Discovery',
description: 'Experience the diverse cultures of Asia.',
price: 1999.99,
// type code here for "relation_many" field
},
{
title: 'African Safari',
description: 'Witness the majestic wildlife of Africa.',
price: 3999.99,
// type code here for "relation_many" field
},
];
const TasksData = [
{
title: 'Follow up with Acme Corp',
// type code here for "relation_one" field
due_date: new Date('2023-11-02T10:00:00Z'),
status: 'InProgress',
},
{
title: 'Prepare proposal for Globex Inc',
// type code here for "relation_one" field
due_date: new Date('2023-11-06T14:00:00Z'),
status: 'Pending',
},
{
title: 'Finalize contract with Initech',
// type code here for "relation_one" field
due_date: new Date('2023-11-11T09:00:00Z'),
status: 'Pending',
},
];
// Similar logic for "relation_many"
async function associateBookingWithCustomer() {
const relatedCustomer0 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Booking0 = await Bookings.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Booking0?.setCustomer) {
await Booking0.setCustomer(relatedCustomer0);
}
const relatedCustomer1 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Booking1 = await Bookings.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Booking1?.setCustomer) {
await Booking1.setCustomer(relatedCustomer1);
}
const relatedCustomer2 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Booking2 = await Bookings.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Booking2?.setCustomer) {
await Booking2.setCustomer(relatedCustomer2);
}
}
// Similar logic for "relation_many"
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);
}
}
// Similar logic for "relation_many"
async function associateTaskWithAssigned_to() {
const relatedAssigned_to0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Task0?.setAssigned_to) {
await Task0.setAssigned_to(relatedAssigned_to0);
}
const relatedAssigned_to1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Task1?.setAssigned_to) {
await Task1.setAssigned_to(relatedAssigned_to1);
}
const relatedAssigned_to2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Task2?.setAssigned_to) {
await Task2.setAssigned_to(relatedAssigned_to2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Activities.bulkCreate(ActivitiesData);
await Bookings.bulkCreate(BookingsData);
await Customers.bulkCreate(CustomersData);
await Leads.bulkCreate(LeadsData);
await Packages.bulkCreate(PackagesData);
await Tasks.bulkCreate(TasksData);
await Promise.all([
// Similar logic for "relation_many"
await associateBookingWithCustomer(),
// Similar logic for "relation_many"
await associateLeadWithAssigned_to(),
// Similar logic for "relation_many"
await associateTaskWithAssigned_to(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('activities', null, {});
await queryInterface.bulkDelete('bookings', null, {});
await queryInterface.bulkDelete('customers', null, {});
await queryInterface.bulkDelete('leads', null, {});
await queryInterface.bulkDelete('packages', null, {});
await queryInterface.bulkDelete('tasks', null, {});
},
};