Skip to content

Commit

Permalink
feat: transform request in newCollectionSchema
Browse files Browse the repository at this point in the history
from camelCase to snake_case
  • Loading branch information
zz-hh-aa committed Dec 3, 2024
1 parent ae037aa commit 9d6878c
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions api.planx.uk/modules/analytics/metabase/collection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,36 @@ type ApiResponse<T> = {
error?: string;
};

/** Interface for incoming request, in camelCase */
export interface NewCollectionParams {
name: string;
description?: string;
/** Optional; if the collection is a child of a parent, specify parent ID here
* For council teams, parent collection should be 58
*/
/** Optional; if the collection is a child of a parent, specify parent ID here */
parentId?: number;
}

/** Interface for request after transforming to snake case (Metabase takes snake while PlanX API takes camel) */
export interface MetabaseCollectionParams {
name: string;
description?: string;
parent_id?: number;
}

/** Metbase collection ID for the the "Council" collection **/
const COUNCIL_COLLECTION_ID = 58;
const COUNCILS_COLLECTION_ID = 58;

export const newCollectionSchema = z.object({
body: z.object({
name: z.string(),
description: z.string().optional(),
parent_id: z.number().default(COUNCIL_COLLECTION_ID),
}),
body: z
.object({
name: z.string(),
description: z.string().optional(),
parentId: z.number().default(COUNCILS_COLLECTION_ID),
})
.transform((data) => ({
name: data.name,
description: data.description,
parent_id: data.parentId,
})),
});

export type NewCollectionRequestHandler = ValidatedRequestHandler<
Expand Down

0 comments on commit 9d6878c

Please sign in to comment.