40049-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-05-21 15:05:36 +00:00

3880 lines
75 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const BoardingHouses = db.boarding_houses;
const BoardingHousePhotos = db.boarding_house_photos;
const Amenities = db.amenities;
const BoardingHouseAmenities = db.boarding_house_amenities;
const Applications = db.applications;
const Tenancies = db.tenancies;
const Payments = db.payments;
const Announcements = db.announcements;
const Conversations = db.conversations;
const Messages = db.messages;
const SavedBoardingHouses = db.saved_boarding_houses;
const SearchLogs = db.search_logs;
const BoardingHousesData = [
{
// type code here for "relation_one" field
"name": "Marie Curie",
"slug": "Grace Hopper",
"description": "Alan Turing",
"location_text": "Grace Hopper",
"monthly_price": 9.8,
"security_deposit": 4.8,
"billing_cycle": "weekly",
"rooms_total": 5,
"rooms_available": 7,
"max_occupants_per_room": 9,
"property_type": "boarding_house",
"status": "archived",
"allow_pets": true,
"allow_smoking": false,
"curfew_enforced": true,
"curfew_time": "Grace Hopper",
"rules": "Ada Lovelace",
"contact_name": "Ada Lovelace",
"contact_phone": "Grace Hopper",
"contact_email": "Alan Turing",
"published_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"name": "Marie Curie",
"slug": "Marie Curie",
"description": "Grace Hopper",
"location_text": "Alan Turing",
"monthly_price": 3.75,
"security_deposit": 1.04,
"billing_cycle": "weekly",
"rooms_total": 4,
"rooms_available": 8,
"max_occupants_per_room": 8,
"property_type": "dormitory",
"status": "unavailable",
"allow_pets": false,
"allow_smoking": true,
"curfew_enforced": false,
"curfew_time": "Ada Lovelace",
"rules": "Alan Turing",
"contact_name": "Ada Lovelace",
"contact_phone": "Marie Curie",
"contact_email": "Marie Curie",
"published_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"name": "Marie Curie",
"slug": "Marie Curie",
"description": "Grace Hopper",
"location_text": "Ada Lovelace",
"monthly_price": 7.23,
"security_deposit": 9.13,
"billing_cycle": "daily",
"rooms_total": 8,
"rooms_available": 8,
"max_occupants_per_room": 7,
"property_type": "apartment",
"status": "draft",
"allow_pets": true,
"allow_smoking": true,
"curfew_enforced": false,
"curfew_time": "Ada Lovelace",
"rules": "Alan Turing",
"contact_name": "Ada Lovelace",
"contact_phone": "Marie Curie",
"contact_email": "Marie Curie",
"published_at": new Date(Date.now()),
},
];
const BoardingHousePhotosData = [
{
// type code here for "relation_one" field
// type code here for "images" field
"caption": "Marie Curie",
"sort_order": 9,
"is_cover": false,
},
{
// type code here for "relation_one" field
// type code here for "images" field
"caption": "Grace Hopper",
"sort_order": 9,
"is_cover": false,
},
{
// type code here for "relation_one" field
// type code here for "images" field
"caption": "Marie Curie",
"sort_order": 9,
"is_cover": true,
},
];
const AmenitiesData = [
{
"name": "Grace Hopper",
"description": "Marie Curie",
"icon_name": "Marie Curie",
},
{
"name": "Marie Curie",
"description": "Alan Turing",
"icon_name": "Grace Hopper",
},
{
"name": "Alan Turing",
"description": "Grace Hopper",
"icon_name": "Alan Turing",
},
];
const BoardingHouseAmenitiesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"is_available": true,
"notes": "Alan Turing",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"is_available": true,
"notes": "Alan Turing",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"is_available": false,
"notes": "Alan Turing",
},
];
const ApplicationsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"applied_at": new Date(Date.now()),
"status": "cancelled",
"decision_at": new Date(Date.now()),
"message_to_landlord": "Grace Hopper",
"requested_occupants": 5,
"desired_move_in_at": new Date(Date.now()),
// type code here for "files" field
"landlord_notes": "Grace Hopper",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"applied_at": new Date(Date.now()),
"status": "cancelled",
"decision_at": new Date(Date.now()),
"message_to_landlord": "Ada Lovelace",
"requested_occupants": 2,
"desired_move_in_at": new Date(Date.now()),
// type code here for "files" field
"landlord_notes": "Grace Hopper",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"applied_at": new Date(Date.now()),
"status": "submitted",
"decision_at": new Date(Date.now()),
"message_to_landlord": "Grace Hopper",
"requested_occupants": 3,
"desired_move_in_at": new Date(Date.now()),
// type code here for "files" field
"landlord_notes": "Ada Lovelace",
},
];
const TenanciesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "ended",
"start_at": new Date(Date.now()),
"end_at": new Date(Date.now()),
"agreed_monthly_rent": 7.04,
"deposit_amount": 3.83,
"room_label": "Ada Lovelace",
"occupants": 6,
"notes": "Grace Hopper",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "ended",
"start_at": new Date(Date.now()),
"end_at": new Date(Date.now()),
"agreed_monthly_rent": 1.06,
"deposit_amount": 0.48,
"room_label": "Grace Hopper",
"occupants": 8,
"notes": "Grace Hopper",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "ended",
"start_at": new Date(Date.now()),
"end_at": new Date(Date.now()),
"agreed_monthly_rent": 1.33,
"deposit_amount": 4.1,
"room_label": "Alan Turing",
"occupants": 4,
"notes": "Alan Turing",
},
];
const PaymentsData = [
{
// type code here for "relation_one" field
"amount": 0.19,
"type": "other",
"status": "failed",
"due_at": new Date(Date.now()),
"paid_at": new Date(Date.now()),
"method": "card",
"reference_code": "Alan Turing",
// type code here for "files" field
"notes": "Grace Hopper",
},
{
// type code here for "relation_one" field
"amount": 7.15,
"type": "rent",
"status": "overdue",
"due_at": new Date(Date.now()),
"paid_at": new Date(Date.now()),
"method": "bank_transfer",
"reference_code": "Alan Turing",
// type code here for "files" field
"notes": "Marie Curie",
},
{
// type code here for "relation_one" field
"amount": 1.17,
"type": "utilities",
"status": "failed",
"due_at": new Date(Date.now()),
"paid_at": new Date(Date.now()),
"method": "other",
"reference_code": "Grace Hopper",
// type code here for "files" field
"notes": "Grace Hopper",
},
];
const AnnouncementsData = [
{
// type code here for "relation_one" field
"title": "Marie Curie",
"content": "Alan Turing",
"audience": "public",
"is_published": true,
"publish_at": new Date(Date.now()),
"expire_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"title": "Ada Lovelace",
"content": "Alan Turing",
"audience": "public",
"is_published": false,
"publish_at": new Date(Date.now()),
"expire_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"title": "Marie Curie",
"content": "Grace Hopper",
"audience": "tenants",
"is_published": false,
"publish_at": new Date(Date.now()),
"expire_at": new Date(Date.now()),
},
];
const ConversationsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "archived",
"last_message_at": new Date(Date.now()),
"subject": "Grace Hopper",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "archived",
"last_message_at": new Date(Date.now()),
"subject": "Alan Turing",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "archived",
"last_message_at": new Date(Date.now()),
"subject": "Marie Curie",
},
];
const MessagesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"body": "Grace Hopper",
// type code here for "files" field
"sent_at": new Date(Date.now()),
"is_read": false,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"body": "Alan Turing",
// type code here for "files" field
"sent_at": new Date(Date.now()),
"is_read": false,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"body": "Grace Hopper",
// type code here for "files" field
"sent_at": new Date(Date.now()),
"is_read": true,
},
];
const SavedBoardingHousesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"saved_at": new Date(Date.now()),
"note": "Alan Turing",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"saved_at": new Date(Date.now()),
"note": "Marie Curie",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"saved_at": new Date(Date.now()),
"note": "Grace Hopper",
},
];
const SearchLogsData = [
{
// type code here for "relation_one" field
"query_text": "Marie Curie",
"location_filter": "Marie Curie",
"min_price": 4.18,
"max_price": 7.01,
"min_rooms_available": 9,
"searched_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"query_text": "Grace Hopper",
"location_filter": "Grace Hopper",
"min_price": 1.04,
"max_price": 1.98,
"min_rooms_available": 3,
"searched_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"query_text": "Alan Turing",
"location_filter": "Alan Turing",
"min_price": 0.61,
"max_price": 5.77,
"min_rooms_available": 9,
"searched_at": new Date(Date.now()),
},
];
// Similar logic for "relation_many"
async function associateBoardingHousWithLandlord() {
const relatedLandlord0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BoardingHous0 = await BoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (BoardingHous0?.setLandlord)
{
await
BoardingHous0.
setLandlord(relatedLandlord0);
}
const relatedLandlord1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BoardingHous1 = await BoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (BoardingHous1?.setLandlord)
{
await
BoardingHous1.
setLandlord(relatedLandlord1);
}
const relatedLandlord2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BoardingHous2 = await BoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (BoardingHous2?.setLandlord)
{
await
BoardingHous2.
setLandlord(relatedLandlord2);
}
}
async function associateBoardingHousePhotoWithBoarding_house() {
const relatedBoarding_house0 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const BoardingHousePhoto0 = await BoardingHousePhotos.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (BoardingHousePhoto0?.setBoarding_house)
{
await
BoardingHousePhoto0.
setBoarding_house(relatedBoarding_house0);
}
const relatedBoarding_house1 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const BoardingHousePhoto1 = await BoardingHousePhotos.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (BoardingHousePhoto1?.setBoarding_house)
{
await
BoardingHousePhoto1.
setBoarding_house(relatedBoarding_house1);
}
const relatedBoarding_house2 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const BoardingHousePhoto2 = await BoardingHousePhotos.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (BoardingHousePhoto2?.setBoarding_house)
{
await
BoardingHousePhoto2.
setBoarding_house(relatedBoarding_house2);
}
}
async function associateBoardingHouseAmenityWithBoarding_house() {
const relatedBoarding_house0 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const BoardingHouseAmenity0 = await BoardingHouseAmenities.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (BoardingHouseAmenity0?.setBoarding_house)
{
await
BoardingHouseAmenity0.
setBoarding_house(relatedBoarding_house0);
}
const relatedBoarding_house1 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const BoardingHouseAmenity1 = await BoardingHouseAmenities.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (BoardingHouseAmenity1?.setBoarding_house)
{
await
BoardingHouseAmenity1.
setBoarding_house(relatedBoarding_house1);
}
const relatedBoarding_house2 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const BoardingHouseAmenity2 = await BoardingHouseAmenities.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (BoardingHouseAmenity2?.setBoarding_house)
{
await
BoardingHouseAmenity2.
setBoarding_house(relatedBoarding_house2);
}
}
async function associateBoardingHouseAmenityWithAmenity() {
const relatedAmenity0 = await Amenities.findOne({
offset: Math.floor(Math.random() * (await Amenities.count())),
});
const BoardingHouseAmenity0 = await BoardingHouseAmenities.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (BoardingHouseAmenity0?.setAmenity)
{
await
BoardingHouseAmenity0.
setAmenity(relatedAmenity0);
}
const relatedAmenity1 = await Amenities.findOne({
offset: Math.floor(Math.random() * (await Amenities.count())),
});
const BoardingHouseAmenity1 = await BoardingHouseAmenities.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (BoardingHouseAmenity1?.setAmenity)
{
await
BoardingHouseAmenity1.
setAmenity(relatedAmenity1);
}
const relatedAmenity2 = await Amenities.findOne({
offset: Math.floor(Math.random() * (await Amenities.count())),
});
const BoardingHouseAmenity2 = await BoardingHouseAmenities.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (BoardingHouseAmenity2?.setAmenity)
{
await
BoardingHouseAmenity2.
setAmenity(relatedAmenity2);
}
}
async function associateApplicationWithTenant() {
const relatedTenant0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Application0 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Application0?.setTenant)
{
await
Application0.
setTenant(relatedTenant0);
}
const relatedTenant1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Application1 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Application1?.setTenant)
{
await
Application1.
setTenant(relatedTenant1);
}
const relatedTenant2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Application2 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Application2?.setTenant)
{
await
Application2.
setTenant(relatedTenant2);
}
}
async function associateApplicationWithBoarding_house() {
const relatedBoarding_house0 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Application0 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Application0?.setBoarding_house)
{
await
Application0.
setBoarding_house(relatedBoarding_house0);
}
const relatedBoarding_house1 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Application1 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Application1?.setBoarding_house)
{
await
Application1.
setBoarding_house(relatedBoarding_house1);
}
const relatedBoarding_house2 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Application2 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Application2?.setBoarding_house)
{
await
Application2.
setBoarding_house(relatedBoarding_house2);
}
}
async function associateTenancyWithTenant() {
const relatedTenant0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Tenancy0 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Tenancy0?.setTenant)
{
await
Tenancy0.
setTenant(relatedTenant0);
}
const relatedTenant1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Tenancy1 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Tenancy1?.setTenant)
{
await
Tenancy1.
setTenant(relatedTenant1);
}
const relatedTenant2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Tenancy2 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Tenancy2?.setTenant)
{
await
Tenancy2.
setTenant(relatedTenant2);
}
}
async function associateTenancyWithBoarding_house() {
const relatedBoarding_house0 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Tenancy0 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Tenancy0?.setBoarding_house)
{
await
Tenancy0.
setBoarding_house(relatedBoarding_house0);
}
const relatedBoarding_house1 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Tenancy1 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Tenancy1?.setBoarding_house)
{
await
Tenancy1.
setBoarding_house(relatedBoarding_house1);
}
const relatedBoarding_house2 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Tenancy2 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Tenancy2?.setBoarding_house)
{
await
Tenancy2.
setBoarding_house(relatedBoarding_house2);
}
}
async function associateTenancyWithApplication() {
const relatedApplication0 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const Tenancy0 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Tenancy0?.setApplication)
{
await
Tenancy0.
setApplication(relatedApplication0);
}
const relatedApplication1 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const Tenancy1 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Tenancy1?.setApplication)
{
await
Tenancy1.
setApplication(relatedApplication1);
}
const relatedApplication2 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const Tenancy2 = await Tenancies.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Tenancy2?.setApplication)
{
await
Tenancy2.
setApplication(relatedApplication2);
}
}
async function associatePaymentWithTenancy() {
const relatedTenancy0 = await Tenancies.findOne({
offset: Math.floor(Math.random() * (await Tenancies.count())),
});
const Payment0 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Payment0?.setTenancy)
{
await
Payment0.
setTenancy(relatedTenancy0);
}
const relatedTenancy1 = await Tenancies.findOne({
offset: Math.floor(Math.random() * (await Tenancies.count())),
});
const Payment1 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Payment1?.setTenancy)
{
await
Payment1.
setTenancy(relatedTenancy1);
}
const relatedTenancy2 = await Tenancies.findOne({
offset: Math.floor(Math.random() * (await Tenancies.count())),
});
const Payment2 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Payment2?.setTenancy)
{
await
Payment2.
setTenancy(relatedTenancy2);
}
}
async function associateAnnouncementWithBoarding_house() {
const relatedBoarding_house0 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Announcement0 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Announcement0?.setBoarding_house)
{
await
Announcement0.
setBoarding_house(relatedBoarding_house0);
}
const relatedBoarding_house1 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Announcement1 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Announcement1?.setBoarding_house)
{
await
Announcement1.
setBoarding_house(relatedBoarding_house1);
}
const relatedBoarding_house2 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Announcement2 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Announcement2?.setBoarding_house)
{
await
Announcement2.
setBoarding_house(relatedBoarding_house2);
}
}
async function associateConversationWithBoarding_house() {
const relatedBoarding_house0 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Conversation0 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Conversation0?.setBoarding_house)
{
await
Conversation0.
setBoarding_house(relatedBoarding_house0);
}
const relatedBoarding_house1 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Conversation1 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Conversation1?.setBoarding_house)
{
await
Conversation1.
setBoarding_house(relatedBoarding_house1);
}
const relatedBoarding_house2 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const Conversation2 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Conversation2?.setBoarding_house)
{
await
Conversation2.
setBoarding_house(relatedBoarding_house2);
}
}
async function associateConversationWithTenant() {
const relatedTenant0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation0 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Conversation0?.setTenant)
{
await
Conversation0.
setTenant(relatedTenant0);
}
const relatedTenant1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation1 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Conversation1?.setTenant)
{
await
Conversation1.
setTenant(relatedTenant1);
}
const relatedTenant2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation2 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Conversation2?.setTenant)
{
await
Conversation2.
setTenant(relatedTenant2);
}
}
async function associateConversationWithLandlord() {
const relatedLandlord0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation0 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Conversation0?.setLandlord)
{
await
Conversation0.
setLandlord(relatedLandlord0);
}
const relatedLandlord1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation1 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Conversation1?.setLandlord)
{
await
Conversation1.
setLandlord(relatedLandlord1);
}
const relatedLandlord2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation2 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Conversation2?.setLandlord)
{
await
Conversation2.
setLandlord(relatedLandlord2);
}
}
async function associateMessageWithConversation() {
const relatedConversation0 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message0 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Message0?.setConversation)
{
await
Message0.
setConversation(relatedConversation0);
}
const relatedConversation1 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message1 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Message1?.setConversation)
{
await
Message1.
setConversation(relatedConversation1);
}
const relatedConversation2 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message2 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Message2?.setConversation)
{
await
Message2.
setConversation(relatedConversation2);
}
}
async function associateMessageWithSender() {
const relatedSender0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message0 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Message0?.setSender)
{
await
Message0.
setSender(relatedSender0);
}
const relatedSender1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message1 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Message1?.setSender)
{
await
Message1.
setSender(relatedSender1);
}
const relatedSender2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message2 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Message2?.setSender)
{
await
Message2.
setSender(relatedSender2);
}
}
async function associateSavedBoardingHousWithTenant() {
const relatedTenant0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SavedBoardingHous0 = await SavedBoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SavedBoardingHous0?.setTenant)
{
await
SavedBoardingHous0.
setTenant(relatedTenant0);
}
const relatedTenant1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SavedBoardingHous1 = await SavedBoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SavedBoardingHous1?.setTenant)
{
await
SavedBoardingHous1.
setTenant(relatedTenant1);
}
const relatedTenant2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SavedBoardingHous2 = await SavedBoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SavedBoardingHous2?.setTenant)
{
await
SavedBoardingHous2.
setTenant(relatedTenant2);
}
}
async function associateSavedBoardingHousWithBoarding_house() {
const relatedBoarding_house0 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const SavedBoardingHous0 = await SavedBoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SavedBoardingHous0?.setBoarding_house)
{
await
SavedBoardingHous0.
setBoarding_house(relatedBoarding_house0);
}
const relatedBoarding_house1 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const SavedBoardingHous1 = await SavedBoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SavedBoardingHous1?.setBoarding_house)
{
await
SavedBoardingHous1.
setBoarding_house(relatedBoarding_house1);
}
const relatedBoarding_house2 = await BoardingHouses.findOne({
offset: Math.floor(Math.random() * (await BoardingHouses.count())),
});
const SavedBoardingHous2 = await SavedBoardingHouses.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SavedBoardingHous2?.setBoarding_house)
{
await
SavedBoardingHous2.
setBoarding_house(relatedBoarding_house2);
}
}
async function associateSearchLogWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SearchLog0 = await SearchLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SearchLog0?.setUser)
{
await
SearchLog0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SearchLog1 = await SearchLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SearchLog1?.setUser)
{
await
SearchLog1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SearchLog2 = await SearchLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SearchLog2?.setUser)
{
await
SearchLog2.
setUser(relatedUser2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await BoardingHouses.bulkCreate(BoardingHousesData);
await BoardingHousePhotos.bulkCreate(BoardingHousePhotosData);
await Amenities.bulkCreate(AmenitiesData);
await BoardingHouseAmenities.bulkCreate(BoardingHouseAmenitiesData);
await Applications.bulkCreate(ApplicationsData);
await Tenancies.bulkCreate(TenanciesData);
await Payments.bulkCreate(PaymentsData);
await Announcements.bulkCreate(AnnouncementsData);
await Conversations.bulkCreate(ConversationsData);
await Messages.bulkCreate(MessagesData);
await SavedBoardingHouses.bulkCreate(SavedBoardingHousesData);
await SearchLogs.bulkCreate(SearchLogsData);
await Promise.all([
// Similar logic for "relation_many"
await associateBoardingHousWithLandlord(),
await associateBoardingHousePhotoWithBoarding_house(),
await associateBoardingHouseAmenityWithBoarding_house(),
await associateBoardingHouseAmenityWithAmenity(),
await associateApplicationWithTenant(),
await associateApplicationWithBoarding_house(),
await associateTenancyWithTenant(),
await associateTenancyWithBoarding_house(),
await associateTenancyWithApplication(),
await associatePaymentWithTenancy(),
await associateAnnouncementWithBoarding_house(),
await associateConversationWithBoarding_house(),
await associateConversationWithTenant(),
await associateConversationWithLandlord(),
await associateMessageWithConversation(),
await associateMessageWithSender(),
await associateSavedBoardingHousWithTenant(),
await associateSavedBoardingHousWithBoarding_house(),
await associateSearchLogWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('boarding_houses', null, {});
await queryInterface.bulkDelete('boarding_house_photos', null, {});
await queryInterface.bulkDelete('amenities', null, {});
await queryInterface.bulkDelete('boarding_house_amenities', null, {});
await queryInterface.bulkDelete('applications', null, {});
await queryInterface.bulkDelete('tenancies', null, {});
await queryInterface.bulkDelete('payments', null, {});
await queryInterface.bulkDelete('announcements', null, {});
await queryInterface.bulkDelete('conversations', null, {});
await queryInterface.bulkDelete('messages', null, {});
await queryInterface.bulkDelete('saved_boarding_houses', null, {});
await queryInterface.bulkDelete('search_logs', null, {});
},
};