feat(mcp): add GET /timers/sync-status endpoint (chronomind.syncStatus MCP tool)
This commit is contained in:
parent
cb79c9b3ad
commit
4a3ac76ff7
@ -136,6 +136,34 @@ export async function timerRoutes(app: FastifyInstance) {
|
|||||||
return { success: true };
|
return { success: true };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Sync status — returns timer + routine counts and latest sync timestamp.
|
||||||
|
// MCP tool: chronomind.syncStatus(userId) — instant ops visibility without querying raw data.
|
||||||
|
app.get('/timers/sync-status', async req => {
|
||||||
|
const auth = await extractAuth(req);
|
||||||
|
const { items: timers } = await repo.listTimers(auth.sub, PRODUCT_ID, {
|
||||||
|
limit: 1000,
|
||||||
|
offset: 0,
|
||||||
|
sortBy: 'createdAt',
|
||||||
|
sortOrder: 'desc',
|
||||||
|
});
|
||||||
|
|
||||||
|
const active = timers.filter(t => t.state === 'active' || t.state === 'warning').length;
|
||||||
|
const pending = timers.filter(t => t.state === 'paused').length;
|
||||||
|
const lastSyncedAt = timers[0]?.lastSyncedAt ?? null;
|
||||||
|
const conflictCount = timers.filter(t => t.syncVersion === 0).length;
|
||||||
|
|
||||||
|
return {
|
||||||
|
userId: auth.sub,
|
||||||
|
productId: PRODUCT_ID,
|
||||||
|
totalTimers: timers.length,
|
||||||
|
active,
|
||||||
|
pending,
|
||||||
|
conflictCount,
|
||||||
|
lastSyncedAt,
|
||||||
|
generatedAt: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Batch upsert (initial sync / offline queue flush)
|
// Batch upsert (initial sync / offline queue flush)
|
||||||
app.post('/timers/batch', async req => {
|
app.post('/timers/batch', async req => {
|
||||||
const auth = await extractAuth(req);
|
const auth = await extractAuth(req);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user