Skip to content

Commit 819f132

Browse files
author
Your GitHub Username
committed
calendar
1 parent 6e59240 commit 819f132

File tree

6 files changed

+942
-5
lines changed

6 files changed

+942
-5
lines changed

index.js

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,104 @@
11
const express = require('express');
22
const cors = require('cors');
3+
const AvailabilityService = require('./services/availabilityService');
4+
35
const app = express();
46
const port = 3000;
57

68
app.use(cors());
79
app.use(express.json());
810

911
app.get('/', (req, res) => {
10-
res.json({
11-
project: 'LeaseFlow Protocol',
12+
res.json({
13+
project: 'LeaseFlow Protocol',
1214
status: 'Active',
1315
contract_id: 'CAEGD57WVTVQSYWYB23AISBW334QO7WNA5XQ56S45GH6BP3D2AVHKUG4'
1416
});
1517
});
1618

19+
app.get('/api/asset/:id/availability', async (req, res) => {
20+
try {
21+
const { id } = req.params;
22+
23+
if (!id || isNaN(id)) {
24+
return res.status(400).json({
25+
error: 'Invalid asset ID. Must be a number.',
26+
code: 'INVALID_ASSET_ID'
27+
});
28+
}
29+
30+
const availability = await availabilityService.getAssetAvailability(id);
31+
32+
res.json({
33+
success: true,
34+
data: availability
35+
});
36+
37+
} catch (error) {
38+
console.error(`Error fetching availability for asset ${req.params.id}:`, error);
39+
40+
res.status(500).json({
41+
error: 'Failed to fetch asset availability',
42+
code: 'FETCH_ERROR',
43+
details: process.env.NODE_ENV === 'development' ? error.message : undefined
44+
});
45+
}
46+
});
47+
48+
app.get('/api/assets/availability', async (req, res) => {
49+
try {
50+
const { ids } = req.query;
51+
52+
if (ids) {
53+
const assetIds = ids.split(',').map(id => id.trim()).filter(id => id && !isNaN(id));
54+
55+
if (assetIds.length === 0) {
56+
return res.status(400).json({
57+
error: 'No valid asset IDs provided',
58+
code: 'INVALID_ASSET_IDS'
59+
});
60+
}
61+
62+
const availability = await availabilityService.getMultipleAssetAvailability(assetIds);
63+
64+
res.json({
65+
success: true,
66+
data: availability
67+
});
68+
} else {
69+
const availability = await availabilityService.getAllAssetsAvailability();
70+
71+
res.json({
72+
success: true,
73+
data: availability
74+
});
75+
}
76+
77+
} catch (error) {
78+
console.error('Error fetching assets availability:', error);
79+
80+
res.status(500).json({
81+
error: 'Failed to fetch assets availability',
82+
code: 'FETCH_ERROR',
83+
details: process.env.NODE_ENV === 'development' ? error.message : undefined
84+
});
85+
}
86+
});
87+
1788
if (require.main === module) {
18-
app.listen(port, () => {
19-
console.log(`LeaseFlow Backend listening at http://localhost:${port}`);
89+
const availabilityService = new AvailabilityService();
90+
91+
availabilityService.initialize().then(() => {
92+
app.locals.availabilityService = availabilityService;
93+
app.listen(port, () => {
94+
console.log(`LeaseFlow Backend listening at http://localhost:${port}`);
95+
console.log('Availability Service started');
96+
});
97+
}).catch(error => {
98+
console.error('Failed to initialize Availability Service:', error);
99+
process.exit(1);
20100
});
21101
}
22102

103+
const availabilityService = new AvailabilityService();
23104
module.exports = app;

package-lock.json

Lines changed: 150 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"test": "jest"
99
},
1010
"dependencies": {
11+
"algosdk": "^2.0.0",
1112
"cors": "^2.8.6",
1213
"dotenv": "^17.3.1",
1314
"express": "^5.2.1"
@@ -16,4 +17,4 @@
1617
"jest": "^30.3.0",
1718
"supertest": "^7.2.2"
1819
}
19-
}
20+
}

0 commit comments

Comments
 (0)