- Server: NIP-98 nostr auth (session cookies), BTC Map sync, claim/link/field routes, physical-presence checks via geolocation distance. 31 tests passing. - Frontend: Leaflet map, team pick, claim/link UI, Archipelago identity bridge vendored (nostr-provider.js) for dashboard launch support. - Verified end-to-end against the live BTC Map API (167 real Madeira places) and via genuine NIP-98-signed HTTP requests against the built app.
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import type { FastifyInstance } from 'fastify';
|
|
|
|
export default async function placesRoutes(app: FastifyInstance) {
|
|
const { db } = app.ctx;
|
|
|
|
const listPlaces = db.prepare(`
|
|
SELECT p.*, c.team AS claim_team, c.claimed_by_pubkey, c.claimed_at
|
|
FROM places p
|
|
LEFT JOIN claims c ON c.place_id = p.id
|
|
ORDER BY p.id
|
|
`);
|
|
const getPlace = db.prepare(`
|
|
SELECT p.*, c.team AS claim_team, c.claimed_by_pubkey, c.claimed_at
|
|
FROM places p
|
|
LEFT JOIN claims c ON c.place_id = p.id
|
|
WHERE p.id = ?
|
|
`);
|
|
const getLinksForPlace = db.prepare(`
|
|
SELECT * FROM links WHERE from_place_id = ? OR to_place_id = ?
|
|
`);
|
|
|
|
app.get('/api/places', async () => {
|
|
return listPlaces.all();
|
|
});
|
|
|
|
app.get('/api/places/:id', async (req, reply) => {
|
|
const id = Number((req.params as { id: string }).id);
|
|
const place = getPlace.get(id);
|
|
if (!place) return reply.code(404).send({ error: 'place not found' });
|
|
const links = getLinksForPlace.all(id, id);
|
|
return { ...place, links };
|
|
});
|
|
}
|