diff --git a/api.planx.uk/modules/analytics/docs.yaml b/api.planx.uk/modules/analytics/docs.yaml index 1ee84da3a0..3d26438b36 100644 --- a/api.planx.uk/modules/analytics/docs.yaml +++ b/api.planx.uk/modules/analytics/docs.yaml @@ -15,13 +15,8 @@ components: schemas: NewCollection: type: object - required: - - slug - properties: - slug: - type: string - description: Name of the collection - description: + properties: + description: type: string description: Optional description for the collection parentId: @@ -49,12 +44,19 @@ paths: "204": $ref: "#/components/responses/AnalyticsResponse" - /metabase/collection: + /metabase/collection/{slug}: post: summary: Create new Metabase collection description: Creates a new collection in Metabase if it doesn't already exist tags: - metabase + parameters: + - name: slug + in: path + required: true + schema: + type: string + description: PlanX team slug requestBody: required: true content: @@ -70,7 +72,8 @@ paths: type: object properties: data: - $ref: "#/components/schemas/NewCollection" + type: integer + description: Metabase collection ID "400": description: Bad request or collection creation failed content: @@ -80,4 +83,4 @@ paths: properties: error: type: string - description: Error message + description: Error message \ No newline at end of file diff --git a/api.planx.uk/modules/analytics/metabase/collection/controller.ts b/api.planx.uk/modules/analytics/metabase/collection/controller.ts index d66bd2ef70..b88c3de553 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/controller.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/controller.ts @@ -4,7 +4,10 @@ import type { NewCollectionRequestHandler } from "./types.js"; export const metabaseCollectionsController: NewCollectionRequestHandler = async (_req, res) => { try { - const params = res.locals.parsedReq.body; + const params = { + ...res.locals.parsedReq.params, + ...res.locals.parsedReq.body, + }; const collection = await createTeamCollection(params); res.status(201).json({ data: collection }); } catch (error) { diff --git a/api.planx.uk/modules/analytics/metabase/collection/types.ts b/api.planx.uk/modules/analytics/metabase/collection/types.ts index 651c96b468..4f97b247f4 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/types.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/types.ts @@ -23,8 +23,10 @@ export type MetabaseCollectionParams = Omit & { // const COUNCILS_COLLECTION_ID = 58; export const createTeamCollectionSchema = z.object({ - body: z.object({ + params: z.object({ slug: z.string(), + }), + body: z.object({ description: z.string().optional(), parentId: z.number().optional(), //.default(COUNCILS_COLLECTION_ID), }), diff --git a/api.planx.uk/modules/analytics/routes.ts b/api.planx.uk/modules/analytics/routes.ts index e4c9dbdb1f..3de94d5c39 100644 --- a/api.planx.uk/modules/analytics/routes.ts +++ b/api.planx.uk/modules/analytics/routes.ts @@ -21,7 +21,7 @@ router.post( logUserResumeController, ); router.post( - "/metabase/collection", + "/metabase/collection/:slug", validate(createTeamCollectionSchema), metabaseCollectionsController, );