40280-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-06-18 07:14:46 +00:00

5280 lines
88 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Categories = db.categories;
const Products = db.products;
const Orders = db.orders;
const OrderItems = db.order_items;
const ContactMessages = db.contact_messages;
const SitePages = db.site_pages;
const BusinessPartners = db.business_partners;
const Promotions = db.promotions;
const Reviews = db.reviews;
const CategoriesData = [
{
"name": "Texas Statutes",
"slug": "texas-statutes",
"description": "Print and annotated compilations of Texas statutes for practitioners and students.",
"is_active": true,
"sort_order": 1,
},
{
"name": "Practice Guides",
"slug": "practice-guides",
"description": "Step by step guides for Texas civil, criminal, and family practice.",
"is_active": true,
"sort_order": 2,
},
{
"name": "Forms and Templates",
"slug": "forms-and-templates",
"description": "Common pleading and transactional forms with practical checklists.",
"is_active": true,
"sort_order": 3,
},
{
"name": "Continuing Legal Education",
"slug": "continuing-legal-education",
"description": "CLE style reference materials and course books for Texas attorneys.",
"is_active": true,
"sort_order": 4,
},
{
"name": "Ethics and Professional Responsibility",
"slug": "ethics-professional-responsibility",
"description": "Resources on Texas disciplinary rules, ethics opinions, and compliance.",
"is_active": true,
"sort_order": 5,
},
];
const ProductsData = [
{
"title": "Texas Penal Code Annotated 2026",
"slug": "texas-penal-code-annotated-2026",
"sku": "TX-PC-2026",
"product_type": "service",
"short_description": "Updated annotated Penal Code with key case notes.",
"description": "A practitioner focused annotated edition of the Texas Penal Code, including recent legislative updates, selected case summaries, and practical cross references.",
// type code here for "relation_one" field
"price": 129.0,
"compare_at_price": 149.0,
"is_taxable": true,
"tax_rate": 0.0825,
"inventory_quantity": 45,
"track_inventory": true,
"status": "draft",
// type code here for "images" field
// type code here for "files" field
"author": "Editorial Board",
"publisher": "Texas Law Books Co.",
"isbn": "9780000001001",
"edition": "2026",
"published_on": new Date('2026-01-10T00:00:00Z'),
"page_count": 980,
},
{
"title": "Texas Family Law Practice Guide",
"slug": "texas-family-law-practice-guide",
"sku": "TX-FAM-GUIDE",
"product_type": "service",
"short_description": "Practical family law workflow and checklists.",
"description": "Comprehensive Texas family law practice guide covering divorce, SAPCR, enforcement, and modification with procedural checklists and drafting tips.",
// type code here for "relation_one" field
"price": 179.0,
"compare_at_price": 199.0,
"is_taxable": true,
"tax_rate": 0.0825,
"inventory_quantity": 30,
"track_inventory": true,
"status": "active",
// type code here for "images" field
// type code here for "files" field
"author": "K. S. Whitman",
"publisher": "Texas Law Books Co.",
"isbn": "9780000001002",
"edition": "5th",
"published_on": new Date('2025-09-01T00:00:00Z'),
"page_count": 1200,
},
{
"title": "Texas Civil Pleadings Form Pack",
"slug": "texas-civil-pleadings-form-pack",
"sku": "TX-CIV-FORMS",
"product_type": "digital_download",
"short_description": "Editable civil pleading templates.",
"description": "Downloadable civil pleadings templates formatted for Texas courts, including petitions, answers, discovery requests, and proposed orders.",
// type code here for "relation_one" field
"price": 79.0,
"compare_at_price": 99.0,
"is_taxable": true,
"tax_rate": 0.0825,
"inventory_quantity": 9999,
"track_inventory": false,
"status": "active",
// type code here for "images" field
// type code here for "files" field
"author": "Forms Department",
"publisher": "Texas Law Books Co.",
"isbn": "9780000001003",
"edition": "2026 Update",
"published_on": new Date('2026-02-15T00:00:00Z'),
"page_count": 0,
},
{
"title": "Texas Ethics Deskbook",
"slug": "texas-ethics-deskbook",
"sku": "TX-ETHICS-DESK",
"product_type": "bundle",
"short_description": "Guidance on Texas ethics and compliance.",
"description": "A deskbook on Texas professional responsibility with rule commentary, common scenarios, and practical compliance checklists for law offices.",
// type code here for "relation_one" field
"price": 99.0,
"compare_at_price": 119.0,
"is_taxable": true,
"tax_rate": 0.0825,
"inventory_quantity": 55,
"track_inventory": true,
"status": "archived",
// type code here for "images" field
// type code here for "files" field
"author": "M. L. Herrera",
"publisher": "Texas Law Books Co.",
"isbn": "9780000001004",
"edition": "3rd",
"published_on": new Date('2024-11-20T00:00:00Z'),
"page_count": 640,
},
{
"title": "Texas Litigation Starter Bundle",
"slug": "texas-litigation-starter-bundle",
"sku": "TX-LIT-BUNDLE",
"product_type": "book",
"short_description": "Bundle for new Texas litigation matters.",
"description": "A curated bundle including a civil procedure reference, key checklists, and a starter set of forms to streamline Texas litigation intake and early filings.",
// type code here for "relation_one" field
"price": 249.0,
"compare_at_price": 299.0,
"is_taxable": true,
"tax_rate": 0.0825,
"inventory_quantity": 20,
"track_inventory": true,
"status": "draft",
// type code here for "images" field
// type code here for "files" field
"author": "Editorial Board",
"publisher": "Texas Law Books Co.",
"isbn": "9780000001005",
"edition": "2026",
"published_on": new Date('2026-03-05T00:00:00Z'),
"page_count": 0,
},
];
const OrdersData = [
{
"order_number": "TLB-100021",
// type code here for "relation_one" field
"status": "paid",
"subtotal_amount": 308.0,
"discount_amount": 20.0,
"tax_amount": 23.76,
"shipping_amount": 12.95,
"total_amount": 324.71,
"payment_method": "cash",
"payment_status": "paid",
"billing_name": "Casey Thompson",
"billing_email": "casey.thompson@lawfirmdemo.com",
"billing_phone": "210-555-0133",
"billing_address_line1": "200 E Houston St",
"billing_address_line2": "Ste 950",
"billing_city": "San Antonio",
"billing_state": "TX",
"billing_postal_code": "78205",
"billing_country": "USA",
"shipping_name": "Casey Thompson",
"shipping_phone": "210-555-0133",
"shipping_address_line1": "200 E Houston St",
"shipping_address_line2": "Ste 950",
"shipping_city": "San Antonio",
"shipping_state": "TX",
"shipping_postal_code": "78205",
"shipping_country": "USA",
"placed_at": new Date('2026-05-01T16:20:00Z'),
"paid_at": new Date('2026-05-01T16:22:00Z'),
"shipped_at": new Date('2026-05-03T18:10:00Z'),
"internal_note": "Priority handling requested via email.",
},
{
"order_number": "TLB-100022",
// type code here for "relation_one" field
"status": "completed",
"subtotal_amount": 99.0,
"discount_amount": 0.0,
"tax_amount": 8.17,
"shipping_amount": 9.95,
"total_amount": 117.12,
"payment_method": "card",
"payment_status": "partially_refunded",
"billing_name": "Riley Garcia",
"billing_email": "riley.garcia@paralegaldemo.com",
"billing_phone": "806-555-0144",
"billing_address_line1": "600 S Tyler St",
"billing_address_line2": "Unit 4B",
"billing_city": "Amarillo",
"billing_state": "TX",
"billing_postal_code": "79101",
"billing_country": "USA",
"shipping_name": "Riley Garcia",
"shipping_phone": "806-555-0144",
"shipping_address_line1": "600 S Tyler St",
"shipping_address_line2": "Unit 4B",
"shipping_city": "Amarillo",
"shipping_state": "TX",
"shipping_postal_code": "79101",
"shipping_country": "USA",
"placed_at": new Date('2026-05-06T14:05:00Z'),
"paid_at": new Date('2026-05-06T14:05:00Z'),
"shipped_at": new Date('2026-05-07T20:00:00Z'),
"internal_note": "Invoice terms requested net 15.",
},
{
"order_number": "TLB-100023",
// type code here for "relation_one" field
"status": "processing",
"subtotal_amount": 129.0,
"discount_amount": 0.0,
"tax_amount": 10.64,
"shipping_amount": 12.95,
"total_amount": 152.59,
"payment_method": "other",
"payment_status": "unpaid",
"billing_name": "Casey Thompson",
"billing_email": "casey.thompson@lawfirmdemo.com",
"billing_phone": "210-555-0133",
"billing_address_line1": "200 E Houston St",
"billing_address_line2": "Ste 950",
"billing_city": "San Antonio",
"billing_state": "TX",
"billing_postal_code": "78205",
"billing_country": "USA",
"shipping_name": "Casey Thompson",
"shipping_phone": "210-555-0133",
"shipping_address_line1": "200 E Houston St",
"shipping_address_line2": "Ste 950",
"shipping_city": "San Antonio",
"shipping_state": "TX",
"shipping_postal_code": "78205",
"shipping_country": "USA",
"placed_at": new Date('2026-05-09T10:40:00Z'),
"paid_at": new Date('2026-05-09T10:41:00Z'),
"shipped_at": new Date('2026-05-10T17:30:00Z'),
"internal_note": "Ship to reception desk.",
},
{
"order_number": "TLB-100024",
// type code here for "relation_one" field
"status": "paid",
"subtotal_amount": 79.0,
"discount_amount": 0.0,
"tax_amount": 6.52,
"shipping_amount": 0.0,
"total_amount": 85.52,
"payment_method": "invoice",
"payment_status": "partially_refunded",
"billing_name": "Riley Garcia",
"billing_email": "riley.garcia@paralegaldemo.com",
"billing_phone": "806-555-0144",
"billing_address_line1": "600 S Tyler St",
"billing_address_line2": "Unit 4B",
"billing_city": "Amarillo",
"billing_state": "TX",
"billing_postal_code": "79101",
"billing_country": "USA",
"shipping_name": "Riley Garcia",
"shipping_phone": "806-555-0144",
"shipping_address_line1": "600 S Tyler St",
"shipping_address_line2": "Unit 4B",
"shipping_city": "Amarillo",
"shipping_state": "TX",
"shipping_postal_code": "79101",
"shipping_country": "USA",
"placed_at": new Date('2026-05-12T09:15:00Z'),
"paid_at": new Date('2026-05-12T09:15:00Z'),
"shipped_at": new Date('2026-05-12T09:15:00Z'),
"internal_note": "Digital download order, auto fulfillment.",
},
{
"order_number": "TLB-100025",
// type code here for "relation_one" field
"status": "pending",
"subtotal_amount": 179.0,
"discount_amount": 10.0,
"tax_amount": 13.94,
"shipping_amount": 12.95,
"total_amount": 195.89,
"payment_method": "cash",
"payment_status": "unpaid",
"billing_name": "Casey Thompson",
"billing_email": "casey.thompson@lawfirmdemo.com",
"billing_phone": "210-555-0133",
"billing_address_line1": "200 E Houston St",
"billing_address_line2": "Ste 950",
"billing_city": "San Antonio",
"billing_state": "TX",
"billing_postal_code": "78205",
"billing_country": "USA",
"shipping_name": "Casey Thompson",
"shipping_phone": "210-555-0133",
"shipping_address_line1": "200 E Houston St",
"shipping_address_line2": "Ste 950",
"shipping_city": "San Antonio",
"shipping_state": "TX",
"shipping_postal_code": "78205",
"shipping_country": "USA",
"placed_at": new Date('2026-05-15T13:00:00Z'),
"paid_at": new Date('2026-05-15T13:01:00Z'),
"shipped_at": new Date('2026-05-16T19:25:00Z'),
"internal_note": "Include packing slip without prices.",
},
];
const OrderItemsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"product_title_snapshot": "Texas Family Law Practice Guide",
"sku_snapshot": "TX-FAM-GUIDE",
"unit_price": 179.0,
"quantity": 1,
"line_total": 179.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"product_title_snapshot": "Texas Ethics Deskbook",
"sku_snapshot": "TX-ETHICS-DESK",
"unit_price": 99.0,
"quantity": 1,
"line_total": 99.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"product_title_snapshot": "Texas Civil Pleadings Form Pack",
"sku_snapshot": "TX-CIV-FORMS",
"unit_price": 79.0,
"quantity": 1,
"line_total": 79.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"product_title_snapshot": "Texas Penal Code Annotated 2026",
"sku_snapshot": "TX-PC-2026",
"unit_price": 129.0,
"quantity": 1,
"line_total": 129.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"product_title_snapshot": "Texas Family Law Practice Guide",
"sku_snapshot": "TX-FAM-GUIDE",
"unit_price": 179.0,
"quantity": 1,
"line_total": 179.0,
},
];
const ContactMessagesData = [
{
"full_name": "Jamie Collins",
"email": "jamie.collins@firmdemo.com",
"phone": "469-555-0188",
"topic": "product_question",
"message": "Do you offer an annual update service for the Penal Code annotated edition",
"status": "new",
"submitted_at": new Date('2026-05-02T11:30:00Z'),
// type code here for "relation_one" field
},
{
"full_name": "Taylor Brooks",
"email": "taylor.brooks@nonprofitdemo.org",
"phone": "832-555-0191",
"topic": "wholesale",
"message": "We would like pricing for a bulk order of ethics deskbooks for our clinic program",
"status": "in_progress",
"submitted_at": new Date('2026-05-04T15:05:00Z'),
// type code here for "relation_one" field
},
{
"full_name": "Cameron Lee",
"email": "cameron.lee@lawfirmdemo.com",
"phone": "512-555-0199",
"topic": "order_support",
"message": "Order TLB-100021 arrived with minor corner damage on one book can we request a replacement",
"status": "in_progress",
"submitted_at": new Date('2026-05-05T09:45:00Z'),
// type code here for "relation_one" field
},
{
"full_name": "Sydney Ramirez",
"email": "sydney.ramirez@procurementdemo.com",
"phone": "210-555-0177",
"topic": "wholesale",
"message": "Our organization is interested in a dealer partnership and cross promotion opportunities",
"status": "closed",
"submitted_at": new Date('2026-05-08T14:10:00Z'),
// type code here for "relation_one" field
},
{
"full_name": "Quinn Harper",
"email": "quinn.harper@educationdemo.edu",
"phone": "713-555-0166",
"topic": "product_question",
"message": "Do you have student discounts for practice guides and bundles",
"status": "in_progress",
"submitted_at": new Date('2026-05-10T18:20:00Z'),
// type code here for "relation_one" field
},
];
const SitePagesData = [
{
"title": "Home",
"slug": "home",
"page_type": "catalog",
"hero_headline": "Texas Law Books and Practice Resources",
"hero_subheadline": "Professional black and white design with light green accents for quick access to trusted Texas legal references.",
"hero_partner_anchor_text": "Law Source",
"hero_partner_url": "https://legaldowntown.com/",
// type code here for "images" field
"content": "Welcome to our Texas based law book shop Browse updated titles practice guides and downloadable forms Contact us for bulk orders and partnerships.",
"status": "published",
"published_at": new Date('2026-04-01T12:00:00Z'),
},
{
"title": "About",
"slug": "about",
"page_type": "about",
"hero_headline": "Built for Texas practitioners",
"hero_subheadline": "Curated legal references and practical tools for day to day work.",
"hero_partner_anchor_text": "Law Source",
"hero_partner_url": "https://legaldowntown.com/",
// type code here for "images" field
"content": "We focus on practical Texas focused materials for attorneys paralegals and students Our team updates key titles and bundles to match evolving needs.",
"status": "published",
"published_at": new Date('2026-04-01T12:05:00Z'),
},
{
"title": "Catalog",
"slug": "catalog",
"page_type": "contact",
"hero_headline": "Browse the catalog",
"hero_subheadline": "Statutes practice guides forms and ethics references.",
"hero_partner_anchor_text": "Law Source",
"hero_partner_url": "https://legaldowntown.com/",
// type code here for "images" field
"content": "Use categories to find titles quickly Filter by print bundles and digital downloads for immediate access.",
"status": "draft",
"published_at": new Date('2026-04-01T12:10:00Z'),
},
{
"title": "Contact",
"slug": "contact",
"page_type": "privacy",
"hero_headline": "Contact our team",
"hero_subheadline": "Questions about titles orders or bulk pricing We can help.",
"hero_partner_anchor_text": "Law Source",
"hero_partner_url": "https://legaldowntown.com/",
// type code here for "images" field
"content": "Send a message with your topic and details Our staff responds during business hours Central Time.",
"status": "draft",
"published_at": new Date('2026-04-01T12:15:00Z'),
},
{
"title": "Terms of Service",
"slug": "terms",
"page_type": "catalog",
"hero_headline": "Terms of Service",
"hero_subheadline": "Clear policies for purchases and downloads.",
"hero_partner_anchor_text": "Law Source",
"hero_partner_url": "https://legaldowntown.com/",
// type code here for "images" field
"content": "All sales policies shipping timelines and digital download terms are described here Contact support for help with access issues.",
"status": "published",
"published_at": new Date('2026-04-01T12:20:00Z'),
},
];
const BusinessPartnersData = [
{
"name": "Legal Downtown Dealer Network",
"anchor_text": "Law Source",
"url": "https://legaldowntown.com/",
"description": "Authorized partner and dealer network for legal resources and referrals.",
"is_featured_in_hero": true,
"is_active": true,
"sort_order": 1,
},
{
"name": "Texas Court Filings Supply Co",
"anchor_text": "Texas Filing Supplies",
"url": "#",
"description": "Demo partner for filing supplies and office materials.",
"is_featured_in_hero": true,
"is_active": true,
"sort_order": 2,
},
{
"name": "Hill Country Print Services",
"anchor_text": "Print Services",
"url": "#",
"description": "Demo partner for print and binding services for internal use materials.",
"is_featured_in_hero": true,
"is_active": true,
"sort_order": 3,
},
{
"name": "Gulf Coast Legal Courier",
"anchor_text": "Courier Service",
"url": "#",
"description": "Demo partner for regional courier delivery options.",
"is_featured_in_hero": true,
"is_active": true,
"sort_order": 4,
},
{
"name": "West Texas CLE Events",
"anchor_text": "CLE Events",
"url": "#",
"description": "Demo partner for legal education event coordination.",
"is_featured_in_hero": false,
"is_active": true,
"sort_order": 5,
},
];
const PromotionsData = [
{
"name": "Spring Practitioner Savings",
"code": "SPRING26",
"discount_type": "free_shipping",
"discount_value": 10.0,
"minimum_order_amount": 150.0,
"starts_at": new Date('2026-04-15T00:00:00Z'),
"ends_at": new Date('2026-05-15T23:59:59Z'),
"usage_limit": 500,
"used_count": 38,
"status": "paused",
},
{
"name": "Free Shipping Over 200",
"code": "SHIP200",
"discount_type": "free_shipping",
"discount_value": 0.0,
"minimum_order_amount": 200.0,
"starts_at": new Date('2026-05-01T00:00:00Z'),
"ends_at": new Date('2026-12-31T23:59:59Z'),
"usage_limit": 2000,
"used_count": 124,
"status": "paused",
},
{
"name": "CLE Bundle Discount",
"code": "CLE15",
"discount_type": "percentage",
"discount_value": 15.0,
"minimum_order_amount": 100.0,
"starts_at": new Date('2026-06-01T00:00:00Z'),
"ends_at": new Date('2026-08-31T23:59:59Z'),
"usage_limit": 800,
"used_count": 0,
"status": "active",
},
{
"name": "New Customer Credit",
"code": "WELCOME10",
"discount_type": "free_shipping",
"discount_value": 10.0,
"minimum_order_amount": 75.0,
"starts_at": new Date('2026-05-10T00:00:00Z'),
"ends_at": new Date('2026-10-31T23:59:59Z'),
"usage_limit": 1500,
"used_count": 210,
"status": "paused",
},
{
"name": "Summer Forms Promo",
"code": "FORMS20",
"discount_type": "free_shipping",
"discount_value": 20.0,
"minimum_order_amount": 50.0,
"starts_at": new Date('2026-07-01T00:00:00Z'),
"ends_at": new Date('2026-07-31T23:59:59Z'),
"usage_limit": 600,
"used_count": 0,
"status": "scheduled",
},
];
const ReviewsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 5,
"title": "Thorough and current",
"body": "Very helpful annotations and organization The updates appear current and easy to find.",
"status": "pending",
"submitted_at": new Date('2026-05-11T12:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 4,
"title": "Strong practice checklists",
"body": "The checklists are practical and save time for intake and first filings.",
"status": "approved",
"submitted_at": new Date('2026-05-12T09:30:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 5,
"title": "Great desk reference",
"body": "Clear explanations and realistic scenarios for everyday compliance questions.",
"status": "rejected",
"submitted_at": new Date('2026-05-13T14:10:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 4,
"title": "Good templates",
"body": "Templates are clean and easy to adapt for typical matters.",
"status": "rejected",
"submitted_at": new Date('2026-05-14T16:45:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 4,
"title": "Useful starter set",
"body": "Nice bundle for getting a new case organized quickly.",
"status": "pending",
"submitted_at": new Date('2026-05-16T10:25:00Z'),
},
];
// Similar logic for "relation_many"
async function associateProductWithCategory() {
const relatedCategory0 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product0 = await Products.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Product0?.setCategory)
{
await
Product0.
setCategory(relatedCategory0);
}
const relatedCategory1 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product1 = await Products.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Product1?.setCategory)
{
await
Product1.
setCategory(relatedCategory1);
}
const relatedCategory2 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product2 = await Products.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Product2?.setCategory)
{
await
Product2.
setCategory(relatedCategory2);
}
const relatedCategory3 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product3 = await Products.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Product3?.setCategory)
{
await
Product3.
setCategory(relatedCategory3);
}
const relatedCategory4 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product4 = await Products.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Product4?.setCategory)
{
await
Product4.
setCategory(relatedCategory4);
}
}
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 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);
}
const relatedOrder4 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const OrderItem4 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (OrderItem4?.setOrder)
{
await
OrderItem4.
setOrder(relatedOrder4);
}
}
async function associateOrderItemWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem0 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (OrderItem0?.setProduct)
{
await
OrderItem0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem1 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (OrderItem1?.setProduct)
{
await
OrderItem1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem2 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (OrderItem2?.setProduct)
{
await
OrderItem2.
setProduct(relatedProduct2);
}
const relatedProduct3 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem3 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (OrderItem3?.setProduct)
{
await
OrderItem3.
setProduct(relatedProduct3);
}
const relatedProduct4 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem4 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (OrderItem4?.setProduct)
{
await
OrderItem4.
setProduct(relatedProduct4);
}
}
async function associateContactMessageWithAssigned_to() {
const relatedAssigned_to0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContactMessage0 = await ContactMessages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ContactMessage0?.setAssigned_to)
{
await
ContactMessage0.
setAssigned_to(relatedAssigned_to0);
}
const relatedAssigned_to1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContactMessage1 = await ContactMessages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ContactMessage1?.setAssigned_to)
{
await
ContactMessage1.
setAssigned_to(relatedAssigned_to1);
}
const relatedAssigned_to2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContactMessage2 = await ContactMessages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ContactMessage2?.setAssigned_to)
{
await
ContactMessage2.
setAssigned_to(relatedAssigned_to2);
}
const relatedAssigned_to3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContactMessage3 = await ContactMessages.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ContactMessage3?.setAssigned_to)
{
await
ContactMessage3.
setAssigned_to(relatedAssigned_to3);
}
const relatedAssigned_to4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContactMessage4 = await ContactMessages.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (ContactMessage4?.setAssigned_to)
{
await
ContactMessage4.
setAssigned_to(relatedAssigned_to4);
}
}
async function associateReviewWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Review0 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Review0?.setProduct)
{
await
Review0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Review1 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Review1?.setProduct)
{
await
Review1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Review2 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Review2?.setProduct)
{
await
Review2.
setProduct(relatedProduct2);
}
const relatedProduct3 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Review3 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Review3?.setProduct)
{
await
Review3.
setProduct(relatedProduct3);
}
const relatedProduct4 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Review4 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Review4?.setProduct)
{
await
Review4.
setProduct(relatedProduct4);
}
}
async function associateReviewWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Review0 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Review0?.setUser)
{
await
Review0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Review1 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Review1?.setUser)
{
await
Review1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Review2 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Review2?.setUser)
{
await
Review2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Review3 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Review3?.setUser)
{
await
Review3.
setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Review4 = await Reviews.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Review4?.setUser)
{
await
Review4.
setUser(relatedUser4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Categories.bulkCreate(CategoriesData);
await Products.bulkCreate(ProductsData);
await Orders.bulkCreate(OrdersData);
await OrderItems.bulkCreate(OrderItemsData);
await ContactMessages.bulkCreate(ContactMessagesData);
await SitePages.bulkCreate(SitePagesData);
await BusinessPartners.bulkCreate(BusinessPartnersData);
await Promotions.bulkCreate(PromotionsData);
await Reviews.bulkCreate(ReviewsData);
await Promise.all([
// Similar logic for "relation_many"
await associateProductWithCategory(),
await associateOrderWithCustomer(),
await associateOrderItemWithOrder(),
await associateOrderItemWithProduct(),
await associateContactMessageWithAssigned_to(),
await associateReviewWithProduct(),
await associateReviewWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('categories', null, {});
await queryInterface.bulkDelete('products', null, {});
await queryInterface.bulkDelete('orders', null, {});
await queryInterface.bulkDelete('order_items', null, {});
await queryInterface.bulkDelete('contact_messages', null, {});
await queryInterface.bulkDelete('site_pages', null, {});
await queryInterface.bulkDelete('business_partners', null, {});
await queryInterface.bulkDelete('promotions', null, {});
await queryInterface.bulkDelete('reviews', null, {});
},
};