diff --git a/apps/api/src/lib/persons.ts b/apps/api/src/lib/persons.ts index 0c2091e9a..3470615c7 100644 --- a/apps/api/src/lib/persons.ts +++ b/apps/api/src/lib/persons.ts @@ -6,6 +6,8 @@ import { alias, and, eq, inArray, sql } from "@/services/db/sql"; export interface PersonPosition { role: (typeof schema.personRoleTypesEnum)[number]; name: string; + /** Slug of the related organisational unit, for constructing urls to its details page. */ + slug: string; type: (typeof schema.organisationalUnitTypesEnum)[number]; /** Optional free-text note describing the person↔org relation. */ description: string | null; @@ -62,6 +64,7 @@ export async function getPersonPositions( personId: personEntityVersions.id, role: schema.personRoleTypes.type, name: schema.organisationalUnits.name, + slug: schema.entities.slug, type: schema.organisationalUnitTypes.type, description: schema.personsToOrganisationalUnits.description, }) @@ -85,6 +88,10 @@ export async function getPersonPositions( schema.organisationalUnits, eq(schema.organisationalUnits.id, organisationalUnitDocumentLifecycle.publishedId), ) + .innerJoin( + schema.entities, + eq(schema.entities.id, organisationalUnitDocumentLifecycle.documentId), + ) .innerJoin( schema.organisationalUnitTypes, eq(schema.organisationalUnits.typeId, schema.organisationalUnitTypes.id), @@ -103,6 +110,7 @@ export async function getPersonPositions( items.push({ role: row.role, name: row.name, + slug: row.slug, type: row.type, description: row.description, }); diff --git a/apps/api/src/routes/governance-bodies/schemas.ts b/apps/api/src/routes/governance-bodies/schemas.ts index 62d39a1a7..70eb098f1 100644 --- a/apps/api/src/routes/governance-bodies/schemas.ts +++ b/apps/api/src/routes/governance-bodies/schemas.ts @@ -17,6 +17,7 @@ const GovernanceBodyPersonSchema = v.object({ v.object({ role: v.picklist(schema.personRoleTypesEnum), name: v.string(), + slug: v.string(), type: v.picklist(schema.organisationalUnitTypesEnum), description: v.nullable(v.string()), }), diff --git a/apps/api/src/routes/impact-case-studies/schemas.ts b/apps/api/src/routes/impact-case-studies/schemas.ts index 8bd4e323f..aaba23347 100644 --- a/apps/api/src/routes/impact-case-studies/schemas.ts +++ b/apps/api/src/routes/impact-case-studies/schemas.ts @@ -43,6 +43,7 @@ export const ImpactCaseStudySchema = v.pipe( v.object({ role: v.picklist(schema.personRoleTypesEnum), name: v.string(), + slug: v.string(), type: v.picklist(schema.organisationalUnitTypesEnum), description: v.nullable(v.string()), }), diff --git a/apps/api/src/routes/members-partners/schemas.ts b/apps/api/src/routes/members-partners/schemas.ts index 2e7d52ef3..00f201d2f 100644 --- a/apps/api/src/routes/members-partners/schemas.ts +++ b/apps/api/src/routes/members-partners/schemas.ts @@ -52,6 +52,7 @@ export const ContributorSchema = v.pipe( v.object({ role: v.picklist(schema.personRoleTypesEnum), name: v.string(), + slug: v.string(), type: v.picklist(schema.organisationalUnitTypesEnum), description: v.nullable(v.string()), }), diff --git a/apps/api/src/routes/persons/schemas.ts b/apps/api/src/routes/persons/schemas.ts index d29e1bfe1..c7f92041e 100644 --- a/apps/api/src/routes/persons/schemas.ts +++ b/apps/api/src/routes/persons/schemas.ts @@ -12,6 +12,7 @@ export const PersonBaseSchema = v.pipe( v.object({ role: v.picklist(schema.personRoleTypesEnum), name: v.string(), + slug: v.string(), type: v.picklist(schema.organisationalUnitTypesEnum), description: v.nullable(v.string()), }), @@ -43,6 +44,7 @@ export const PersonSchema = v.pipe( v.object({ role: v.picklist(schema.personRoleTypesEnum), name: v.string(), + slug: v.string(), type: v.picklist(schema.organisationalUnitTypesEnum), description: v.nullable(v.string()), }), diff --git a/apps/api/src/routes/spotlight-articles/schemas.ts b/apps/api/src/routes/spotlight-articles/schemas.ts index f4369a589..1d5866b86 100644 --- a/apps/api/src/routes/spotlight-articles/schemas.ts +++ b/apps/api/src/routes/spotlight-articles/schemas.ts @@ -47,6 +47,7 @@ export const SpotlightArticleSchema = v.pipe( v.object({ role: v.picklist(schema.personRoleTypesEnum), name: v.string(), + slug: v.string(), type: v.picklist(schema.organisationalUnitTypesEnum), description: v.nullable(v.string()), }), diff --git a/apps/api/src/routes/working-groups/schemas.ts b/apps/api/src/routes/working-groups/schemas.ts index dad7be662..6f9da7ae9 100644 --- a/apps/api/src/routes/working-groups/schemas.ts +++ b/apps/api/src/routes/working-groups/schemas.ts @@ -87,6 +87,7 @@ export const WorkingGroupSchema = v.pipe( v.object({ role: v.picklist(schema.personRoleTypesEnum), name: v.string(), + slug: v.string(), type: v.picklist(schema.organisationalUnitTypesEnum), description: v.nullable(v.string()), }), diff --git a/apps/api/test/__snapshots__/openapi.test.ts.snap b/apps/api/test/__snapshots__/openapi.test.ts.snap index d283d33d3..857c8af13 100644 --- a/apps/api/test/__snapshots__/openapi.test.ts.snap +++ b/apps/api/test/__snapshots__/openapi.test.ts.snap @@ -416,6 +416,9 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh ], "type": "string", }, + "slug": { + "type": "string", + }, "type": { "enum": [ "governance_body", @@ -432,6 +435,7 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh "required": [ "role", "name", + "slug", "type", "description", ], @@ -5859,6 +5863,9 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh ], "type": "string", }, + "slug": { + "type": "string", + }, "type": { "enum": [ "governance_body", @@ -5875,6 +5882,7 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh "required": [ "role", "name", + "slug", "type", "description", ], @@ -6405,6 +6413,9 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh ], "type": "string", }, + "slug": { + "type": "string", + }, "type": { "enum": [ "governance_body", @@ -6421,6 +6432,7 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh "required": [ "role", "name", + "slug", "type", "description", ], @@ -7050,6 +7062,9 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh ], "type": "string", }, + "slug": { + "type": "string", + }, "type": { "enum": [ "governance_body", @@ -7066,6 +7081,7 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh "required": [ "role", "name", + "slug", "type", "description", ], @@ -11584,6 +11600,9 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh ], "type": "string", }, + "slug": { + "type": "string", + }, "type": { "enum": [ "governance_body", @@ -11600,6 +11619,7 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh "required": [ "role", "name", + "slug", "type", "description", ], @@ -11768,6 +11788,9 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh ], "type": "string", }, + "slug": { + "type": "string", + }, "type": { "enum": [ "governance_body", @@ -11784,6 +11807,7 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh "required": [ "role", "name", + "slug", "type", "description", ], @@ -13512,6 +13536,9 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh ], "type": "string", }, + "slug": { + "type": "string", + }, "type": { "enum": [ "governance_body", @@ -13528,6 +13555,7 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh "required": [ "role", "name", + "slug", "type", "description", ], @@ -14057,6 +14085,9 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh ], "type": "string", }, + "slug": { + "type": "string", + }, "type": { "enum": [ "governance_body", @@ -14073,6 +14104,7 @@ exports[`openapi > GET /docs/openapi.json > should match the api contract snapsh "required": [ "role", "name", + "slug", "type", "description", ], diff --git a/apps/api/test/api-persons.test.ts b/apps/api/test/api-persons.test.ts index c28ea7fa0..0f43928c1 100644 --- a/apps/api/test/api-persons.test.ts +++ b/apps/api/test/api-persons.test.ts @@ -157,6 +157,7 @@ describe("persons", () => { expect.objectContaining({ role: "is_affiliated_with", name: item.affiliation.organisationalUnit.name, + slug: item.affiliation.entity.slug, description: item.affiliation.description, }), ]); @@ -199,6 +200,7 @@ describe("persons", () => { expect.objectContaining({ role: "is_affiliated_with", name: item.affiliation.organisationalUnit.name, + slug: item.affiliation.entity.slug, description: item.affiliation.description, }), ]); @@ -298,6 +300,7 @@ describe("persons", () => { expect.objectContaining({ role: "is_affiliated_with", name: item.affiliation.organisationalUnit.name, + slug: item.affiliation.entity.slug, description: item.affiliation.description, }), ]);