const db = require('../models'); const Users = db.users; const Contracts = db.contracts; const MaintenanceRequests = db.maintenance_requests; const Payments = db.payments; const Properties = db.properties; const ContractsData = [ { file: 'contract1.pdf', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field uploaded_at: new Date('2023-10-01T10:00:00Z'), status: 'flagged', }, { file: 'contract2.pdf', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field uploaded_at: new Date('2023-10-02T11:00:00Z'), status: 'flagged', }, { file: 'contract3.pdf', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field uploaded_at: new Date('2023-10-03T12:00:00Z'), status: 'approved', }, ]; const MaintenanceRequestsData = [ { // type code here for "relation_one" field description: 'Leaking faucet in kitchen', // type code here for "images" field status: 'open', submitted_at: new Date('2023-10-01T10:00:00Z'), }, { // type code here for "relation_one" field description: 'Broken window in living room', // type code here for "images" field status: 'open', submitted_at: new Date('2023-10-02T11:00:00Z'), }, { // type code here for "relation_one" field description: 'Heating system not working', // type code here for "images" field status: 'resolved', submitted_at: new Date('2023-10-03T12:00:00Z'), }, ]; const PaymentsData = [ { // type code here for "relation_one" field amount: 1500, payment_date: new Date('2023-10-01T10:00:00Z'), payment_method: 'credit_card', }, { // type code here for "relation_one" field amount: 2000, payment_date: new Date('2023-10-02T11:00:00Z'), payment_method: 'cash', }, { // type code here for "relation_one" field amount: 1800, payment_date: new Date('2023-10-03T12:00:00Z'), payment_method: 'credit_card', }, ]; const PropertiesData = [ { address: '123 Main St, Dubai', // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_many" field }, { address: '456 Elm St, Abu Dhabi', // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_many" field }, { address: '789 Oak St, Sharjah', // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_many" field }, ]; // Similar logic for "relation_many" async function associateContractWithTenant() { const relatedTenant0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract0 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Contract0?.setTenant) { await Contract0.setTenant(relatedTenant0); } const relatedTenant1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract1 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Contract1?.setTenant) { await Contract1.setTenant(relatedTenant1); } const relatedTenant2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract2 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Contract2?.setTenant) { await Contract2.setTenant(relatedTenant2); } } async function associateContractWithLandlord() { const relatedLandlord0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract0 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Contract0?.setLandlord) { await Contract0.setLandlord(relatedLandlord0); } const relatedLandlord1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract1 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Contract1?.setLandlord) { await Contract1.setLandlord(relatedLandlord1); } const relatedLandlord2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract2 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Contract2?.setLandlord) { await Contract2.setLandlord(relatedLandlord2); } } async function associateContractWithLegal_reviewer() { const relatedLegal_reviewer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract0 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Contract0?.setLegal_reviewer) { await Contract0.setLegal_reviewer(relatedLegal_reviewer0); } const relatedLegal_reviewer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract1 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Contract1?.setLegal_reviewer) { await Contract1.setLegal_reviewer(relatedLegal_reviewer1); } const relatedLegal_reviewer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contract2 = await Contracts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Contract2?.setLegal_reviewer) { await Contract2.setLegal_reviewer(relatedLegal_reviewer2); } } async function associateMaintenanceRequestWithTenant() { const relatedTenant0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const MaintenanceRequest0 = await MaintenanceRequests.findOne({ order: [['id', 'ASC']], offset: 0, }); if (MaintenanceRequest0?.setTenant) { await MaintenanceRequest0.setTenant(relatedTenant0); } const relatedTenant1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const MaintenanceRequest1 = await MaintenanceRequests.findOne({ order: [['id', 'ASC']], offset: 1, }); if (MaintenanceRequest1?.setTenant) { await MaintenanceRequest1.setTenant(relatedTenant1); } const relatedTenant2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const MaintenanceRequest2 = await MaintenanceRequests.findOne({ order: [['id', 'ASC']], offset: 2, }); if (MaintenanceRequest2?.setTenant) { await MaintenanceRequest2.setTenant(relatedTenant2); } } async function associatePaymentWithTenant() { const relatedTenant0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setTenant) { await Payment0.setTenant(relatedTenant0); } const relatedTenant1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setTenant) { await Payment1.setTenant(relatedTenant1); } const relatedTenant2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setTenant) { await Payment2.setTenant(relatedTenant2); } } // 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); } } // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Contracts.bulkCreate(ContractsData); await MaintenanceRequests.bulkCreate(MaintenanceRequestsData); await Payments.bulkCreate(PaymentsData); await Properties.bulkCreate(PropertiesData); await Promise.all([ // Similar logic for "relation_many" await associateContractWithTenant(), await associateContractWithLandlord(), await associateContractWithLegal_reviewer(), await associateMaintenanceRequestWithTenant(), await associatePaymentWithTenant(), // Similar logic for "relation_many" await associatePropertyWithLandlord(), // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('contracts', null, {}); await queryInterface.bulkDelete('maintenance_requests', null, {}); await queryInterface.bulkDelete('payments', null, {}); await queryInterface.bulkDelete('properties', null, {}); }, };