800 lines
17 KiB
JavaScript
800 lines
17 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Bookings = db.bookings;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const Products = db.products;
|
|
|
|
const Reviews = db.reviews;
|
|
|
|
const Services = db.services;
|
|
|
|
const BookingsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-10-06T15:00:00Z'),
|
|
|
|
status: 'cancelled',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-10-07T16:00:00Z'),
|
|
|
|
status: 'cancelled',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-10-08T17:00:00Z'),
|
|
|
|
status: 'rescheduled',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-10-09T18:00:00Z'),
|
|
|
|
status: 'new',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-10-10T19:00:00Z'),
|
|
|
|
status: 'new',
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_price: 209.98,
|
|
|
|
status: 'processing',
|
|
|
|
order_date: new Date('2023-10-01T10:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_price: 129.99,
|
|
|
|
status: 'confirmed',
|
|
|
|
order_date: new Date('2023-10-02T11:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_price: 748.99,
|
|
|
|
status: 'delivered',
|
|
|
|
order_date: new Date('2023-10-03T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_price: 329.98,
|
|
|
|
status: 'cancelled',
|
|
|
|
order_date: new Date('2023-10-04T13:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_price: 259.98,
|
|
|
|
status: 'delivered',
|
|
|
|
order_date: new Date('2023-10-05T14:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
name: 'Smart Thermostat',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Home Automation',
|
|
|
|
sub_category: 'Thermostats',
|
|
|
|
price: 199.99,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'LED Light Bulb',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Lighting',
|
|
|
|
sub_category: 'Bulbs',
|
|
|
|
price: 9.99,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Water Purifier',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Appliances',
|
|
|
|
sub_category: 'Purifiers',
|
|
|
|
price: 129.99,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Smart Door Lock',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Security',
|
|
|
|
sub_category: 'Locks',
|
|
|
|
price: 249.99,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Solar Panel Kit',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Energy',
|
|
|
|
sub_category: 'Solar Panels',
|
|
|
|
price: 499.99,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const ReviewsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 5,
|
|
|
|
comment: 'Excellent service and product quality!',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 4,
|
|
|
|
comment: 'Very good, but room for improvement.',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 3,
|
|
|
|
comment: 'Average experience, nothing special.',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 2,
|
|
|
|
comment: 'Not satisfied with the service.',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 1,
|
|
|
|
comment: 'Poor quality, would not recommend.',
|
|
},
|
|
];
|
|
|
|
const ServicesData = [
|
|
{
|
|
name: 'HVAC Maintenance',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Home Services',
|
|
|
|
sub_category: 'Maintenance',
|
|
|
|
price: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Plumbing Repair',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Home Services',
|
|
|
|
sub_category: 'Repair',
|
|
|
|
price: 100,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Electrical Inspection',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Home Services',
|
|
|
|
sub_category: 'Inspection',
|
|
|
|
price: 120,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Roof Cleaning',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Home Services',
|
|
|
|
sub_category: 'Cleaning',
|
|
|
|
price: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Garden Landscaping',
|
|
|
|
// type code here for "images" field
|
|
|
|
category: 'Home Services',
|
|
|
|
sub_category: 'Landscaping',
|
|
|
|
price: 300,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateBookingWithCustomer() {
|
|
const relatedCustomer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking0 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Booking0?.setCustomer) {
|
|
await Booking0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking1 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Booking1?.setCustomer) {
|
|
await Booking1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking2 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Booking2?.setCustomer) {
|
|
await Booking2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking3 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Booking3?.setCustomer) {
|
|
await Booking3.setCustomer(relatedCustomer3);
|
|
}
|
|
|
|
const relatedCustomer4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking4 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Booking4?.setCustomer) {
|
|
await Booking4.setCustomer(relatedCustomer4);
|
|
}
|
|
}
|
|
|
|
async function associateBookingWithService() {
|
|
const relatedService0 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Booking0 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Booking0?.setService) {
|
|
await Booking0.setService(relatedService0);
|
|
}
|
|
|
|
const relatedService1 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Booking1 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Booking1?.setService) {
|
|
await Booking1.setService(relatedService1);
|
|
}
|
|
|
|
const relatedService2 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Booking2 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Booking2?.setService) {
|
|
await Booking2.setService(relatedService2);
|
|
}
|
|
|
|
const relatedService3 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Booking3 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Booking3?.setService) {
|
|
await Booking3.setService(relatedService3);
|
|
}
|
|
|
|
const relatedService4 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Booking4 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Booking4?.setService) {
|
|
await Booking4.setService(relatedService4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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 associateReviewWithService() {
|
|
const relatedService0 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setService) {
|
|
await Review0.setService(relatedService0);
|
|
}
|
|
|
|
const relatedService1 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setService) {
|
|
await Review1.setService(relatedService1);
|
|
}
|
|
|
|
const relatedService2 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setService) {
|
|
await Review2.setService(relatedService2);
|
|
}
|
|
|
|
const relatedService3 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Review3 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Review3?.setService) {
|
|
await Review3.setService(relatedService3);
|
|
}
|
|
|
|
const relatedService4 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Review4 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Review4?.setService) {
|
|
await Review4.setService(relatedService4);
|
|
}
|
|
}
|
|
|
|
async function associateServiceWithProvider() {
|
|
const relatedProvider0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Service0 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Service0?.setProvider) {
|
|
await Service0.setProvider(relatedProvider0);
|
|
}
|
|
|
|
const relatedProvider1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Service1 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Service1?.setProvider) {
|
|
await Service1.setProvider(relatedProvider1);
|
|
}
|
|
|
|
const relatedProvider2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Service2 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Service2?.setProvider) {
|
|
await Service2.setProvider(relatedProvider2);
|
|
}
|
|
|
|
const relatedProvider3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Service3 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Service3?.setProvider) {
|
|
await Service3.setProvider(relatedProvider3);
|
|
}
|
|
|
|
const relatedProvider4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Service4 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Service4?.setProvider) {
|
|
await Service4.setProvider(relatedProvider4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Bookings.bulkCreate(BookingsData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Reviews.bulkCreate(ReviewsData);
|
|
|
|
await Services.bulkCreate(ServicesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateBookingWithCustomer(),
|
|
|
|
await associateBookingWithService(),
|
|
|
|
await associateOrderWithCustomer(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateReviewWithUser(),
|
|
|
|
await associateReviewWithProduct(),
|
|
|
|
await associateReviewWithService(),
|
|
|
|
await associateServiceWithProvider(),
|
|
|
|
// Similar logic for "relation_many"
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('bookings', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
|
|
await queryInterface.bulkDelete('reviews', null, {});
|
|
|
|
await queryInterface.bulkDelete('services', null, {});
|
|
},
|
|
};
|