NGU-Web/server/src/routes/directory.js
Zaldimmar d1a6332a45 More audit cleanup: shared route cache helper, url columns, tab keys
- One CACHE and json() in shape.js for the seven public route files
- A url column type: link fields (13 of them) refuse javascript:, data:
  and any other scheme on save, not only when drawn
- The chapter map's logo uses the shared Logo component
- Schedule tabs take Home and End as well as the arrows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 02:02:24 -05:00

86 lines
3 KiB
JavaScript

/* ═══════════════════════════════════════════════════════════════
DIRECTORY ROUTE: read-only, mounted under /api
GET /directory every public record that has a page
One flat list per kind, each row just enough to name a record
and build its URL: id and name, plus the organization's kind,
which decides whether its page is /regions, /chapters or
/partners. The QR code page reads it to offer "any page on the
site" without five list requests carrying descriptions, links
and blocks it would throw away.
Each list applies the same visibility rule as that record's own
page, so nothing here leads to a 404:
events published
organizations published
teams published, and so is the organization
awards published
people published
blog_posts published
and each leaves out unlisted records (is_listed = 0): the QR page
is public, and listing them here would undo the point of them.
The site already serves each of these at its own URL; this only
lists them in one place.
═══════════════════════════════════════════════════════════════ */
import { Hono } from "hono";
import { CACHE } from "../shape.js";
const directory = new Hono();
directory.get("/directory", (c) => {
const db = c.get("db");
const all = (sql) => db.prepare(sql).all();
return c.json(
{
directory: {
events: all(
`SELECT id, title AS name, starts_on
FROM events
WHERE is_published = 1 AND is_listed = 1
ORDER BY starts_on IS NULL, starts_on DESC, title`,
),
organizations: all(
`SELECT id, name, kind
FROM organizations
WHERE is_published = 1 AND is_listed = 1
ORDER BY kind, name`,
),
teams: all(
`SELECT t.id, t.name, o.name AS org_name
FROM teams t
JOIN organizations o ON o.id = t.org_id AND o.is_published = 1
WHERE t.is_published = 1 AND t.is_listed = 1
ORDER BY o.name, t.sort_order, t.name`,
),
awards: all(
`SELECT id, name
FROM awards
WHERE is_published = 1 AND is_listed = 1
ORDER BY name`,
),
people: all(
`SELECT id, display_name AS name
FROM people
WHERE is_published = 1 AND is_listed = 1
ORDER BY COALESCE(sort_name, display_name)`,
),
blog_posts: all(
`SELECT id, title AS name
FROM blog_posts
WHERE is_published = 1 AND is_listed = 1
ORDER BY published_on IS NULL, published_on DESC, title`,
),
},
},
200,
{ "Cache-Control": CACHE },
);
});
export default directory;