Tons of Stuff
Some checks failed
Deploy Backend to Docker / deploy (push) Failing after 6m13s
Deploy Backend to Docker / deploy-portainer (push) Has been skipped

This commit is contained in:
2025-12-03 20:19:40 -05:00
parent 0b86c88eb4
commit b7c2e0fc24
19 changed files with 1783 additions and 134 deletions

View File

@@ -4,23 +4,44 @@ import { PriceRepository } from '../../database/repository';
const repository = new PriceRepository();
export const priceRoutes: FastifyPluginAsync = async (server) => {
// GET /api/prices/latest - Get all current listings
// GET /api/prices/latest - Get all current listings with lowest price
server.get('/latest', async (request, reply) => {
try {
const prices = await repository.getLatestPrices();
if (prices.length === 0) {
return {
success: true,
data: {
timestamp: new Date(),
lowestPrice: 0,
platform: '',
sellerName: '',
allPrices: []
}
};
}
const lowestPrice = prices.reduce((min: any, p: any) =>
Number(p.usdPerMillion) < Number(min.usdPerMillion) ? p : min
);
return {
success: true,
data: prices.map((p: any) => ({
id: p.id,
timestamp: p.timestamp,
vendor: p.vendor,
seller: p.sellerName,
usdPrice: p.usdPrice.toString(),
auecAmount: p.auecAmount.toString(),
usdPerMillion: p.usdPerMillion.toString(),
deliveryTime: p.deliveryTime,
url: p.url,
})),
data: {
timestamp: new Date(),
lowestPrice: Number(lowestPrice.usdPerMillion),
platform: lowestPrice.vendor,
sellerName: lowestPrice.sellerName,
allPrices: prices.map((p: any) => ({
id: p.id,
platform: p.vendor,
sellerName: p.sellerName,
pricePerMillion: Number(p.usdPerMillion),
timestamp: p.timestamp,
url: p.url
}))
}
};
} catch (error) {
reply.code(500);