const db = require('../models'); const Users = db.users; const Deliveries = db.deliveries; const Medicines = db.medicines; const OrderItems = db.order_items; const Orders = db.orders; const Payments = db.payments; const Pharmacies = db.pharmacies; const Prescriptions = db.prescriptions; const Organizations = db.organizations; const DeliveriesData = [ { // type code here for "relation_one" field address: '123 Main St, City A', tracking_status: 'processing', // type code here for "relation_one" field }, { // type code here for "relation_one" field address: '456 Elm St, City B', tracking_status: 'delivered', // type code here for "relation_one" field }, { // type code here for "relation_one" field address: '789 Oak St, City C', tracking_status: 'delivered', // type code here for "relation_one" field }, { // type code here for "relation_one" field address: '101 Pine St, City D', tracking_status: 'processing', // type code here for "relation_one" field }, ]; const MedicinesData = [ { name: 'Paracetamol', generic_name: 'Acetaminophen', brand: 'Tylenol', price: 2.5, stock: 100, category: 'OTC', schedule: 'H1', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Amoxicillin', generic_name: 'Amoxicillin', brand: 'Amoxil', price: 5, stock: 50, category: 'Prescription', schedule: 'X', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Ibuprofen', generic_name: 'Ibuprofen', brand: 'Advil', price: 3, stock: 200, category: 'Prescription', schedule: 'X', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Metformin', generic_name: 'Metformin', brand: 'Glucophage', price: 4, stock: 150, category: 'Prescription', schedule: 'H', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrderItemsData = [ { // type code here for "relation_one" field quantity: 2, price: 5, // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field quantity: 1, price: 5, // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field quantity: 3, price: 9, // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field quantity: 2, price: 8, // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrdersData = [ { // type code here for "relation_one" field // type code here for "relation_one" field status: 'pending', order_date: new Date('2023-10-01T10:00:00Z'), // type code here for "relation_many" field // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field status: 'pending', order_date: new Date('2023-10-02T11:00:00Z'), // type code here for "relation_many" field // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field status: 'delivered', order_date: new Date('2023-10-03T12:00:00Z'), // type code here for "relation_many" field // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field status: 'dispatched', order_date: new Date('2023-10-04T13:00:00Z'), // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const PaymentsData = [ { // type code here for "relation_one" field amount: 10, method: 'Wallet', status: 'completed', // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 5, method: 'UPI', status: 'completed', // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 9, method: 'UPI', status: 'completed', // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 8, method: 'Wallet', status: 'pending', // type code here for "relation_one" field }, ]; const PharmaciesData = [ { name: 'HealthPlus Pharmacy', license_number: 'LIC123456', // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'MediCare Store', license_number: 'LIC654321', // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Wellness Pharmacy', license_number: 'LIC112233', // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'CareWell Drugs', license_number: 'LIC445566', // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const PrescriptionsData = [ { // type code here for "files" field verified: true, // 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 "files" field verified: false, // 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 "files" field verified: true, // 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 "files" field verified: true, // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'Hans Selye', }, { name: 'Charles Lyell', }, { name: 'Comte de Buffon', }, { 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 associateDeliveryWithOrder() { const relatedOrder0 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Delivery0 = await Deliveries.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Delivery0?.setOrder) { await Delivery0.setOrder(relatedOrder0); } const relatedOrder1 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Delivery1 = await Deliveries.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Delivery1?.setOrder) { await Delivery1.setOrder(relatedOrder1); } const relatedOrder2 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Delivery2 = await Deliveries.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Delivery2?.setOrder) { await Delivery2.setOrder(relatedOrder2); } const relatedOrder3 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Delivery3 = await Deliveries.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Delivery3?.setOrder) { await Delivery3.setOrder(relatedOrder3); } } async function associateDeliveryWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Delivery0 = await Deliveries.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Delivery0?.setOrganization) { await Delivery0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Delivery1 = await Deliveries.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Delivery1?.setOrganization) { await Delivery1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Delivery2 = await Deliveries.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Delivery2?.setOrganization) { await Delivery2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Delivery3 = await Deliveries.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Delivery3?.setOrganization) { await Delivery3.setOrganization(relatedOrganization3); } } async function associateMedicineWithPharmacy() { const relatedPharmacy0 = await Pharmacies.findOne({ offset: Math.floor(Math.random() * (await Pharmacies.count())), }); const Medicine0 = await Medicines.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Medicine0?.setPharmacy) { await Medicine0.setPharmacy(relatedPharmacy0); } const relatedPharmacy1 = await Pharmacies.findOne({ offset: Math.floor(Math.random() * (await Pharmacies.count())), }); const Medicine1 = await Medicines.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Medicine1?.setPharmacy) { await Medicine1.setPharmacy(relatedPharmacy1); } const relatedPharmacy2 = await Pharmacies.findOne({ offset: Math.floor(Math.random() * (await Pharmacies.count())), }); const Medicine2 = await Medicines.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Medicine2?.setPharmacy) { await Medicine2.setPharmacy(relatedPharmacy2); } const relatedPharmacy3 = await Pharmacies.findOne({ offset: Math.floor(Math.random() * (await Pharmacies.count())), }); const Medicine3 = await Medicines.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Medicine3?.setPharmacy) { await Medicine3.setPharmacy(relatedPharmacy3); } } async function associateMedicineWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Medicine0 = await Medicines.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Medicine0?.setOrganization) { await Medicine0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Medicine1 = await Medicines.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Medicine1?.setOrganization) { await Medicine1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Medicine2 = await Medicines.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Medicine2?.setOrganization) { await Medicine2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Medicine3 = await Medicines.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Medicine3?.setOrganization) { await Medicine3.setOrganization(relatedOrganization3); } } async function associateOrderItemWithMedicine() { const relatedMedicine0 = await Medicines.findOne({ offset: Math.floor(Math.random() * (await Medicines.count())), }); const OrderItem0 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 0, }); if (OrderItem0?.setMedicine) { await OrderItem0.setMedicine(relatedMedicine0); } const relatedMedicine1 = await Medicines.findOne({ offset: Math.floor(Math.random() * (await Medicines.count())), }); const OrderItem1 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 1, }); if (OrderItem1?.setMedicine) { await OrderItem1.setMedicine(relatedMedicine1); } const relatedMedicine2 = await Medicines.findOne({ offset: Math.floor(Math.random() * (await Medicines.count())), }); const OrderItem2 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 2, }); if (OrderItem2?.setMedicine) { await OrderItem2.setMedicine(relatedMedicine2); } const relatedMedicine3 = await Medicines.findOne({ offset: Math.floor(Math.random() * (await Medicines.count())), }); const OrderItem3 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 3, }); if (OrderItem3?.setMedicine) { await OrderItem3.setMedicine(relatedMedicine3); } } async function associateOrderItemWithOrder() { const relatedOrder0 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const OrderItem0 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 0, }); if (OrderItem0?.setOrder) { await OrderItem0.setOrder(relatedOrder0); } const relatedOrder1 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const OrderItem1 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 1, }); if (OrderItem1?.setOrder) { await OrderItem1.setOrder(relatedOrder1); } const relatedOrder2 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const OrderItem2 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 2, }); if (OrderItem2?.setOrder) { await OrderItem2.setOrder(relatedOrder2); } const relatedOrder3 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const OrderItem3 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 3, }); if (OrderItem3?.setOrder) { await OrderItem3.setOrder(relatedOrder3); } } async function associateOrderItemWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const OrderItem0 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 0, }); if (OrderItem0?.setOrganization) { await OrderItem0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const OrderItem1 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 1, }); if (OrderItem1?.setOrganization) { await OrderItem1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const OrderItem2 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 2, }); if (OrderItem2?.setOrganization) { await OrderItem2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const OrderItem3 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 3, }); if (OrderItem3?.setOrganization) { await OrderItem3.setOrganization(relatedOrganization3); } } 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); } } async function associateOrderWithPharmacy() { const relatedPharmacy0 = await Pharmacies.findOne({ offset: Math.floor(Math.random() * (await Pharmacies.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setPharmacy) { await Order0.setPharmacy(relatedPharmacy0); } const relatedPharmacy1 = await Pharmacies.findOne({ offset: Math.floor(Math.random() * (await Pharmacies.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setPharmacy) { await Order1.setPharmacy(relatedPharmacy1); } const relatedPharmacy2 = await Pharmacies.findOne({ offset: Math.floor(Math.random() * (await Pharmacies.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setPharmacy) { await Order2.setPharmacy(relatedPharmacy2); } const relatedPharmacy3 = await Pharmacies.findOne({ offset: Math.floor(Math.random() * (await Pharmacies.count())), }); const Order3 = await Orders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Order3?.setPharmacy) { await Order3.setPharmacy(relatedPharmacy3); } } // Similar logic for "relation_many" async function associateOrderWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setOrganization) { await Order0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setOrganization) { await Order1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setOrganization) { await Order2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Order3 = await Orders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Order3?.setOrganization) { await Order3.setOrganization(relatedOrganization3); } } async function associatePaymentWithOrder() { const relatedOrder0 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setOrder) { await Payment0.setOrder(relatedOrder0); } const relatedOrder1 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setOrder) { await Payment1.setOrder(relatedOrder1); } const relatedOrder2 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setOrder) { await Payment2.setOrder(relatedOrder2); } const relatedOrder3 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Payment3 = await Payments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Payment3?.setOrder) { await Payment3.setOrder(relatedOrder3); } } async function associatePaymentWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setOrganization) { await Payment0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setOrganization) { await Payment1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setOrganization) { await Payment2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment3 = await Payments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Payment3?.setOrganization) { await Payment3.setOrganization(relatedOrganization3); } } async function associatePharmacyWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Pharmacy0 = await Pharmacies.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Pharmacy0?.setOwner) { await Pharmacy0.setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Pharmacy1 = await Pharmacies.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Pharmacy1?.setOwner) { await Pharmacy1.setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Pharmacy2 = await Pharmacies.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Pharmacy2?.setOwner) { await Pharmacy2.setOwner(relatedOwner2); } const relatedOwner3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Pharmacy3 = await Pharmacies.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Pharmacy3?.setOwner) { await Pharmacy3.setOwner(relatedOwner3); } } async function associatePharmacyWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Pharmacy0 = await Pharmacies.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Pharmacy0?.setOrganization) { await Pharmacy0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Pharmacy1 = await Pharmacies.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Pharmacy1?.setOrganization) { await Pharmacy1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Pharmacy2 = await Pharmacies.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Pharmacy2?.setOrganization) { await Pharmacy2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Pharmacy3 = await Pharmacies.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Pharmacy3?.setOrganization) { await Pharmacy3.setOrganization(relatedOrganization3); } } async function associatePrescriptionWithCustomer() { const relatedCustomer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Prescription0 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Prescription0?.setCustomer) { await Prescription0.setCustomer(relatedCustomer0); } const relatedCustomer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Prescription1 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Prescription1?.setCustomer) { await Prescription1.setCustomer(relatedCustomer1); } const relatedCustomer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Prescription2 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Prescription2?.setCustomer) { await Prescription2.setCustomer(relatedCustomer2); } const relatedCustomer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Prescription3 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Prescription3?.setCustomer) { await Prescription3.setCustomer(relatedCustomer3); } } async function associatePrescriptionWithOrder() { const relatedOrder0 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Prescription0 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Prescription0?.setOrder) { await Prescription0.setOrder(relatedOrder0); } const relatedOrder1 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Prescription1 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Prescription1?.setOrder) { await Prescription1.setOrder(relatedOrder1); } const relatedOrder2 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Prescription2 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Prescription2?.setOrder) { await Prescription2.setOrder(relatedOrder2); } const relatedOrder3 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Prescription3 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Prescription3?.setOrder) { await Prescription3.setOrder(relatedOrder3); } } async function associatePrescriptionWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Prescription0 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Prescription0?.setOrganization) { await Prescription0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Prescription1 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Prescription1?.setOrganization) { await Prescription1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Prescription2 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Prescription2?.setOrganization) { await Prescription2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Prescription3 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Prescription3?.setOrganization) { await Prescription3.setOrganization(relatedOrganization3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Deliveries.bulkCreate(DeliveriesData); await Medicines.bulkCreate(MedicinesData); await OrderItems.bulkCreate(OrderItemsData); await Orders.bulkCreate(OrdersData); await Payments.bulkCreate(PaymentsData); await Pharmacies.bulkCreate(PharmaciesData); await Prescriptions.bulkCreate(PrescriptionsData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateDeliveryWithOrder(), await associateDeliveryWithOrganization(), await associateMedicineWithPharmacy(), await associateMedicineWithOrganization(), await associateOrderItemWithMedicine(), await associateOrderItemWithOrder(), await associateOrderItemWithOrganization(), await associateOrderWithCustomer(), await associateOrderWithPharmacy(), // Similar logic for "relation_many" await associateOrderWithOrganization(), await associatePaymentWithOrder(), await associatePaymentWithOrganization(), await associatePharmacyWithOwner(), await associatePharmacyWithOrganization(), await associatePrescriptionWithCustomer(), await associatePrescriptionWithOrder(), await associatePrescriptionWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('deliveries', null, {}); await queryInterface.bulkDelete('medicines', null, {}); await queryInterface.bulkDelete('order_items', null, {}); await queryInterface.bulkDelete('orders', null, {}); await queryInterface.bulkDelete('payments', null, {}); await queryInterface.bulkDelete('pharmacies', null, {}); await queryInterface.bulkDelete('prescriptions', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };