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
| Mount | Model | Name field | Extra fields |
|---|---|---|---|
/location | Location | name | image, description, parentId, isFeatured, typeId |
/location-type | LocationType | value | — |
/category | Category | title | image, description |
/keyword | Keyword | keyword | — |
/food-type | FoodType | value | — |
/food-format | FoodFormat | value | — |
/dietary-restriction | DietaryRestriction | value | — |
/transport-type | TransportType | value | — |
/suitability-concern | SuitabilityConcern | value | — |
/activity-restriction | ActivityRestriction | value | — |
/mandatory-item | MandatoryItem | value | — |
Every mount exposes the same five operations:
| Method | Path | Auth | Purpose |
|---|---|---|---|
| GET | /<type> | Public | Paginated list |
| GET | /<type>/:id | Public | Single row |
| POST | /<type> | Admin | Create |
| PATCH | /<type>/:id | Admin | Update |
| DELETE | /<type>/:id | Admin | Delete |
Listing
All catalog lists support:
| Param | Behaviour |
|---|---|
page, limit | Pagination via getPaginationParams |
search | Case-insensitive contains on the name field |
includeInactive | Any value includes inactive rows; omitted means isActive = true only |
parentId | Locations only: direct children of a location |
type | Locations only: matches LocationType.slug |
featured | Locations 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. slugis generated from the submitted slug or the name. A duplicate returns409.isActivedefaults totrueon create.typeIdmust reference an existingLocationType, otherwise400.parentIdmust 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
locationAncestorsarray 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.
| Method | Endpoint | Auth | Destination |
|---|---|---|---|
| POST | /upload | Any auth cookie | Cloudflare Images |
| POST | /upload/multiple | Any auth cookie | Cloudflare Images |
| POST | /upload/local | Public | public/uploads |
| POST | /upload/local/multiple | Public | public/uploads |
| GET | /uploads/:file | Public | Static 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:
{
"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.
{
"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
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /media/:id | Stream a Cloudflare image inline |
| GET | /media/:id/details | Return { id, filename } |
| GET | /media/:id/:filename | Stream 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.
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| GET | /media-library | Admin | Paginated media rows |
| POST | /media-library | Admin | Register a file |
| DELETE | /media-library/:id | Admin | Delete a row |
| GET | /media-library/entity-images/:category | Admin | Images attached to entities |
| DELETE | /media-library/entity-image | Admin | Remove 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:
| Category | Source | Returned id shape |
|---|---|---|
activities | Activity.images[] | activity-<id>-<index> |
users | User.image | user-<id> |
suppliers | Supplier.companyLogo | supplier-<id> |
supplier-docs | Supplier.license | supplier-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.