Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: team.getBopsSubmissionURL() function #212

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we find that passing the env in becomes a repeated pattern (outside of integrations) maybe this is just something we can do once when instantiating the client.

): 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;
}
Loading