diff --git a/api.planx.uk/modules/analytics/metabase/collection/controller.ts b/api.planx.uk/modules/analytics/metabase/collection/controller.ts index c36d2c9365..039261c7b8 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/controller.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/controller.ts @@ -1,35 +1,9 @@ import { z } from "zod"; import type { ValidatedRequestHandler } from "../../../../shared/middleware/validate.js"; import { checkCollections, newCollection } from "./service.js"; -import type { NewCollectionParams } from "./types.js"; +import type { NewCollectionRequest } from "./types.js"; import type { Request, Response } from "express"; -// Error response type -interface ErrorResponse { - error: string; -} - -// Response types -type ApiResponse = { - data?: T; - error?: string; -}; - -// Define validation schemas -export const newCollectionSchema = z.object({ - body: z.object({ - name: z.string(), - description: z.string().optional(), - parentId: z.number().optional(), - }), -}); - -// Define types for validated requests -export type NewCollectionRequest = ValidatedRequestHandler< - typeof newCollectionSchema, - ApiResponse ->; - // Controller functions export const checkCollectionsController = async ( _req: Request, diff --git a/api.planx.uk/modules/analytics/metabase/collection/types.ts b/api.planx.uk/modules/analytics/metabase/collection/types.ts index e1b583e13a..f35d9cb690 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/types.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/types.ts @@ -1,3 +1,26 @@ +import { z } from "zod"; +import type { ValidatedRequestHandler } from "../../../../shared/middleware/validate.js"; + +type ApiResponse = { + data?: T; + error?: string; +}; + +export const checkCollectionsSchema = z.object({ + query: z.object({ + name: z.string().min(1, "Name parameter is required"), + }), +}); + +export type CheckCollectionsRequest = ValidatedRequestHandler< + typeof checkCollectionsSchema, + ApiResponse +>; + +export interface CheckCollectionResponse { + collectionId: number | false; +} + export interface NewCollectionParams { /** The name of the new collection */ name: string; @@ -9,3 +32,23 @@ export interface NewCollectionParams { namespace?: string; authority_level?: null; } + +export const newCollectionSchema = z.object({ + body: z.object({ + name: z.string(), + description: z.string().optional(), + parent_id: z.number().optional(), + namespace: z.string().optional(), + authority_level: z.null().optional(), + }), +}); + +export type NewCollectionRequest = ValidatedRequestHandler< + typeof newCollectionSchema, + ApiResponse +>; + +export interface NewCollectionResponse { + id: number; + name: string; +}