Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions coordinator/src/persistence/orders-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,24 +595,4 @@ function deriveTransitions(status: OrderStatus): string[] {
default:
return [status];
}

async getMetrics(): Promise<OrderMetrics> {
const byStatus = await this.all<{ status: string; count: number }>(this.metricsByStatus);
const totalRow = await this.get<{ count: number }>(this.metricsTotal);
const lastUpdatedRow = await this.get<{ ts: number | null }>(this.metricsLastUpdated);

const statusMap: Record<string, number> = {};
for (const row of byStatus) {
statusMap[row.status] = Number(row.count);
}

return {
totalOrders: Number(totalRow?.count ?? 0),
byStatus: statusMap,
completedOrders: statusMap["completed"] ?? 0,
refundedOrders: statusMap["refunded"] ?? 0,
staleExpiredOrders: (statusMap["expired"] ?? 0) + (statusMap["failed"] ?? 0),
lastUpdatedTimestamp: lastUpdatedRow?.ts != null ? Number(lastUpdatedRow.ts) : null
};
}
}
15 changes: 15 additions & 0 deletions coordinator/src/server/routes/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ export function ordersRoutes(orders: OrderService): Router {
});

// Parameterized routes come AFTER specific routes
router.get("/orders/:id/transitions", async (req, res, next) => {
const id = req.params.id;
try {
const order = await orders.get(id);
if (!order) {
res.status(404).json({ error: "not_found" });
return;
}
const history = await orders.getTransitions(id);
res.json({ transitions: history });
} catch (err) {
next(err);
}
});

router.get("/orders/:id", async (req, res, next) => {
const id = req.params.id;
try {
Expand Down
Loading