Skip to content

Commit

Permalink
chore: move createCollection to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-hh-aa committed Dec 10, 2024
1 parent e234edc commit e00a6c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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<any> {
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;
}
19 changes: 2 additions & 17 deletions api.planx.uk/modules/analytics/metabase/collection/service.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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.
Expand Down

0 comments on commit e00a6c8

Please sign in to comment.