/* ═══════════════════════════════════════════════════════════════ ADMIN ENTITY DESCRIPTORS One object per editable entity, one file each in admin-schema/ (the shared column helpers and child collections are in admin-schema/columns.js); this file lists them. One object per editable entity. Everything the CRUD handlers do (validation, SQL, nesting) is read from here, so adding a table later is a descriptor rather than another set of hand-written statements to keep in step with the schema. Anatomy of a descriptor: columns writable columns of the parent row extensions 1:1 side tables, optionally gated on a column value (organizations.kind decides whether a regions or groups row should exist) children ordered collections, replaced wholesale on save; `readRole` on one hides it from lesser roles, as on an extension (an organization's contacts) singleton the one id this entity ever has; the engine refuses create and delete (see front_page) undeletable ids the engine refuses to delete (the pages the site draws in code) check (db, id) => void, run after a save has written everything, inside its transaction: throw an HttpError to refuse it (site settings' colors) Replacing children wholesale is only safe because nothing has a foreign key INTO these tables. That is the dividing line, and it is why teams and awards are entities of their own rather than repeaters on the organization form: affiliations.team_id and person_awards.award_id point at them, so a delete-and- reinsert save would abort the moment either had a single dependent row. Parent ids are immutable. Polymorphic children reference their owner by free-text owner_id, so renaming a slug in place would silently orphan every link and content block attached to it. affiliations is edited from both ends: a person's roles, and a team's members. Each side deletes and reinserts only its own slice (WHERE person_id = ?, WHERE team_id = ?) and declares every column of the row, so a save from one side round-trips what the other side owns rather than blanking it. ═══════════════════════════════════════════════════════════════ */ import { organizations } from "./admin-schema/organizations.js"; import { events } from "./admin-schema/events.js"; import { people } from "./admin-schema/people.js"; import { teams } from "./admin-schema/teams.js"; import { awards } from "./admin-schema/awards.js"; import { timeline } from "./admin-schema/timeline.js"; import { frontPage } from "./admin-schema/frontPage.js"; import { blogPosts } from "./admin-schema/blog.js"; import { siteSettings } from "./admin-schema/siteSettings.js"; import { siteNav } from "./admin-schema/siteNav.js"; import { newsletters } from "./admin-schema/newsletters.js"; import { personTagTypes } from "./admin-schema/personTags.js"; import { tags } from "./admin-schema/tags.js"; import { contactTypes } from "./admin-schema/contactTypes.js"; import { redirects } from "./admin-schema/redirects.js"; import { pages } from "./admin-schema/sitePages.js"; export const ENTITIES = { organizations, events, people, person_tag_types: personTagTypes, tags, contact_types: contactTypes, redirects, teams, awards, timeline, front_page: frontPage, blog_posts: blogPosts, pages, navigation: siteNav, site_settings: siteSettings, newsletters, }; /* ── Options for the form's select inputs ────────────────────── */ export const OPTION_QUERIES = { // Ministries have no public page (063_ministries.sql), so nothing // that links to its organization can pick one; a group picks its // ministry from `ministries`. organizations: "SELECT id, name AS label, kind FROM organizations WHERE kind <> 'ministry' ORDER BY kind, name", regions: "SELECT id, name AS label FROM organizations WHERE kind = 'region' ORDER BY name", ministries: "SELECT id, name AS label FROM organizations WHERE kind = 'ministry' ORDER BY name", // What an organization cards section can hand-pick (067). card_orgs: "SELECT id, name || ' (' || kind || ')' AS label FROM organizations WHERE kind IN ('partner', 'ministry') ORDER BY kind, name", event_scopes: "SELECT id, name AS label FROM event_scopes ORDER BY sort_order", events: "SELECT id, title AS label FROM events ORDER BY starts_on DESC, title", people: "SELECT id, display_name AS label FROM people ORDER BY sort_name, display_name", person_tag_types: "SELECT id, name AS label FROM person_tag_types ORDER BY sort_order, name", tags: "SELECT id, name AS label FROM tags ORDER BY sort_order, name", contact_types: "SELECT id, name AS label FROM contact_types ORDER BY sort_order, name", // Link fields with `redirects: true` pick from these (068). redirects: "SELECT id, id || ' (' || target_url || ')' AS label FROM redirects ORDER BY id", blog_posts: "SELECT id, title AS label FROM blog_posts ORDER BY published_on DESC, title", // Navigation's Under page: a page by its address (080). site_pages: "SELECT path AS id, title || ' (' || path || ')' AS label FROM site_pages ORDER BY sort_order, title", // org_id rides along so the affiliation row can filter the list // down to teams of the organization it already names. teams: "SELECT id, name AS label, org_id FROM teams ORDER BY org_id, sort_order, name", // One flat list the ref picker filters by ref_kind, rather than five // dropdowns of which four are always wrong. The timeline and the // featured cards both pick from it. `kind` is the discriminator // the client's filterBy matches on; org_kind disambiguates the label, // since a region and a group can share a name. record_refs: ` SELECT 'event' AS kind, id, title AS label FROM events UNION ALL SELECT 'organization', id, name || ' (' || kind || ')' FROM organizations WHERE kind <> 'ministry' UNION ALL SELECT 'award', id, name FROM awards UNION ALL SELECT 'person', id, display_name FROM people UNION ALL SELECT 'team', id, name FROM teams ORDER BY kind, label`, // The awarding organization is folded into the label instead, // because a person can receive an award from any organization: // there is nothing to filter on, only something to disambiguate // when two orgs name an award the same thing. awards: ` SELECT a.id, CASE WHEN o.name IS NULL THEN a.name ELSE a.name || ' (' || o.name || ')' END AS label, a.org_id FROM awards a LEFT JOIN organizations o ON o.id = a.org_id ORDER BY a.sort_order, a.name`, };