1053 lines
25 KiB
JavaScript
1053 lines
25 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Bookings = db.bookings;
|
|
|
|
const CleaningSchedules = db.cleaning_schedules;
|
|
|
|
const Listings = db.listings;
|
|
|
|
const Reviews = db.reviews;
|
|
|
|
const Agencies = db.agencies;
|
|
|
|
const BookingsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
check_in: new Date('2025-05-10T14:00:00Z'),
|
|
|
|
check_out: new Date('2025-05-15T10:00:00Z'),
|
|
|
|
total_price: 600,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
check_in: new Date('2025-06-01T14:00:00Z'),
|
|
|
|
check_out: new Date('2025-06-07T10:00:00Z'),
|
|
|
|
total_price: 900,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
check_in: new Date('2025-07-15T14:00:00Z'),
|
|
|
|
check_out: new Date('2025-07-20T10:00:00Z'),
|
|
|
|
total_price: 1000,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
check_in: new Date('2025-08-05T14:00:00Z'),
|
|
|
|
check_out: new Date('2025-08-10T10:00:00Z'),
|
|
|
|
total_price: 900,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
check_in: new Date('2025-09-10T14:00:00Z'),
|
|
|
|
check_out: new Date('2025-09-15T10:00:00Z'),
|
|
|
|
total_price: 1500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CleaningSchedulesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_date: new Date('2025-05-15T12:00:00Z'),
|
|
|
|
completed: false,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_date: new Date('2025-06-07T12:00:00Z'),
|
|
|
|
completed: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_date: new Date('2025-07-20T12:00:00Z'),
|
|
|
|
completed: false,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_date: new Date('2025-08-10T12:00:00Z'),
|
|
|
|
completed: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_date: new Date('2025-09-15T12:00:00Z'),
|
|
|
|
completed: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ListingsData = [
|
|
{
|
|
title: 'Charming Cottage',
|
|
|
|
description: 'A cozy cottage in the countryside.',
|
|
|
|
// type code here for "images" field
|
|
|
|
price_per_night: 120,
|
|
|
|
status: 'unavailable',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Modern Apartment',
|
|
|
|
description: 'A stylish apartment in the city center.',
|
|
|
|
// type code here for "images" field
|
|
|
|
price_per_night: 150,
|
|
|
|
status: 'unavailable',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Beach House',
|
|
|
|
description: 'A beautiful house by the beach.',
|
|
|
|
// type code here for "images" field
|
|
|
|
price_per_night: 200,
|
|
|
|
status: 'available',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Mountain Cabin',
|
|
|
|
description: 'A rustic cabin in the mountains.',
|
|
|
|
// type code here for "images" field
|
|
|
|
price_per_night: 180,
|
|
|
|
status: 'booked',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Luxury Villa',
|
|
|
|
description: 'A luxurious villa with a private pool.',
|
|
|
|
// type code here for "images" field
|
|
|
|
price_per_night: 300,
|
|
|
|
status: 'booked',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ReviewsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 5,
|
|
|
|
comment: 'Amazing stay, highly recommend!',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 4,
|
|
|
|
comment: 'Great location, very comfortable.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 5,
|
|
|
|
comment: 'Beautiful house, perfect for a getaway.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 3,
|
|
|
|
comment: 'Nice cabin, but a bit remote.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 5,
|
|
|
|
comment: 'Luxurious and relaxing, worth every penny.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const AgenciesData = [
|
|
{
|
|
name: 'Sunshine Rentals',
|
|
},
|
|
|
|
{
|
|
name: 'Cozy Stays',
|
|
},
|
|
|
|
{
|
|
name: 'Urban Escapes',
|
|
},
|
|
|
|
{
|
|
name: 'Mountain Retreats',
|
|
},
|
|
|
|
{
|
|
name: 'Beachfront Villas',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithAgency() {
|
|
const relatedAgency0 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setAgency) {
|
|
await User0.setAgency(relatedAgency0);
|
|
}
|
|
|
|
const relatedAgency1 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setAgency) {
|
|
await User1.setAgency(relatedAgency1);
|
|
}
|
|
|
|
const relatedAgency2 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setAgency) {
|
|
await User2.setAgency(relatedAgency2);
|
|
}
|
|
|
|
const relatedAgency3 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setAgency) {
|
|
await User3.setAgency(relatedAgency3);
|
|
}
|
|
|
|
const relatedAgency4 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const User4 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (User4?.setAgency) {
|
|
await User4.setAgency(relatedAgency4);
|
|
}
|
|
}
|
|
|
|
async function associateBookingWithListing() {
|
|
const relatedListing0 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Booking0 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Booking0?.setListing) {
|
|
await Booking0.setListing(relatedListing0);
|
|
}
|
|
|
|
const relatedListing1 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Booking1 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Booking1?.setListing) {
|
|
await Booking1.setListing(relatedListing1);
|
|
}
|
|
|
|
const relatedListing2 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Booking2 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Booking2?.setListing) {
|
|
await Booking2.setListing(relatedListing2);
|
|
}
|
|
|
|
const relatedListing3 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Booking3 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Booking3?.setListing) {
|
|
await Booking3.setListing(relatedListing3);
|
|
}
|
|
|
|
const relatedListing4 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Booking4 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Booking4?.setListing) {
|
|
await Booking4.setListing(relatedListing4);
|
|
}
|
|
}
|
|
|
|
async function associateBookingWithTraveler() {
|
|
const relatedTraveler0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking0 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Booking0?.setTraveler) {
|
|
await Booking0.setTraveler(relatedTraveler0);
|
|
}
|
|
|
|
const relatedTraveler1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking1 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Booking1?.setTraveler) {
|
|
await Booking1.setTraveler(relatedTraveler1);
|
|
}
|
|
|
|
const relatedTraveler2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking2 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Booking2?.setTraveler) {
|
|
await Booking2.setTraveler(relatedTraveler2);
|
|
}
|
|
|
|
const relatedTraveler3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking3 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Booking3?.setTraveler) {
|
|
await Booking3.setTraveler(relatedTraveler3);
|
|
}
|
|
|
|
const relatedTraveler4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking4 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Booking4?.setTraveler) {
|
|
await Booking4.setTraveler(relatedTraveler4);
|
|
}
|
|
}
|
|
|
|
async function associateBookingWithAgency() {
|
|
const relatedAgency0 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Booking0 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Booking0?.setAgency) {
|
|
await Booking0.setAgency(relatedAgency0);
|
|
}
|
|
|
|
const relatedAgency1 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Booking1 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Booking1?.setAgency) {
|
|
await Booking1.setAgency(relatedAgency1);
|
|
}
|
|
|
|
const relatedAgency2 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Booking2 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Booking2?.setAgency) {
|
|
await Booking2.setAgency(relatedAgency2);
|
|
}
|
|
|
|
const relatedAgency3 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Booking3 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Booking3?.setAgency) {
|
|
await Booking3.setAgency(relatedAgency3);
|
|
}
|
|
|
|
const relatedAgency4 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Booking4 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Booking4?.setAgency) {
|
|
await Booking4.setAgency(relatedAgency4);
|
|
}
|
|
}
|
|
|
|
async function associateCleaningScheduleWithListing() {
|
|
const relatedListing0 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const CleaningSchedule0 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CleaningSchedule0?.setListing) {
|
|
await CleaningSchedule0.setListing(relatedListing0);
|
|
}
|
|
|
|
const relatedListing1 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const CleaningSchedule1 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CleaningSchedule1?.setListing) {
|
|
await CleaningSchedule1.setListing(relatedListing1);
|
|
}
|
|
|
|
const relatedListing2 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const CleaningSchedule2 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CleaningSchedule2?.setListing) {
|
|
await CleaningSchedule2.setListing(relatedListing2);
|
|
}
|
|
|
|
const relatedListing3 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const CleaningSchedule3 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CleaningSchedule3?.setListing) {
|
|
await CleaningSchedule3.setListing(relatedListing3);
|
|
}
|
|
|
|
const relatedListing4 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const CleaningSchedule4 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CleaningSchedule4?.setListing) {
|
|
await CleaningSchedule4.setListing(relatedListing4);
|
|
}
|
|
}
|
|
|
|
async function associateCleaningScheduleWithAgency() {
|
|
const relatedAgency0 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const CleaningSchedule0 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CleaningSchedule0?.setAgency) {
|
|
await CleaningSchedule0.setAgency(relatedAgency0);
|
|
}
|
|
|
|
const relatedAgency1 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const CleaningSchedule1 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CleaningSchedule1?.setAgency) {
|
|
await CleaningSchedule1.setAgency(relatedAgency1);
|
|
}
|
|
|
|
const relatedAgency2 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const CleaningSchedule2 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CleaningSchedule2?.setAgency) {
|
|
await CleaningSchedule2.setAgency(relatedAgency2);
|
|
}
|
|
|
|
const relatedAgency3 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const CleaningSchedule3 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CleaningSchedule3?.setAgency) {
|
|
await CleaningSchedule3.setAgency(relatedAgency3);
|
|
}
|
|
|
|
const relatedAgency4 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const CleaningSchedule4 = await CleaningSchedules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CleaningSchedule4?.setAgency) {
|
|
await CleaningSchedule4.setAgency(relatedAgency4);
|
|
}
|
|
}
|
|
|
|
async function associateListingWithHost() {
|
|
const relatedHost0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Listing0 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Listing0?.setHost) {
|
|
await Listing0.setHost(relatedHost0);
|
|
}
|
|
|
|
const relatedHost1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Listing1 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Listing1?.setHost) {
|
|
await Listing1.setHost(relatedHost1);
|
|
}
|
|
|
|
const relatedHost2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Listing2 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Listing2?.setHost) {
|
|
await Listing2.setHost(relatedHost2);
|
|
}
|
|
|
|
const relatedHost3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Listing3 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Listing3?.setHost) {
|
|
await Listing3.setHost(relatedHost3);
|
|
}
|
|
|
|
const relatedHost4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Listing4 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Listing4?.setHost) {
|
|
await Listing4.setHost(relatedHost4);
|
|
}
|
|
}
|
|
|
|
async function associateListingWithAgency() {
|
|
const relatedAgency0 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing0 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Listing0?.setAgency) {
|
|
await Listing0.setAgency(relatedAgency0);
|
|
}
|
|
|
|
const relatedAgency1 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing1 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Listing1?.setAgency) {
|
|
await Listing1.setAgency(relatedAgency1);
|
|
}
|
|
|
|
const relatedAgency2 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing2 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Listing2?.setAgency) {
|
|
await Listing2.setAgency(relatedAgency2);
|
|
}
|
|
|
|
const relatedAgency3 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing3 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Listing3?.setAgency) {
|
|
await Listing3.setAgency(relatedAgency3);
|
|
}
|
|
|
|
const relatedAgency4 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing4 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Listing4?.setAgency) {
|
|
await Listing4.setAgency(relatedAgency4);
|
|
}
|
|
}
|
|
|
|
async function associateListingWithAgency() {
|
|
const relatedAgency0 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing0 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Listing0?.setAgency) {
|
|
await Listing0.setAgency(relatedAgency0);
|
|
}
|
|
|
|
const relatedAgency1 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing1 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Listing1?.setAgency) {
|
|
await Listing1.setAgency(relatedAgency1);
|
|
}
|
|
|
|
const relatedAgency2 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing2 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Listing2?.setAgency) {
|
|
await Listing2.setAgency(relatedAgency2);
|
|
}
|
|
|
|
const relatedAgency3 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing3 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Listing3?.setAgency) {
|
|
await Listing3.setAgency(relatedAgency3);
|
|
}
|
|
|
|
const relatedAgency4 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Listing4 = await Listings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Listing4?.setAgency) {
|
|
await Listing4.setAgency(relatedAgency4);
|
|
}
|
|
}
|
|
|
|
async function associateReviewWithListing() {
|
|
const relatedListing0 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setListing) {
|
|
await Review0.setListing(relatedListing0);
|
|
}
|
|
|
|
const relatedListing1 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setListing) {
|
|
await Review1.setListing(relatedListing1);
|
|
}
|
|
|
|
const relatedListing2 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setListing) {
|
|
await Review2.setListing(relatedListing2);
|
|
}
|
|
|
|
const relatedListing3 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Review3 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Review3?.setListing) {
|
|
await Review3.setListing(relatedListing3);
|
|
}
|
|
|
|
const relatedListing4 = await Listings.findOne({
|
|
offset: Math.floor(Math.random() * (await Listings.count())),
|
|
});
|
|
const Review4 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Review4?.setListing) {
|
|
await Review4.setListing(relatedListing4);
|
|
}
|
|
}
|
|
|
|
async function associateReviewWithTraveler() {
|
|
const relatedTraveler0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setTraveler) {
|
|
await Review0.setTraveler(relatedTraveler0);
|
|
}
|
|
|
|
const relatedTraveler1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setTraveler) {
|
|
await Review1.setTraveler(relatedTraveler1);
|
|
}
|
|
|
|
const relatedTraveler2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setTraveler) {
|
|
await Review2.setTraveler(relatedTraveler2);
|
|
}
|
|
|
|
const relatedTraveler3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review3 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Review3?.setTraveler) {
|
|
await Review3.setTraveler(relatedTraveler3);
|
|
}
|
|
|
|
const relatedTraveler4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review4 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Review4?.setTraveler) {
|
|
await Review4.setTraveler(relatedTraveler4);
|
|
}
|
|
}
|
|
|
|
async function associateReviewWithAgency() {
|
|
const relatedAgency0 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setAgency) {
|
|
await Review0.setAgency(relatedAgency0);
|
|
}
|
|
|
|
const relatedAgency1 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setAgency) {
|
|
await Review1.setAgency(relatedAgency1);
|
|
}
|
|
|
|
const relatedAgency2 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setAgency) {
|
|
await Review2.setAgency(relatedAgency2);
|
|
}
|
|
|
|
const relatedAgency3 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Review3 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Review3?.setAgency) {
|
|
await Review3.setAgency(relatedAgency3);
|
|
}
|
|
|
|
const relatedAgency4 = await Agencies.findOne({
|
|
offset: Math.floor(Math.random() * (await Agencies.count())),
|
|
});
|
|
const Review4 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Review4?.setAgency) {
|
|
await Review4.setAgency(relatedAgency4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Bookings.bulkCreate(BookingsData);
|
|
|
|
await CleaningSchedules.bulkCreate(CleaningSchedulesData);
|
|
|
|
await Listings.bulkCreate(ListingsData);
|
|
|
|
await Reviews.bulkCreate(ReviewsData);
|
|
|
|
await Agencies.bulkCreate(AgenciesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithAgency(),
|
|
|
|
await associateBookingWithListing(),
|
|
|
|
await associateBookingWithTraveler(),
|
|
|
|
await associateBookingWithAgency(),
|
|
|
|
await associateCleaningScheduleWithListing(),
|
|
|
|
await associateCleaningScheduleWithAgency(),
|
|
|
|
await associateListingWithHost(),
|
|
|
|
await associateListingWithAgency(),
|
|
|
|
await associateListingWithAgency(),
|
|
|
|
await associateReviewWithListing(),
|
|
|
|
await associateReviewWithTraveler(),
|
|
|
|
await associateReviewWithAgency(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('bookings', null, {});
|
|
|
|
await queryInterface.bulkDelete('cleaning_schedules', null, {});
|
|
|
|
await queryInterface.bulkDelete('listings', null, {});
|
|
|
|
await queryInterface.bulkDelete('reviews', null, {});
|
|
|
|
await queryInterface.bulkDelete('agencies', null, {});
|
|
},
|
|
};
|