diff --git a/api.planx.uk/modules/analytics/metabase/collection/collection.test.ts b/api.planx.uk/modules/analytics/metabase/collection/collection.test.ts index f540c09a33..53bf198827 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/collection.test.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/collection.test.ts @@ -1,13 +1,10 @@ -import { - checkCollections, - getCollection, - createCollection, -} from "./service.js"; +import { checkCollections, getCollection } from "./service.js"; import nock from "nock"; import { MetabaseError } from "../shared/client.js"; import { $api } from "../../../../client/index.js"; import { updateMetabaseId } from "./updateMetabaseId.js"; import { getTeamAndMetabaseId } from "./getTeamAndMetabaseId.js"; +import { createCollection } from "./createCollection.js"; describe("checkCollections", () => { beforeEach(() => { diff --git a/api.planx.uk/modules/analytics/metabase/collection/createCollection.ts b/api.planx.uk/modules/analytics/metabase/collection/createCollection.ts new file mode 100644 index 0000000000..e2f0df0539 --- /dev/null +++ b/api.planx.uk/modules/analytics/metabase/collection/createCollection.ts @@ -0,0 +1,20 @@ +import { createMetabaseClient } from "../shared/client.js"; +import type { NewCollectionParams } from "./types.js"; + +const client = createMetabaseClient(); + +export async function createCollection( + params: NewCollectionParams, +): Promise { + const transformedParams = { + name: params.name, + parent_id: params.parentId, + }; + + const response = await client.post(`/api/collection/`, transformedParams); + + console.log( + `New collection: ${response.data.name}, new collection ID: ${response.data.id}`, + ); + return response.data.id; +} diff --git a/api.planx.uk/modules/analytics/metabase/collection/service.ts b/api.planx.uk/modules/analytics/metabase/collection/service.ts index d4e151634d..a0c3fef8af 100644 --- a/api.planx.uk/modules/analytics/metabase/collection/service.ts +++ b/api.planx.uk/modules/analytics/metabase/collection/service.ts @@ -1,26 +1,11 @@ -import { MetabaseError, createMetabaseClient } from "../shared/client.js"; +import { createMetabaseClient } from "../shared/client.js"; import { updateMetabaseId } from "./updateMetabaseId.js"; import type { NewCollectionParams } from "./types.js"; import { getTeamAndMetabaseId } from "./getTeamAndMetabaseId.js"; +import { createCollection } from "./createCollection.js"; const client = createMetabaseClient(); -export async function createCollection( - params: NewCollectionParams, -): Promise { - const transformedParams = { - name: params.name, - parent_id: params.parentId, - }; - - const response = await client.post(`/api/collection/`, transformedParams); - - console.log( - `New collection: ${response.data.name}, new collection ID: ${response.data.id}`, - ); - return response.data.id; -} - /** * First uses name to get teams.id and .metabase_id, if present. * If metabase_id is null, return an object that includes its id. If not, create the collection.