From dd781388a148fba93ee9e886175e5a15df876ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 12 Jan 2024 12:44:27 +0000 Subject: [PATCH] feat: Add team.updateTheme() --- src/requests/team.ts | 46 +++++++++++++++++++++++++++++++++++++++++++- src/types/team.ts | 2 +- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/requests/team.ts b/src/requests/team.ts index 29d25773..809d2a4a 100644 --- a/src/requests/team.ts +++ b/src/requests/team.ts @@ -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; @@ -71,6 +71,13 @@ export class TeamClient { ): Promise { return getBopsSubmissionURL(this.client, slug, env); } + + async updateTheme( + teamId: number, + theme: Partial, + ): Promise { + return updateTheme(this.client, teamId, theme); + } } const defaultNotifyPersonalisation = { @@ -305,3 +312,40 @@ async function getBopsSubmissionURL( return team?.integrations?.bopsSubmissionURL ?? null; } + +async function updateTheme( + client: GraphQLClient, + teamId: number, + theme: Partial, +) { + 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]); +} diff --git a/src/types/team.ts b/src/types/team.ts index 89043340..4a26bad7 100644 --- a/src/types/team.ts +++ b/src/types/team.ts @@ -5,7 +5,7 @@ export interface Team { name: string; slug: string; settings?: TeamSettings; - theme?: TeamTheme; + theme: TeamTheme; notifyPersonalisation?: NotifyPersonalisation; boundaryBBox?: GeoJsonObject; }