1124 lines
27 KiB
JavaScript
1124 lines
27 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Agreements = db.agreements;
|
|
|
|
const Contractors = db.contractors;
|
|
|
|
const Payments = db.payments;
|
|
|
|
const Properties = db.properties;
|
|
|
|
const RepairRequests = db.repair_requests;
|
|
|
|
const Rooms = db.rooms;
|
|
|
|
const Tenants = db.tenants;
|
|
|
|
const Companies = db.companies;
|
|
|
|
const AgreementsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "files" field
|
|
|
|
start_date: new Date('2023-01-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "files" field
|
|
|
|
start_date: new Date('2023-02-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "files" field
|
|
|
|
start_date: new Date('2023-03-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ContractorsData = [
|
|
{
|
|
name: 'FixIt Services',
|
|
|
|
service_type: 'Refurbishment',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'PlumbRight',
|
|
|
|
service_type: 'Electrician',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'RoofMasters',
|
|
|
|
service_type: 'Roof',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 500,
|
|
|
|
due_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 450,
|
|
|
|
due_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
status: 'Overdue',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 600,
|
|
|
|
due_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
status: 'Paid',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PropertiesData = [
|
|
{
|
|
description: 'Spacious 3-bedroom house with garden',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "images" field
|
|
|
|
amenities: 'KitchenFacilities',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
hmo_license_number: 'HMO123456',
|
|
|
|
license_issue_date: new Date('2023-01-15T00:00:00Z'),
|
|
|
|
license_expiry_date: new Date('2024-01-15T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Modern apartment with city view',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "images" field
|
|
|
|
amenities: 'SharedBathrooms',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
hmo_license_number: 'HMO654321',
|
|
|
|
license_issue_date: new Date('2023-02-20T00:00:00Z'),
|
|
|
|
license_expiry_date: new Date('2024-02-20T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Cozy studio near university',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "images" field
|
|
|
|
amenities: 'SharedBathrooms',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
hmo_license_number: 'HMO789012',
|
|
|
|
license_issue_date: new Date('2023-03-10T00:00:00Z'),
|
|
|
|
license_expiry_date: new Date('2024-03-10T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const RepairRequestsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
description: 'Leaky faucet in kitchen',
|
|
|
|
// type code here for "images" field
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
description: 'Broken window in living room',
|
|
|
|
// type code here for "images" field
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
description: 'Clogged drain in bathroom',
|
|
|
|
// type code here for "images" field
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const RoomsData = [
|
|
{
|
|
room_number: '101',
|
|
|
|
size: 15.5,
|
|
|
|
furnishings: 'Furnished',
|
|
|
|
ensuite_status: true,
|
|
|
|
description: 'Bright room with ensuite bathroom',
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
room_number: '102',
|
|
|
|
size: 12,
|
|
|
|
furnishings: 'Unfurnished',
|
|
|
|
ensuite_status: false,
|
|
|
|
description: 'Cozy room with shared bathroom',
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
room_number: '201',
|
|
|
|
size: 18,
|
|
|
|
furnishings: 'Furnished',
|
|
|
|
ensuite_status: true,
|
|
|
|
description: 'Spacious room with city view',
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TenantsData = [
|
|
{
|
|
first_name: 'John',
|
|
|
|
last_name: 'Doe',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Jane',
|
|
|
|
last_name: 'Smith',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Alice',
|
|
|
|
last_name: 'Johnson',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CompaniesData = [
|
|
{
|
|
name: 'Gustav Kirchhoff',
|
|
},
|
|
|
|
{
|
|
name: 'Johannes Kepler',
|
|
},
|
|
|
|
{
|
|
name: 'Murray Gell-Mann',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setCompany) {
|
|
await User0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setCompany) {
|
|
await User1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setCompany) {
|
|
await User2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associateAgreementWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Agreement0 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Agreement0?.setTenant) {
|
|
await Agreement0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Agreement1 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Agreement1?.setTenant) {
|
|
await Agreement1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Agreement2 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Agreement2?.setTenant) {
|
|
await Agreement2.setTenant(relatedTenant2);
|
|
}
|
|
}
|
|
|
|
async function associateAgreementWithProperty() {
|
|
const relatedProperty0 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Agreement0 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Agreement0?.setProperty) {
|
|
await Agreement0.setProperty(relatedProperty0);
|
|
}
|
|
|
|
const relatedProperty1 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Agreement1 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Agreement1?.setProperty) {
|
|
await Agreement1.setProperty(relatedProperty1);
|
|
}
|
|
|
|
const relatedProperty2 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Agreement2 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Agreement2?.setProperty) {
|
|
await Agreement2.setProperty(relatedProperty2);
|
|
}
|
|
}
|
|
|
|
async function associateAgreementWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Agreement0 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Agreement0?.setCompany) {
|
|
await Agreement0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Agreement1 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Agreement1?.setCompany) {
|
|
await Agreement1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Agreement2 = await Agreements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Agreement2?.setCompany) {
|
|
await Agreement2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateContractorWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Contractor0 = await Contractors.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Contractor0?.setCompany) {
|
|
await Contractor0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Contractor1 = await Contractors.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Contractor1?.setCompany) {
|
|
await Contractor1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Contractor2 = await Contractors.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Contractor2?.setCompany) {
|
|
await Contractor2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setTenant) {
|
|
await Payment0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setTenant) {
|
|
await Payment1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setTenant) {
|
|
await Payment2.setTenant(relatedTenant2);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithProperty() {
|
|
const relatedProperty0 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setProperty) {
|
|
await Payment0.setProperty(relatedProperty0);
|
|
}
|
|
|
|
const relatedProperty1 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setProperty) {
|
|
await Payment1.setProperty(relatedProperty1);
|
|
}
|
|
|
|
const relatedProperty2 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setProperty) {
|
|
await Payment2.setProperty(relatedProperty2);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setCompany) {
|
|
await Payment0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setCompany) {
|
|
await Payment1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setCompany) {
|
|
await Payment2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associatePropertyWithLandlord() {
|
|
const relatedLandlord0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Property0 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Property0?.setLandlord) {
|
|
await Property0.setLandlord(relatedLandlord0);
|
|
}
|
|
|
|
const relatedLandlord1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Property1 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Property1?.setLandlord) {
|
|
await Property1.setLandlord(relatedLandlord1);
|
|
}
|
|
|
|
const relatedLandlord2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Property2 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Property2?.setLandlord) {
|
|
await Property2.setLandlord(relatedLandlord2);
|
|
}
|
|
}
|
|
|
|
async function associatePropertyWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Property0 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Property0?.setCompany) {
|
|
await Property0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Property1 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Property1?.setCompany) {
|
|
await Property1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Property2 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Property2?.setCompany) {
|
|
await Property2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associateRepairRequestWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const RepairRequest0 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (RepairRequest0?.setTenant) {
|
|
await RepairRequest0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const RepairRequest1 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (RepairRequest1?.setTenant) {
|
|
await RepairRequest1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const RepairRequest2 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (RepairRequest2?.setTenant) {
|
|
await RepairRequest2.setTenant(relatedTenant2);
|
|
}
|
|
}
|
|
|
|
async function associateRepairRequestWithProperty() {
|
|
const relatedProperty0 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const RepairRequest0 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (RepairRequest0?.setProperty) {
|
|
await RepairRequest0.setProperty(relatedProperty0);
|
|
}
|
|
|
|
const relatedProperty1 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const RepairRequest1 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (RepairRequest1?.setProperty) {
|
|
await RepairRequest1.setProperty(relatedProperty1);
|
|
}
|
|
|
|
const relatedProperty2 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const RepairRequest2 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (RepairRequest2?.setProperty) {
|
|
await RepairRequest2.setProperty(relatedProperty2);
|
|
}
|
|
}
|
|
|
|
async function associateRepairRequestWithContractor() {
|
|
const relatedContractor0 = await Contractors.findOne({
|
|
offset: Math.floor(Math.random() * (await Contractors.count())),
|
|
});
|
|
const RepairRequest0 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (RepairRequest0?.setContractor) {
|
|
await RepairRequest0.setContractor(relatedContractor0);
|
|
}
|
|
|
|
const relatedContractor1 = await Contractors.findOne({
|
|
offset: Math.floor(Math.random() * (await Contractors.count())),
|
|
});
|
|
const RepairRequest1 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (RepairRequest1?.setContractor) {
|
|
await RepairRequest1.setContractor(relatedContractor1);
|
|
}
|
|
|
|
const relatedContractor2 = await Contractors.findOne({
|
|
offset: Math.floor(Math.random() * (await Contractors.count())),
|
|
});
|
|
const RepairRequest2 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (RepairRequest2?.setContractor) {
|
|
await RepairRequest2.setContractor(relatedContractor2);
|
|
}
|
|
}
|
|
|
|
async function associateRepairRequestWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const RepairRequest0 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (RepairRequest0?.setCompany) {
|
|
await RepairRequest0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const RepairRequest1 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (RepairRequest1?.setCompany) {
|
|
await RepairRequest1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const RepairRequest2 = await RepairRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (RepairRequest2?.setCompany) {
|
|
await RepairRequest2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associateRoomWithProperty() {
|
|
const relatedProperty0 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Room0 = await Rooms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Room0?.setProperty) {
|
|
await Room0.setProperty(relatedProperty0);
|
|
}
|
|
|
|
const relatedProperty1 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Room1 = await Rooms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Room1?.setProperty) {
|
|
await Room1.setProperty(relatedProperty1);
|
|
}
|
|
|
|
const relatedProperty2 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Room2 = await Rooms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Room2?.setProperty) {
|
|
await Room2.setProperty(relatedProperty2);
|
|
}
|
|
}
|
|
|
|
async function associateRoomWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Room0 = await Rooms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Room0?.setCompany) {
|
|
await Room0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Room1 = await Rooms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Room1?.setCompany) {
|
|
await Room1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Room2 = await Rooms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Room2?.setCompany) {
|
|
await Room2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associateTenantWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Tenant0 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Tenant0?.setUser) {
|
|
await Tenant0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Tenant1 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Tenant1?.setUser) {
|
|
await Tenant1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Tenant2 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Tenant2?.setUser) {
|
|
await Tenant2.setUser(relatedUser2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateTenantWithRoom() {
|
|
const relatedRoom0 = await Rooms.findOne({
|
|
offset: Math.floor(Math.random() * (await Rooms.count())),
|
|
});
|
|
const Tenant0 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Tenant0?.setRoom) {
|
|
await Tenant0.setRoom(relatedRoom0);
|
|
}
|
|
|
|
const relatedRoom1 = await Rooms.findOne({
|
|
offset: Math.floor(Math.random() * (await Rooms.count())),
|
|
});
|
|
const Tenant1 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Tenant1?.setRoom) {
|
|
await Tenant1.setRoom(relatedRoom1);
|
|
}
|
|
|
|
const relatedRoom2 = await Rooms.findOne({
|
|
offset: Math.floor(Math.random() * (await Rooms.count())),
|
|
});
|
|
const Tenant2 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Tenant2?.setRoom) {
|
|
await Tenant2.setRoom(relatedRoom2);
|
|
}
|
|
}
|
|
|
|
async function associateTenantWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Tenant0 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Tenant0?.setCompany) {
|
|
await Tenant0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Tenant1 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Tenant1?.setCompany) {
|
|
await Tenant1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Tenant2 = await Tenants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Tenant2?.setCompany) {
|
|
await Tenant2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Agreements.bulkCreate(AgreementsData);
|
|
|
|
await Contractors.bulkCreate(ContractorsData);
|
|
|
|
await Payments.bulkCreate(PaymentsData);
|
|
|
|
await Properties.bulkCreate(PropertiesData);
|
|
|
|
await RepairRequests.bulkCreate(RepairRequestsData);
|
|
|
|
await Rooms.bulkCreate(RoomsData);
|
|
|
|
await Tenants.bulkCreate(TenantsData);
|
|
|
|
await Companies.bulkCreate(CompaniesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithCompany(),
|
|
|
|
await associateAgreementWithTenant(),
|
|
|
|
await associateAgreementWithProperty(),
|
|
|
|
await associateAgreementWithCompany(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateContractorWithCompany(),
|
|
|
|
await associatePaymentWithTenant(),
|
|
|
|
await associatePaymentWithProperty(),
|
|
|
|
await associatePaymentWithCompany(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associatePropertyWithLandlord(),
|
|
|
|
await associatePropertyWithCompany(),
|
|
|
|
await associateRepairRequestWithTenant(),
|
|
|
|
await associateRepairRequestWithProperty(),
|
|
|
|
await associateRepairRequestWithContractor(),
|
|
|
|
await associateRepairRequestWithCompany(),
|
|
|
|
await associateRoomWithProperty(),
|
|
|
|
await associateRoomWithCompany(),
|
|
|
|
await associateTenantWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateTenantWithRoom(),
|
|
|
|
await associateTenantWithCompany(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('agreements', null, {});
|
|
|
|
await queryInterface.bulkDelete('contractors', null, {});
|
|
|
|
await queryInterface.bulkDelete('payments', null, {});
|
|
|
|
await queryInterface.bulkDelete('properties', null, {});
|
|
|
|
await queryInterface.bulkDelete('repair_requests', null, {});
|
|
|
|
await queryInterface.bulkDelete('rooms', null, {});
|
|
|
|
await queryInterface.bulkDelete('tenants', null, {});
|
|
|
|
await queryInterface.bulkDelete('companies', null, {});
|
|
},
|
|
};
|