Skip to content

Catalog & Media ​

Activities point at shared catalog rows instead of storing location and amenity text inline. Eleven catalog types share one generic CRUD controller, so their behaviour is identical. Media is split between Cloudflare Images uploads, local uploads, a proxy, and an admin media library.

Catalog routes ​

MountModelName fieldExtra fields
/locationLocationnameimage, description, parentId, isFeatured, typeId
/location-typeLocationTypevalue—
/categoryCategorytitleimage, description
/keywordKeywordkeyword—
/food-typeFoodTypevalue—
/food-formatFoodFormatvalue—
/dietary-restrictionDietaryRestrictionvalue—
/transport-typeTransportTypevalue—
/suitability-concernSuitabilityConcernvalue—
/activity-restrictionActivityRestrictionvalue—
/mandatory-itemMandatoryItemvalue—

Every mount exposes the same five operations:

MethodPathAuthPurpose
GET/<type>PublicPaginated list
GET/<type>/:idPublicSingle row
POST/<type>AdminCreate
PATCH/<type>/:idAdminUpdate
DELETE/<type>/:idAdminDelete

Listing ​

All catalog lists support:

ParamBehaviour
page, limitPagination via getPaginationParams
searchCase-insensitive contains on the name field
includeInactiveAny value includes inactive rows; omitted means isActive = true only
parentIdLocations only: direct children of a location
typeLocations only: matches LocationType.slug
featuredLocations only: true selects featured rows

Rows are ordered by createdAt desc. Location lists include the related type.

Create and update ​

  • The name field is required and trimmed; a missing value returns 400.
  • slug is generated from the submitted slug or the name. A duplicate returns 409.
  • isActive defaults to true on create.
  • typeId must reference an existing LocationType, otherwise 400.
  • parentId must exist and must not create a cycle. The controller walks the parent chain and rejects a row that points at itself or at one of its descendants.
  • Changing a location's parent or slug? No — changing either parent or name/slug triggers a transaction that refreshes the denormalised locationAncestors array for the whole subtree. The transaction timeout is 60 seconds.
  • Delete is a hard delete and returns 204.

Deletion is not guarded

There is no "in use" check before delete. Removing a catalog row that activities reference will fail at the database level if the relation is restrictive, or remove the link if it cascades. Deactivate with isActive: false when you want to retire a value without touching activities.

Media uploads ​

Two storage backends exist, and their auth differs.

MethodEndpointAuthDestination
POST/uploadAny auth cookieCloudflare Images
POST/upload/multipleAny auth cookieCloudflare Images
POST/upload/localPublicpublic/uploads
POST/upload/local/multiplePublicpublic/uploads
GET/uploads/:filePublicStatic file from public/uploads

Field names are file for single uploads and images for multiple uploads. Multer accepts JPEG, PNG, WebP, GIF and AVIF up to 10 MB and keeps the file in memory.

Cloudflare Images ​

POST /upload converts the buffer to WebP at quality 80 with Sharp, requests a Cloudflare direct-upload URL, uploads the file, and returns:

json
{
  "id": "cloudflare-image-id",
  "displayUrl": "https://imagedelivery.net/<hash>/<id>/public",
  "storageUrl": "https://imagedelivery.net/<hash>/<id>"
}

Cloudflare credentials are CF_ACCOUNT_ID, CF_API_TOKEN and CF_ACCOUNT_HASH.

Local uploads ​

The local endpoints exist for flows that run before a login exists, such as supplier registration. saveLocalFile accepts only JPEG, PNG and WebP, rotates by EXIF, converts to WebP at quality 82, sanitises the original filename, and appends a timestamp plus random suffix.

json
{
  "url": "/uploads/company-logo-1730000000000-a1b2c3.webp",
  "filename": "company-logo-1730000000000-a1b2c3.webp",
  "path": "/srv/app/public/uploads/company-logo-1730000000000-a1b2c3.webp"
}

UPLOADS_BASE_URL can rewrite the returned base URL in deployments where the API does not serve its own files. Note that these endpoints have no auth; they are protected only by the multer MIME filter and rate limiting.

Image proxy ​

MethodEndpointPurpose
GET/media/:idStream a Cloudflare image inline
GET/media/:id/detailsReturn { id, filename }
GET/media/:id/:filenameStream with an explicit filename

The proxy fetches the Cloudflare delivery URL, forwards the content type, sets Cache-Control: public, max-age=31536000, and pipes the body. It exists so images can be served from the API origin without exposing delivery URLs in stored markup.

Media library ​

The media library catalogues uploaded files and indexes images that already live on entities.

MethodEndpointAuthPurpose
GET/media-libraryAdminPaginated media rows
POST/media-libraryAdminRegister a file
DELETE/media-library/:idAdminDelete a row
GET/media-library/entity-images/:categoryAdminImages attached to entities
DELETE/media-library/entity-imageAdminRemove an entity image

POST /media-library requires url and filename and accepts mimeType, fileSize, category (UNRELATED or SUPPLIER_DOC, default UNRELATED) and relatedId.

GET /media-library/entity-images/:category supports activities, users, suppliers and supplier-docs, with page, limit and an optional supplierId search. It reads the source entities directly rather than a separate join table:

CategorySourceReturned id shape
activitiesActivity.images[]activity-<id>-<index>
usersUser.imageuser-<id>
suppliersSupplier.companyLogosupplier-<id>
supplier-docsSupplier.licensesupplier-doc-<id>

Removing an entity image is a query-based operation (?url=...&category=...&entityId=...) rather than a media row delete, because the entity columns are the source of truth.

Built with VitePress