37822-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-01-26 05:10:22 +00:00

2629 lines
50 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Listings = db.listings;
const Locations = db.locations;
const Amenities = db.amenities;
const Inquiries = db.inquiries;
const Offers = db.offers;
const Viewings = db.viewings;
const Reviews = db.reviews;
const BlogPosts = db.blog_posts;
const Files = db.files;
const ListingsData = [
{
"title": "Spacious Family Home in Green Valley",
"description": "Beautiful 4 bedroom home with modern finishes and garden",
"status": "sold",
"property_type": "apartment",
"price": 425000.0,
"area": 220.5,
"bedrooms": 4,
"bathrooms": 3,
"address": "12 Oak Lane, Green Valley, OR",
// type code here for "relation_one" field
// type code here for "images" field
// type code here for "relation_one" field
// type code here for "relation_many" field
"published_at": new Date('2025-03-01T10:00:00Z'),
},
{
"title": "Riverside Commercial Plot",
"description": "Prime commercial land suitable for small retail development",
"status": "active",
"property_type": "commercial",
"price": 650000.0,
"area": 1500.0,
"bedrooms": 0,
"bathrooms": 0,
"address": "Lot 7 Riverside Blvd, Riverside, CA",
// type code here for "relation_one" field
// type code here for "images" field
// type code here for "relation_one" field
// type code here for "relation_many" field
"published_at": new Date('2025-02-15T09:30:00Z'),
},
{
"title": "Sunset Ridge Luxury Condo",
"description": "Modern 2 bedroom apartment with city views and amenities",
"status": "pending",
"property_type": "commercial",
"price": 320000.0,
"area": 95.0,
"bedrooms": 2,
"bathrooms": 2,
"address": "Unit 502, 88 Sunset Ave, Austin, TX",
// type code here for "relation_one" field
// type code here for "images" field
// type code here for "relation_one" field
// type code here for "relation_many" field
"published_at": new Date('2025-04-05T14:20:00Z'),
},
];
const LocationsData = [
{
"name": "Green Valley",
"city": "Springfield",
"state": "Oregon",
"country": "USA",
"latitude": 44.0462,
"longitude": -123.022,
},
{
"name": "Riverside Plains",
"city": "Riverside",
"state": "California",
"country": "USA",
"latitude": 33.9533,
"longitude": -117.3962,
},
{
"name": "Sunset Ridge",
"city": "Austin",
"state": "Texas",
"country": "USA",
"latitude": 30.2672,
"longitude": -97.7431,
},
];
const AmenitiesData = [
{
"name": "Swimming Pool",
"description": "Outdoor pool with lounge area",
"icon": "pool",
},
{
"name": "Garage",
"description": "Attached two car garage",
"icon": "garage",
},
{
"name": "Garden",
"description": "Private landscaped garden",
"icon": "flower",
},
];
const InquiriesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"contact_name": "Daniel Kim",
"contact_email": "daniel.kim@example.com",
"contact_phone": "+1-555-0105",
"message": "Interested in a weekend viewing and mortgage options",
"status": "closed",
"submitted_at": new Date('2025-03-05T12:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"contact_name": "Daniel Kim",
"contact_email": "daniel.kim@example.com",
"contact_phone": "+1-555-0105",
"message": "Is the condo pet friendly and what are HOA fees",
"status": "new",
"submitted_at": new Date('2025-04-06T08:30:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"contact_name": "Maria Gomez",
"contact_email": "maria.gomez@example.com",
"contact_phone": "+1-555-0104",
"message": "Can you share recent land surveys and zoning details",
"status": "responded",
"submitted_at": new Date('2025-02-20T15:10:00Z'),
},
];
const OffersData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"amount": 410000.0,
"offer_reference": "OFF-20250306-001",
"message": "Strong offer with flexible closing date",
"status": "accepted",
"submitted_at": new Date('2025-03-06T13:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"amount": 180000.0,
"offer_reference": "OFF-20250511-002",
"message": "Cash offer for the estate lot",
"status": "rejected",
"submitted_at": new Date('2025-05-11T10:15:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"amount": 525000.0,
"offer_reference": "OFF-20250126-003",
"message": "Offer contingent on inspection",
"status": "rejected",
"submitted_at": new Date('2025-01-26T12:20:00Z'),
},
];
const ViewingsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"subject": "Family home viewing",
"start": new Date('2025-03-08T10:00:00Z'),
"end": new Date('2025-03-08T10:45:00Z'),
"status": "cancelled",
"notes": "Client prefers morning visits",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"subject": "Condo walkthrough",
"start": new Date('2025-04-10T15:00:00Z'),
"end": new Date('2025-04-10T15:30:00Z'),
"status": "completed",
"notes": "Check balcony views and parking",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"subject": "Commercial lot inspection",
"start": new Date('2025-02-25T09:00:00Z'),
"end": new Date('2025-02-25T10:30:00Z'),
"status": "scheduled",
"notes": "Surveyor attended and provided report",
},
];
const ReviewsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 5,
"comment": "Wonderful neighborhood and great layout",
"created": new Date('2025-03-12T10:10:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 4,
"comment": "Clean condo and convenient location",
"created": new Date('2025-04-12T09:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 5,
"comment": "Perfect beach access and cozy interior",
"created": new Date('2025-02-02T14:30:00Z'),
},
];
const BlogPostsData = [
{
"title": "Preparing Your Land for Sale",
"slug": "preparing-your-land-for-sale",
"body": "Key steps to prepare land for sale including surveys and permits",
// type code here for "relation_one" field
// type code here for "images" field
"published_at": new Date('2025-02-01T08:00:00Z'),
},
{
"title": "Top Renovations That Add Value",
"slug": "top-renovations-add-value",
"body": "Affordable renovations that increase property resale value",
// type code here for "relation_one" field
// type code here for "images" field
"published_at": new Date('2025-03-18T10:30:00Z'),
},
{
"title": "Guide to Coastal Property Investment",
"slug": "coastal-property-investment",
"body": "What to consider when investing in coastal real estate",
// type code here for "relation_one" field
// type code here for "images" field
"published_at": new Date('2025-01-10T09:15:00Z'),
},
];
const FilesData = [
{
// type code here for "files" field
"title": "Green Valley Survey",
// type code here for "relation_one" field
// type code here for "relation_one" field
"uploaded_at": new Date('2025-03-02T09:00:00Z'),
},
{
// type code here for "files" field
"title": "Riverside Zoning Report",
// type code here for "relation_one" field
// type code here for "relation_one" field
"uploaded_at": new Date('2025-02-18T13:20:00Z'),
},
{
// type code here for "files" field
"title": "Sunset Ridge Floorplan",
// type code here for "relation_one" field
// type code here for "relation_one" field
"uploaded_at": new Date('2025-04-01T11:10:00Z'),
},
];
// Similar logic for "relation_many"
async function associateListingWithLocation() {
const relatedLocation0 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const Listing0 = await Listings.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Listing0?.setLocation)
{
await
Listing0.
setLocation(relatedLocation0);
}
const relatedLocation1 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const Listing1 = await Listings.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Listing1?.setLocation)
{
await
Listing1.
setLocation(relatedLocation1);
}
const relatedLocation2 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const Listing2 = await Listings.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Listing2?.setLocation)
{
await
Listing2.
setLocation(relatedLocation2);
}
}
async function associateListingWithAgent() {
const relatedAgent0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Listing0 = await Listings.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Listing0?.setAgent)
{
await
Listing0.
setAgent(relatedAgent0);
}
const relatedAgent1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Listing1 = await Listings.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Listing1?.setAgent)
{
await
Listing1.
setAgent(relatedAgent1);
}
const relatedAgent2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Listing2 = await Listings.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Listing2?.setAgent)
{
await
Listing2.
setAgent(relatedAgent2);
}
}
// Similar logic for "relation_many"
async function associateInquiryWithListing() {
const relatedListing0 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Inquiry0 = await Inquiries.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Inquiry0?.setListing)
{
await
Inquiry0.
setListing(relatedListing0);
}
const relatedListing1 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Inquiry1 = await Inquiries.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Inquiry1?.setListing)
{
await
Inquiry1.
setListing(relatedListing1);
}
const relatedListing2 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Inquiry2 = await Inquiries.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Inquiry2?.setListing)
{
await
Inquiry2.
setListing(relatedListing2);
}
}
async function associateInquiryWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Inquiry0 = await Inquiries.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Inquiry0?.setUser)
{
await
Inquiry0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Inquiry1 = await Inquiries.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Inquiry1?.setUser)
{
await
Inquiry1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Inquiry2 = await Inquiries.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Inquiry2?.setUser)
{
await
Inquiry2.
setUser(relatedUser2);
}
}
async function associateOfferWithListing() {
const relatedListing0 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Offer0 = await Offers.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Offer0?.setListing)
{
await
Offer0.
setListing(relatedListing0);
}
const relatedListing1 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Offer1 = await Offers.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Offer1?.setListing)
{
await
Offer1.
setListing(relatedListing1);
}
const relatedListing2 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Offer2 = await Offers.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Offer2?.setListing)
{
await
Offer2.
setListing(relatedListing2);
}
}
async function associateOfferWithBuyer() {
const relatedBuyer0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Offer0 = await Offers.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Offer0?.setBuyer)
{
await
Offer0.
setBuyer(relatedBuyer0);
}
const relatedBuyer1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Offer1 = await Offers.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Offer1?.setBuyer)
{
await
Offer1.
setBuyer(relatedBuyer1);
}
const relatedBuyer2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Offer2 = await Offers.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Offer2?.setBuyer)
{
await
Offer2.
setBuyer(relatedBuyer2);
}
}
async function associateViewingWithListing() {
const relatedListing0 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Viewing0 = await Viewings.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Viewing0?.setListing)
{
await
Viewing0.
setListing(relatedListing0);
}
const relatedListing1 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Viewing1 = await Viewings.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Viewing1?.setListing)
{
await
Viewing1.
setListing(relatedListing1);
}
const relatedListing2 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const Viewing2 = await Viewings.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Viewing2?.setListing)
{
await
Viewing2.
setListing(relatedListing2);
}
}
async function associateViewingWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Viewing0 = await Viewings.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Viewing0?.setUser)
{
await
Viewing0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Viewing1 = await Viewings.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Viewing1?.setUser)
{
await
Viewing1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Viewing2 = await Viewings.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Viewing2?.setUser)
{
await
Viewing2.
setUser(relatedUser2);
}
}
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);
}
}
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);
}
}
async function associateBlogPostWithAuthor() {
const relatedAuthor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BlogPost0 = await BlogPosts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (BlogPost0?.setAuthor)
{
await
BlogPost0.
setAuthor(relatedAuthor0);
}
const relatedAuthor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BlogPost1 = await BlogPosts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (BlogPost1?.setAuthor)
{
await
BlogPost1.
setAuthor(relatedAuthor1);
}
const relatedAuthor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BlogPost2 = await BlogPosts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (BlogPost2?.setAuthor)
{
await
BlogPost2.
setAuthor(relatedAuthor2);
}
}
async function associateFileWithListing() {
const relatedListing0 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const File0 = await Files.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (File0?.setListing)
{
await
File0.
setListing(relatedListing0);
}
const relatedListing1 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const File1 = await Files.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (File1?.setListing)
{
await
File1.
setListing(relatedListing1);
}
const relatedListing2 = await Listings.findOne({
offset: Math.floor(Math.random() * (await Listings.count())),
});
const File2 = await Files.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (File2?.setListing)
{
await
File2.
setListing(relatedListing2);
}
}
async function associateFileWithUploaded_by() {
const relatedUploaded_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const File0 = await Files.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (File0?.setUploaded_by)
{
await
File0.
setUploaded_by(relatedUploaded_by0);
}
const relatedUploaded_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const File1 = await Files.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (File1?.setUploaded_by)
{
await
File1.
setUploaded_by(relatedUploaded_by1);
}
const relatedUploaded_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const File2 = await Files.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (File2?.setUploaded_by)
{
await
File2.
setUploaded_by(relatedUploaded_by2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Listings.bulkCreate(ListingsData);
await Locations.bulkCreate(LocationsData);
await Amenities.bulkCreate(AmenitiesData);
await Inquiries.bulkCreate(InquiriesData);
await Offers.bulkCreate(OffersData);
await Viewings.bulkCreate(ViewingsData);
await Reviews.bulkCreate(ReviewsData);
await BlogPosts.bulkCreate(BlogPostsData);
await Files.bulkCreate(FilesData);
await Promise.all([
// Similar logic for "relation_many"
await associateListingWithLocation(),
await associateListingWithAgent(),
// Similar logic for "relation_many"
await associateInquiryWithListing(),
await associateInquiryWithUser(),
await associateOfferWithListing(),
await associateOfferWithBuyer(),
await associateViewingWithListing(),
await associateViewingWithUser(),
await associateReviewWithListing(),
await associateReviewWithUser(),
await associateBlogPostWithAuthor(),
await associateFileWithListing(),
await associateFileWithUploaded_by(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('listings', null, {});
await queryInterface.bulkDelete('locations', null, {});
await queryInterface.bulkDelete('amenities', null, {});
await queryInterface.bulkDelete('inquiries', null, {});
await queryInterface.bulkDelete('offers', null, {});
await queryInterface.bulkDelete('viewings', null, {});
await queryInterface.bulkDelete('reviews', null, {});
await queryInterface.bulkDelete('blog_posts', null, {});
await queryInterface.bulkDelete('files', null, {});
},
};