const db = require('../models'); const Users = db.users; const ContactInquiries = db.contact_inquiries; const Employees = db.employees; const JobApplications = db.job_applications; const JobOpenings = db.job_openings; const Orders = db.orders; const SupportTickets = db.support_tickets; const Dashboard = db.dashboard; const DataVisualisatio = db.data_visualisatio; const Companies = db.companies; const ContactInquiriesData = [ { name: 'Alice Johnson', email: 'alice.johnson@example.com', message: 'Interested in your services', submitted_at: new Date('2023-10-01T09:00:00Z'), // type code here for "relation_one" field }, { name: 'Bob Williams', email: 'bob.williams@example.com', message: 'Need more information about pricing', submitted_at: new Date('2023-10-02T10:00:00Z'), // type code here for "relation_one" field }, { name: 'Charlie Brown', email: 'charlie.brown@example.com', message: 'How can I apply for a job?', submitted_at: new Date('2023-10-03T11:00:00Z'), // type code here for "relation_one" field }, { name: 'Diana Prince', email: 'diana.prince@example.com', message: 'Technical support needed', submitted_at: new Date('2023-10-04T12:00:00Z'), // type code here for "relation_one" field }, { name: 'Eve Adams', email: 'eve.adams@example.com', message: 'Request for a product demo', submitted_at: new Date('2023-10-05T13:00:00Z'), // type code here for "relation_one" field }, ]; const EmployeesData = [ { first_name: 'John', last_name: 'Doe', email: 'johndoe@company.com', phone: '555-1234', role: 'manager', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Jane', last_name: 'Smith', email: 'janesmith@company.com', phone: '555-5678', role: 'designer', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Mike', last_name: 'Brown', email: 'mikebrown@company.com', phone: '555-8765', role: 'developer', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Emily', last_name: 'White', email: 'emilywhite@company.com', phone: '555-4321', role: 'designer', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Bob', last_name: 'Green', email: 'bobgreen@company.com', phone: '555-6789', role: 'developer', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const JobApplicationsData = [ { applicant_name: 'Alice Johnson', email: 'alice.johnson@example.com', resume: 'alice_resume.pdf', // type code here for "relation_one" field // type code here for "relation_one" field }, { applicant_name: 'Bob Williams', email: 'bob.williams@example.com', resume: 'bob_resume.pdf', // type code here for "relation_one" field // type code here for "relation_one" field }, { applicant_name: 'Charlie Brown', email: 'charlie.brown@example.com', resume: 'charlie_resume.pdf', // type code here for "relation_one" field // type code here for "relation_one" field }, { applicant_name: 'Diana Prince', email: 'diana.prince@example.com', resume: 'diana_resume.pdf', // type code here for "relation_one" field // type code here for "relation_one" field }, { applicant_name: 'Eve Adams', email: 'eve.adams@example.com', resume: 'eve_resume.pdf', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const JobOpeningsData = [ { title: 'Software Engineer', description: 'Develop and maintain software applications', job_type: 'full_time', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Graphic Designer', description: 'Create visual concepts and designs', job_type: 'contract', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Project Manager', description: 'Oversee project development and execution', job_type: 'contract', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Data Analyst', description: 'Analyze and interpret complex data sets', job_type: 'part_time', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'HR Specialist', description: 'Manage recruitment and employee relations', job_type: 'full_time', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const OrdersData = [ { order_number: 'ORD001', order_date: new Date('2023-10-01T10:00:00Z'), status: 'completed', // type code here for "relation_one" field // type code here for "relation_one" field }, { order_number: 'ORD002', order_date: new Date('2023-10-02T11:00:00Z'), status: 'pending', // type code here for "relation_one" field // type code here for "relation_one" field }, { order_number: 'ORD003', order_date: new Date('2023-10-03T12:00:00Z'), status: 'pending', // type code here for "relation_one" field // type code here for "relation_one" field }, { order_number: 'ORD004', order_date: new Date('2023-10-04T13:00:00Z'), status: 'pending', // type code here for "relation_one" field // type code here for "relation_one" field }, { order_number: 'ORD005', order_date: new Date('2023-10-05T14:00:00Z'), status: 'completed', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const SupportTicketsData = [ { subject: 'Login Issue', description: 'Unable to login to the dashboard', status: 'open', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { subject: 'Order Delay', description: 'Order not received on time', status: 'resolved', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { subject: 'Feature Request', description: 'Request for a new feature in the app', status: 'open', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { subject: 'Bug Report', description: 'Found a bug in the system', status: 'resolved', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { subject: 'Account Setup', description: 'Need help setting up account', status: 'resolved', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const DashboardData = [ { // type code here for "relation_one" field }, { // type code here for "relation_one" field }, { // type code here for "relation_one" field }, { // type code here for "relation_one" field }, { // type code here for "relation_one" field }, ]; const DataVisualisatioData = [ { // type code here for "relation_one" field }, { // type code here for "relation_one" field }, { // type code here for "relation_one" field }, { // type code here for "relation_one" field }, { // type code here for "relation_one" field }, ]; const CompaniesData = [ { name: 'Saraswati Industries', }, { name: 'Tech Solutions', }, { name: 'Green Energy Corp', }, { name: 'HealthCare Innovations', }, { name: 'EduTech Solutions', }, ]; // Similar logic for "relation_many" async function associateUserWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setCompany) { await User0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setCompany) { await User1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setCompany) { await User2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setCompany) { await User3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setCompany) { await User4.setCompany(relatedCompany4); } } async function associateContactInquiryWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const ContactInquiry0 = await ContactInquiries.findOne({ order: [['id', 'ASC']], offset: 0, }); if (ContactInquiry0?.setCompany) { await ContactInquiry0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const ContactInquiry1 = await ContactInquiries.findOne({ order: [['id', 'ASC']], offset: 1, }); if (ContactInquiry1?.setCompany) { await ContactInquiry1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const ContactInquiry2 = await ContactInquiries.findOne({ order: [['id', 'ASC']], offset: 2, }); if (ContactInquiry2?.setCompany) { await ContactInquiry2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const ContactInquiry3 = await ContactInquiries.findOne({ order: [['id', 'ASC']], offset: 3, }); if (ContactInquiry3?.setCompany) { await ContactInquiry3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const ContactInquiry4 = await ContactInquiries.findOne({ order: [['id', 'ASC']], offset: 4, }); if (ContactInquiry4?.setCompany) { await ContactInquiry4.setCompany(relatedCompany4); } } async function associateEmployeeWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee0 = await Employees.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Employee0?.setCompany) { await Employee0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee1 = await Employees.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Employee1?.setCompany) { await Employee1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee2 = await Employees.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Employee2?.setCompany) { await Employee2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee3 = await Employees.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Employee3?.setCompany) { await Employee3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee4 = await Employees.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Employee4?.setCompany) { await Employee4.setCompany(relatedCompany4); } } async function associateEmployeeWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee0 = await Employees.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Employee0?.setCompany) { await Employee0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee1 = await Employees.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Employee1?.setCompany) { await Employee1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee2 = await Employees.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Employee2?.setCompany) { await Employee2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee3 = await Employees.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Employee3?.setCompany) { await Employee3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Employee4 = await Employees.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Employee4?.setCompany) { await Employee4.setCompany(relatedCompany4); } } async function associateJobApplicationWithJob_opening() { const relatedJob_opening0 = await JobOpenings.findOne({ offset: Math.floor(Math.random() * (await JobOpenings.count())), }); const JobApplication0 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (JobApplication0?.setJob_opening) { await JobApplication0.setJob_opening(relatedJob_opening0); } const relatedJob_opening1 = await JobOpenings.findOne({ offset: Math.floor(Math.random() * (await JobOpenings.count())), }); const JobApplication1 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (JobApplication1?.setJob_opening) { await JobApplication1.setJob_opening(relatedJob_opening1); } const relatedJob_opening2 = await JobOpenings.findOne({ offset: Math.floor(Math.random() * (await JobOpenings.count())), }); const JobApplication2 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (JobApplication2?.setJob_opening) { await JobApplication2.setJob_opening(relatedJob_opening2); } const relatedJob_opening3 = await JobOpenings.findOne({ offset: Math.floor(Math.random() * (await JobOpenings.count())), }); const JobApplication3 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (JobApplication3?.setJob_opening) { await JobApplication3.setJob_opening(relatedJob_opening3); } const relatedJob_opening4 = await JobOpenings.findOne({ offset: Math.floor(Math.random() * (await JobOpenings.count())), }); const JobApplication4 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (JobApplication4?.setJob_opening) { await JobApplication4.setJob_opening(relatedJob_opening4); } } async function associateJobApplicationWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobApplication0 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (JobApplication0?.setCompany) { await JobApplication0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobApplication1 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (JobApplication1?.setCompany) { await JobApplication1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobApplication2 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (JobApplication2?.setCompany) { await JobApplication2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobApplication3 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (JobApplication3?.setCompany) { await JobApplication3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobApplication4 = await JobApplications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (JobApplication4?.setCompany) { await JobApplication4.setCompany(relatedCompany4); } } // Similar logic for "relation_many" async function associateJobOpeningWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobOpening0 = await JobOpenings.findOne({ order: [['id', 'ASC']], offset: 0, }); if (JobOpening0?.setCompany) { await JobOpening0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobOpening1 = await JobOpenings.findOne({ order: [['id', 'ASC']], offset: 1, }); if (JobOpening1?.setCompany) { await JobOpening1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobOpening2 = await JobOpenings.findOne({ order: [['id', 'ASC']], offset: 2, }); if (JobOpening2?.setCompany) { await JobOpening2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobOpening3 = await JobOpenings.findOne({ order: [['id', 'ASC']], offset: 3, }); if (JobOpening3?.setCompany) { await JobOpening3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const JobOpening4 = await JobOpenings.findOne({ order: [['id', 'ASC']], offset: 4, }); if (JobOpening4?.setCompany) { await JobOpening4.setCompany(relatedCompany4); } } async function associateOrderWithCustomer() { const relatedCustomer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setCustomer) { await Order0.setCustomer(relatedCustomer0); } const relatedCustomer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setCustomer) { await Order1.setCustomer(relatedCustomer1); } const relatedCustomer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setCustomer) { await Order2.setCustomer(relatedCustomer2); } const relatedCustomer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order3 = await Orders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Order3?.setCustomer) { await Order3.setCustomer(relatedCustomer3); } const relatedCustomer4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order4 = await Orders.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Order4?.setCustomer) { await Order4.setCustomer(relatedCustomer4); } } async function associateOrderWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setCompany) { await Order0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setCompany) { await Order1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setCompany) { await Order2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Order3 = await Orders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Order3?.setCompany) { await Order3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Order4 = await Orders.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Order4?.setCompany) { await Order4.setCompany(relatedCompany4); } } async function associateSupportTicketWithAssigned_to() { const relatedAssigned_to0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket0 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 0, }); if (SupportTicket0?.setAssigned_to) { await SupportTicket0.setAssigned_to(relatedAssigned_to0); } const relatedAssigned_to1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket1 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 1, }); if (SupportTicket1?.setAssigned_to) { await SupportTicket1.setAssigned_to(relatedAssigned_to1); } const relatedAssigned_to2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket2 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 2, }); if (SupportTicket2?.setAssigned_to) { await SupportTicket2.setAssigned_to(relatedAssigned_to2); } const relatedAssigned_to3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket3 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 3, }); if (SupportTicket3?.setAssigned_to) { await SupportTicket3.setAssigned_to(relatedAssigned_to3); } const relatedAssigned_to4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket4 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 4, }); if (SupportTicket4?.setAssigned_to) { await SupportTicket4.setAssigned_to(relatedAssigned_to4); } } async function associateSupportTicketWithSubmitted_by() { const relatedSubmitted_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket0 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 0, }); if (SupportTicket0?.setSubmitted_by) { await SupportTicket0.setSubmitted_by(relatedSubmitted_by0); } const relatedSubmitted_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket1 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 1, }); if (SupportTicket1?.setSubmitted_by) { await SupportTicket1.setSubmitted_by(relatedSubmitted_by1); } const relatedSubmitted_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket2 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 2, }); if (SupportTicket2?.setSubmitted_by) { await SupportTicket2.setSubmitted_by(relatedSubmitted_by2); } const relatedSubmitted_by3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket3 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 3, }); if (SupportTicket3?.setSubmitted_by) { await SupportTicket3.setSubmitted_by(relatedSubmitted_by3); } const relatedSubmitted_by4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SupportTicket4 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 4, }); if (SupportTicket4?.setSubmitted_by) { await SupportTicket4.setSubmitted_by(relatedSubmitted_by4); } } async function associateSupportTicketWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const SupportTicket0 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 0, }); if (SupportTicket0?.setCompany) { await SupportTicket0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const SupportTicket1 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 1, }); if (SupportTicket1?.setCompany) { await SupportTicket1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const SupportTicket2 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 2, }); if (SupportTicket2?.setCompany) { await SupportTicket2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const SupportTicket3 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 3, }); if (SupportTicket3?.setCompany) { await SupportTicket3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const SupportTicket4 = await SupportTickets.findOne({ order: [['id', 'ASC']], offset: 4, }); if (SupportTicket4?.setCompany) { await SupportTicket4.setCompany(relatedCompany4); } } async function associateDashboardWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Dashboard0 = await Dashboard.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Dashboard0?.setCompany) { await Dashboard0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Dashboard1 = await Dashboard.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Dashboard1?.setCompany) { await Dashboard1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Dashboard2 = await Dashboard.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Dashboard2?.setCompany) { await Dashboard2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Dashboard3 = await Dashboard.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Dashboard3?.setCompany) { await Dashboard3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Dashboard4 = await Dashboard.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Dashboard4?.setCompany) { await Dashboard4.setCompany(relatedCompany4); } } async function associateDataVisualisatioWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const DataVisualisatio0 = await DataVisualisatio.findOne({ order: [['id', 'ASC']], offset: 0, }); if (DataVisualisatio0?.setCompany) { await DataVisualisatio0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const DataVisualisatio1 = await DataVisualisatio.findOne({ order: [['id', 'ASC']], offset: 1, }); if (DataVisualisatio1?.setCompany) { await DataVisualisatio1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const DataVisualisatio2 = await DataVisualisatio.findOne({ order: [['id', 'ASC']], offset: 2, }); if (DataVisualisatio2?.setCompany) { await DataVisualisatio2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const DataVisualisatio3 = await DataVisualisatio.findOne({ order: [['id', 'ASC']], offset: 3, }); if (DataVisualisatio3?.setCompany) { await DataVisualisatio3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const DataVisualisatio4 = await DataVisualisatio.findOne({ order: [['id', 'ASC']], offset: 4, }); if (DataVisualisatio4?.setCompany) { await DataVisualisatio4.setCompany(relatedCompany4); } } module.exports = { up: async (queryInterface, Sequelize) => { await ContactInquiries.bulkCreate(ContactInquiriesData); await Employees.bulkCreate(EmployeesData); await JobApplications.bulkCreate(JobApplicationsData); await JobOpenings.bulkCreate(JobOpeningsData); await Orders.bulkCreate(OrdersData); await SupportTickets.bulkCreate(SupportTicketsData); await Dashboard.bulkCreate(DashboardData); await DataVisualisatio.bulkCreate(DataVisualisatioData); await Companies.bulkCreate(CompaniesData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithCompany(), await associateContactInquiryWithCompany(), await associateEmployeeWithCompany(), await associateEmployeeWithCompany(), await associateJobApplicationWithJob_opening(), await associateJobApplicationWithCompany(), // Similar logic for "relation_many" await associateJobOpeningWithCompany(), await associateOrderWithCustomer(), await associateOrderWithCompany(), await associateSupportTicketWithAssigned_to(), await associateSupportTicketWithSubmitted_by(), await associateSupportTicketWithCompany(), await associateDashboardWithCompany(), await associateDataVisualisatioWithCompany(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('contact_inquiries', null, {}); await queryInterface.bulkDelete('employees', null, {}); await queryInterface.bulkDelete('job_applications', null, {}); await queryInterface.bulkDelete('job_openings', null, {}); await queryInterface.bulkDelete('orders', null, {}); await queryInterface.bulkDelete('support_tickets', null, {}); await queryInterface.bulkDelete('dashboard', null, {}); await queryInterface.bulkDelete('data_visualisatio', null, {}); await queryInterface.bulkDelete('companies', null, {}); }, };