Skip to content

Commit

Permalink
chore: tidy imports and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-hh-aa committed Dec 23, 2024
1 parent c9e9740 commit 6d8cd9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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<number> {
const response = await client.post(`/api/collection/`, params);
const response = await $metabase.post(`/api/collection/`, params);
return response.data.id;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createMetabaseClient } from "../shared/client.js";
import type { GetCollectionResponse } from "./types.js";
import { $metabase } from "../shared/client.js";

Expand Down
26 changes: 11 additions & 15 deletions api.planx.uk/modules/analytics/metabase/collection/service.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<number> {
export async function createTeamCollection({
slug,
parentId,
description,
}: NewCollectionParams): Promise<number> {
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;
Expand Down

0 comments on commit 6d8cd9c

Please sign in to comment.