dld_backend/load_sample_data.js
2025-10-30 12:13:02 +05:30

222 lines
6.9 KiB
JavaScript

const fs = require('fs');
const database = require('./src/models/database');
async function loadSampleData() {
try {
console.log('🔄 Loading sample data into database...');
// Create sample data for testing
const sampleRents = [
{
registration_date: '2025-08-01 10:00:00',
start_date: '2025-08-01',
end_date: '2026-07-31',
version_en: 'v1.0',
area_en: 'business bay',
contract_amount: 90000,
annual_amount: 90000,
is_free_hold_en: 'freehold',
actual_area: 1000,
prop_type_en: 'unit',
prop_sub_type_en: 'flat',
rooms: 2,
usage_en: 'residential',
total_properties: 1
},
{
registration_date: '2025-09-01 10:00:00',
start_date: '2025-09-01',
end_date: '2026-08-31',
version_en: 'v1.0',
area_en: 'business bay',
contract_amount: 85000,
annual_amount: 85000,
is_free_hold_en: 'freehold',
actual_area: 950,
prop_type_en: 'unit',
prop_sub_type_en: 'flat',
rooms: 2,
usage_en: 'residential',
total_properties: 1
},
{
registration_date: '2025-10-01 10:00:00',
start_date: '2025-10-01',
end_date: '2026-09-30',
version_en: 'v1.0',
area_en: 'business bay',
contract_amount: 92000,
annual_amount: 92000,
is_free_hold_en: 'freehold',
actual_area: 1050,
prop_type_en: 'unit',
prop_sub_type_en: 'flat',
rooms: 2,
usage_en: 'residential',
total_properties: 1
},
{
registration_date: '2025-08-01 10:00:00',
start_date: '2025-08-01',
end_date: '2026-07-31',
version_en: 'v1.0',
area_en: 'downtown',
contract_amount: 120000,
annual_amount: 120000,
is_free_hold_en: 'freehold',
actual_area: 1200,
prop_type_en: 'unit',
prop_sub_type_en: 'flat',
rooms: 3,
usage_en: 'residential',
total_properties: 1
},
{
registration_date: '2025-09-01 10:00:00',
start_date: '2025-09-01',
end_date: '2026-08-31',
version_en: 'v1.0',
area_en: 'downtown',
contract_amount: 115000,
annual_amount: 115000,
is_free_hold_en: 'freehold',
actual_area: 1150,
prop_type_en: 'unit',
prop_sub_type_en: 'flat',
rooms: 3,
usage_en: 'residential',
total_properties: 1
}
];
const sampleTransactions = [
{
transaction_number: 'TXN001',
instance_date: '2025-08-15 10:00:00',
group_en: 'residential',
procedure_en: 'sale',
is_offplan_en: 'ready',
is_free_hold_en: 'freehold',
usage_en: 'residential',
area_en: 'downtown',
prop_type_en: 'unit',
trans_value: 5000000,
actual_area: 1200,
total_buyer: 1,
total_seller: 1,
project_en: 'Burj Khalifa'
},
{
transaction_number: 'TXN002',
instance_date: '2025-09-10 10:00:00',
group_en: 'residential',
procedure_en: 'sale',
is_offplan_en: 'ready',
is_free_hold_en: 'freehold',
usage_en: 'residential',
area_en: 'marina',
prop_type_en: 'unit',
trans_value: 3000000,
actual_area: 1000,
total_buyer: 1,
total_seller: 1,
project_en: 'Marina Heights'
},
{
transaction_number: 'TXN003',
instance_date: '2025-08-20 10:00:00',
group_en: 'residential',
procedure_en: 'sale',
is_offplan_en: 'off-plan',
is_free_hold_en: 'freehold',
usage_en: 'residential',
area_en: 'business bay',
prop_type_en: 'unit',
trans_value: 2500000,
actual_area: 900,
total_buyer: 1,
total_seller: 1,
project_en: 'Business Bay Tower'
},
{
transaction_number: 'TXN004',
instance_date: '2025-09-05 10:00:00',
group_en: 'residential',
procedure_en: 'sale',
is_offplan_en: 'ready',
is_free_hold_en: 'freehold',
usage_en: 'residential',
area_en: 'jbr',
prop_type_en: 'unit',
trans_value: 2000000,
actual_area: 800,
total_buyer: 1,
total_seller: 1,
project_en: 'JBR Residences'
},
{
transaction_number: 'TXN005',
instance_date: '2025-10-01 10:00:00',
group_en: 'residential',
procedure_en: 'sale',
is_offplan_en: 'off-plan',
is_free_hold_en: 'freehold',
usage_en: 'residential',
area_en: 'dubai hills',
prop_type_en: 'unit',
trans_value: 1800000,
actual_area: 750,
total_buyer: 1,
total_seller: 1,
project_en: 'Dubai Hills'
}
];
// Insert sample rents data
for (const rent of sampleRents) {
await database.query(`
INSERT INTO rents (registration_date, start_date, end_date, version_en, area_en, contract_amount, annual_amount, is_free_hold_en, actual_area, prop_type_en, prop_sub_type_en, rooms, usage_en, total_properties)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [
rent.registration_date, rent.start_date, rent.end_date, rent.version_en,
rent.area_en, rent.contract_amount, rent.annual_amount, rent.is_free_hold_en,
rent.actual_area, rent.prop_type_en, rent.prop_sub_type_en, rent.rooms,
rent.usage_en, rent.total_properties
]);
}
// Insert sample transactions data
for (const transaction of sampleTransactions) {
await database.query(`
INSERT INTO transactions (transaction_number, instance_date, group_en, procedure_en, is_offplan_en, is_free_hold_en, usage_en, area_en, prop_type_en, trans_value, actual_area, total_buyer, total_seller, project_en)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [
transaction.transaction_number, transaction.instance_date, transaction.group_en,
transaction.procedure_en, transaction.is_offplan_en, transaction.is_free_hold_en,
transaction.usage_en, transaction.area_en, transaction.prop_type_en,
transaction.trans_value, transaction.actual_area, transaction.total_buyer,
transaction.total_seller, transaction.project_en
]);
}
console.log('✅ Sample data loaded successfully!');
console.log(`📊 Loaded ${sampleRents.length} rental records`);
console.log(`📊 Loaded ${sampleTransactions.length} transaction records`);
} catch (error) {
console.error('❌ Error loading sample data:', error.message);
}
}
// Run if called directly
if (require.main === module) {
loadSampleData().then(() => {
process.exit(0);
}).catch(error => {
console.error('Failed to load sample data:', error);
process.exit(1);
});
}
module.exports = loadSampleData;