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 c384fee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand Down
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> {

Check warning on line 8 in api.planx.uk/modules/analytics/metabase/collection/createCollection.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Unexpected any. Specify a different type
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 c384fee

Please sign in to comment.