-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
141 lines (129 loc) · 4.33 KB
/
setup.js
File metadata and controls
141 lines (129 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { testConnection, syncDatabase } from './config/db.js';
import AuthService from './services/authService.js';
import LandService from './services/landService.js';
console.log('🚀 Setting up CLMS Development Environment...\n');
async function setupDevelopment() {
try {
// Test database connection
console.log('📊 Testing database connection...');
const connectionSuccess = await testConnection();
if (!connectionSuccess) {
console.log('❌ Database connection failed');
return;
}
// Sync database
console.log('🔄 Synchronizing database...');
await syncDatabase(true); // force: true to recreate tables
console.log('✅ Database synchronized\n');
// Create initial admin user
console.log('👤 Creating initial admin user...');
try {
const adminUser = await AuthService.register({
email: 'admin@gbewaa.com',
password: 'AdminPass123',
role: 'ADMIN',
firstName: 'System',
lastName: 'Administrator'
});
console.log('✅ Admin user created:', adminUser.email);
} catch (error) {
if (error.message.includes('already exists')) {
console.log('ℹ️ Admin user already exists');
} else {
throw error;
}
}
// Create sample staff user
console.log('👥 Creating sample staff user...');
try {
const staffUser = await AuthService.register({
email: 'staff@gbewaa.com',
password: 'StaffPass123',
role: 'STAFF',
firstName: 'John',
lastName: 'Staff'
});
console.log('✅ Staff user created:', staffUser.email);
} catch (error) {
if (error.message.includes('already exists')) {
console.log('ℹ️ Staff user already exists');
} else {
throw error;
}
}
// Create sample auditor user
console.log('📊 Creating sample auditor user...');
try {
const auditorUser = await AuthService.register({
email: 'auditor@gbewaa.com',
password: 'AuditorPass123',
role: 'AUDITOR',
firstName: 'Jane',
lastName: 'Auditor'
});
console.log('✅ Auditor user created:', auditorUser.email);
} catch (error) {
if (error.message.includes('already exists')) {
console.log('ℹ️ Auditor user already exists');
} else {
throw error;
}
}
// Create sample land plots
console.log('\n🏞️ Creating sample land plots...');
const samplePlots = [
{
plotNumber: 'GB001',
location: 'Tamale North District',
size: 2.5,
sizeUnit: 'ACRES',
ownerName: 'Gbewaa Palace',
description: 'Prime residential land near main road'
},
{
plotNumber: 'GB002',
location: 'Tamale South District',
size: 1.8,
sizeUnit: 'HECTARES',
ownerName: 'Gbewaa Palace',
status: 'RESERVED',
description: 'Commercial land with excellent access'
},
{
plotNumber: 'GB003',
location: 'Tamale Central District',
size: 3000,
sizeUnit: 'SQ_METERS',
ownerName: 'Gbewaa Palace',
description: 'Mixed-use development opportunity'
}
];
for (const plotData of samplePlots) {
try {
const plot = await LandService.createLandPlot(plotData);
console.log(`✅ Created plot: ${plot.plotNumber} - ${plot.getFormattedSize()}`);
} catch (error) {
if (error.message.includes('already exists')) {
console.log(`ℹ️ Plot ${plotData.plotNumber} already exists`);
} else {
throw error;
}
}
}
console.log('\n🎉 Development environment setup complete!');
console.log('\n📋 Summary:');
console.log('✅ Database connected and synchronized');
console.log('✅ Sample users created (admin, staff, auditor)');
console.log('✅ Sample land plots created');
console.log('\n🚀 You can now start the server with: npm run dev');
console.log('\n🔐 Login credentials:');
console.log(' Admin: admin@gbewaa.com / AdminPass123');
console.log(' Staff: staff@gbewaa.com / StaffPass123');
console.log(' Auditor: auditor@gbewaa.com / AuditorPass123');
} catch (error) {
console.error('❌ Setup failed:', error.message);
console.error(error);
}
process.exit(0);
}
setupDevelopment();