Skip to content

Commit

Permalink
feat: change route to include team slug
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-hh-aa committed Dec 19, 2024
1 parent 445a576 commit f4dea96
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
23 changes: 13 additions & 10 deletions api.planx.uk/modules/analytics/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -80,4 +83,4 @@ paths:
properties:
error:
type: string
description: Error message
description: Error message
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion api.planx.uk/modules/analytics/metabase/collection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export type MetabaseCollectionParams = Omit<NewCollectionParams, "slug"> & {
// 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),
}),
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/analytics/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.post(
logUserResumeController,
);
router.post(
"/metabase/collection",
"/metabase/collection/:slug",
validate(createTeamCollectionSchema),
metabaseCollectionsController,
);
Expand Down

0 comments on commit f4dea96

Please sign in to comment.