Skip to content

Commit

Permalink
feat: team.getBopsSubmissionURL() function (#212)
Browse files Browse the repository at this point in the history
## What does this PR do?
- Adds new `team.getBopsSubmissionURL()` function which can be used to
replace env vars in `planx-new`
- Relies on theopensystemslab/planx-new#2499
  • Loading branch information
DafyddLlyr authored Dec 4, 2023
1 parent e3e09c0 commit 6a821ec
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/requests/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface RemoveMember {
teamId: number;
}

type PlanXEnv = "pizza" | "staging" | "production";

export class TeamClient {
protected client: GraphQLClient;

Expand Down Expand Up @@ -62,6 +64,13 @@ export class TeamClient {
async getBySlug(slug: string): Promise<Team> {
return getBySlug(this.client, slug);
}

async getBopsSubmissionURL(
slug: string,
env: PlanXEnv,
): Promise<string | null> {
return getBopsSubmissionURL(this.client, slug, env);
}
}

const defaultNotifyPersonalisation = {
Expand Down Expand Up @@ -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<GetBopsSubmissionURL>(query, { slug });

return team?.integrations?.bopsSubmissionURL ?? null;
}

0 comments on commit 6a821ec

Please sign in to comment.