Skip to content

Commit

Permalink
feat: Add team.updateTheme()
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jan 12, 2024
1 parent 4589660 commit dd78138
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
46 changes: 45 additions & 1 deletion src/requests/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { GraphQLClient } from "graphql-request";
import { gql } from "graphql-request";

import { TeamRole } from "../types/roles";
import { Team } from "../types/team";
import { Team, TeamTheme } from "../types/team";

interface UpsertMember {
userId: number;
Expand Down Expand Up @@ -71,6 +71,13 @@ export class TeamClient {
): Promise<string | null> {
return getBopsSubmissionURL(this.client, slug, env);
}

async updateTheme(
teamId: number,
theme: Partial<TeamTheme>,
): Promise<boolean> {
return updateTheme(this.client, teamId, theme);
}
}

const defaultNotifyPersonalisation = {
Expand Down Expand Up @@ -305,3 +312,40 @@ async function getBopsSubmissionURL(

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

async function updateTheme(
client: GraphQLClient,
teamId: number,
theme: Partial<TeamTheme>,
) {
const response: { update_team_themes: [{ team_id: number; id: number }] } =
await client.request(
gql`
mutation UpdateTeamTheme(
$team_id: Int
$theme: team_themes_set_input!
) {
update_team_themes(
where: { team_id: { _eq: $team_id } }
_set: $theme
) {
returning {
team_id
id
}
}
}
`,
{
team_id: teamId,
theme: {
primary_colour: theme.primaryColour,
action_colour: theme.actionColour,
link_colour: theme.linkColour,
logo: theme.logo,
favicon: theme.favicon,
},
},
);
return Boolean(response.update_team_themes[0]);
}
2 changes: 1 addition & 1 deletion src/types/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Team {
name: string;
slug: string;
settings?: TeamSettings;
theme?: TeamTheme;
theme: TeamTheme;
notifyPersonalisation?: NotifyPersonalisation;
boundaryBBox?: GeoJsonObject;
}
Expand Down

0 comments on commit dd78138

Please sign in to comment.