From e19754f588aff4b603aff6aa58a0b79c91c17c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 30 Nov 2023 19:45:07 +0000 Subject: [PATCH] feat: team.getBopsSubmissionURL() function --- src/requests/team.ts | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/requests/team.ts b/src/requests/team.ts index 27ecfe99..4dd07d86 100644 --- a/src/requests/team.ts +++ b/src/requests/team.ts @@ -15,6 +15,8 @@ interface RemoveMember { teamId: number; } +type PlanXEnv = "pizza" | "staging" | "production"; + export class TeamClient { protected client: GraphQLClient; @@ -62,6 +64,13 @@ export class TeamClient { async getBySlug(slug: string): Promise { return getBySlug(this.client, slug); } + + async getBopsSubmissionURL( + slug: string, + env: PlanXEnv, + ): Promise { + return getBopsSubmissionURL(this.client, slug, env); + } } const defaultNotifyPersonalisation = { @@ -248,3 +257,45 @@ async function getBySlug(client: GraphQLClient, slug: string) { ); return response.teams[0]; } + +interface GetBopsSubmissionURL { + teams: { + integrations: { + bopsSubmissionURL: string | null; + } | null; + }[]; +} + +async function getBopsSubmissionURL( + client: GraphQLClient, + slug: string, + env: PlanXEnv, +) { + const stagingQuery = gql` + query GetStagingBopsSubmissionURL($slug: String!) { + teams(where: { slug: { _eq: $slug } }) { + integrations { + bopsSubmissionURL: staging_bops_submission_url + } + } + } + `; + + const productionQuery = gql` + query GetProductionBopsSubmissionURL($slug: String!) { + teams(where: { slug: { _eq: $slug } }) { + integrations { + bopsSubmissionURL: production_bops_submission_url + } + } + } + `; + + const query = env === "production" ? productionQuery : stagingQuery; + + const { + teams: [team], + } = await client.request(query, { slug }); + + return team?.integrations?.bopsSubmissionURL ?? null; +}