diff --git a/api.planx.uk/modules/analytics/metabase/collection/controller.ts b/api.planx.uk/modules/analytics/metabase/collection/controller.ts index e69de29bb2..946a35f0e8 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/controller.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/controller.ts @@ -0,0 +1,18 @@ +import { createCollectionIfDoesNotExist } from "./service.js"; +import type { NewCollectionRequestHandler } from "./types.js"; + +export const MetabaseCollectionsController: NewCollectionRequestHandler = + async (_req, res) => { + try { + const params = res.locals.parsedReq.body; + const collection = await createCollectionIfDoesNotExist(params); + res.status(201).json({ data: collection }); + } catch (error) { + res.status(400).json({ + error: + error instanceof Error + ? error.message + : "An unexpected error occurred", + }); + } + }; diff --git a/api.planx.uk/modules/analytics/metabase/collection/types.ts b/api.planx.uk/modules/analytics/metabase/collection/types.ts index 966449cc31..4b4e53169c 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/types.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/types.ts @@ -40,7 +40,7 @@ export const createCollectionIfDoesNotExistSchema = z.object({ export type NewCollectionRequestHandler = ValidatedRequestHandler< typeof createCollectionIfDoesNotExistSchema, - ApiResponse + ApiResponse >; export interface NewCollectionResponse {