diff --git a/api.planx.uk/modules/analytics/metabase/collection/createCollection.ts b/api.planx.uk/modules/analytics/metabase/collection/createCollection.ts index 43f8604413..56fe09a0de 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/createCollection.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/createCollection.ts @@ -1,11 +1,9 @@ -import { createMetabaseClient } from "../shared/client.js"; -import type { MetabaseCollectionParams, NewCollectionParams } from "./types.js"; - -const client = createMetabaseClient(); +import type { MetabaseCollectionParams } from "./types.js"; +import { $metabase } from "../shared/client.js"; export async function createCollection( params: MetabaseCollectionParams, ): Promise { - const response = await client.post(`/api/collection/`, params); + const response = await $metabase.post(`/api/collection/`, params); return response.data.id; } diff --git a/api.planx.uk/modules/analytics/metabase/collection/getCollection.ts b/api.planx.uk/modules/analytics/metabase/collection/getCollection.ts index f1566f37f1..587fb8bf0f 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/getCollection.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/getCollection.ts @@ -1,4 +1,3 @@ -import { createMetabaseClient } from "../shared/client.js"; import type { GetCollectionResponse } from "./types.js"; import { $metabase } from "../shared/client.js"; diff --git a/api.planx.uk/modules/analytics/metabase/collection/service.ts b/api.planx.uk/modules/analytics/metabase/collection/service.ts index 80cde51b03..a52044c858 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/service.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/service.ts @@ -1,5 +1,5 @@ import { updateMetabaseId } from "./updateMetabaseId.js"; -import type { NewCollectionParams, MetabaseCollectionParams } from "./types.js"; +import type { NewCollectionParams } from "./types.js"; import { getTeamIdAndMetabaseId } from "./getTeamIdAndMetabaseId.js"; import { createCollection } from "./createCollection.js"; @@ -10,27 +10,23 @@ import { createCollection } from "./createCollection.js"; * @params `slug` is required, but `description` and `parent_id` are optional. * @returns `response.data`, so use dot notation to access `id` or `parent_id`. */ -export async function createTeamCollection( - params: NewCollectionParams, -): Promise { +export async function createTeamCollection({ + slug, + parentId, + description, +}: NewCollectionParams): Promise { try { - const { - metabaseId, - name, - id: teamId, - } = await getTeamIdAndMetabaseId(params.slug); + const { metabaseId, name, id: teamId } = await getTeamIdAndMetabaseId(slug); if (metabaseId) { return metabaseId; } - const { slug, ...rest } = params; - const metabaseParams = { + const newMetabaseId = await createCollection({ name, - ...rest, - } as const; - - const newMetabaseId = await createCollection(metabaseParams); + parentId, + description, + }); await updateMetabaseId(teamId, newMetabaseId); return newMetabaseId;