From 51b0a4fdca5d55c3e4c3a0df753a5e81e5e14ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 22 Sep 2023 14:56:59 +0100 Subject: [PATCH] feat: Get team by slug --- src/requests/team.ts | 25 +++++++++++++++++++++++++ src/types/team.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/types/team.ts diff --git a/src/requests/team.ts b/src/requests/team.ts index d2ab2744..27ecfe99 100644 --- a/src/requests/team.ts +++ b/src/requests/team.ts @@ -2,6 +2,7 @@ import type { GraphQLClient } from "graphql-request"; import { gql } from "graphql-request"; import { TeamRole } from "../types/roles"; +import { Team } from "../types/team"; interface UpsertMember { userId: number; @@ -57,6 +58,10 @@ export class TeamClient { async _destroyAll(): Promise { return _destroyAllTeams(this.client); } + + async getBySlug(slug: string): Promise { + return getBySlug(this.client, slug); + } } const defaultNotifyPersonalisation = { @@ -223,3 +228,23 @@ export async function removeMember( ); return Boolean(response.delete_team_members?.affected_rows); } + +async function getBySlug(client: GraphQLClient, slug: string) { + const response: { teams: Team[] } = await client.request( + gql` + query GetTeamBySlug($slug: String!) { + teams(where: { slug: { _eq: $slug } }) { + id + name + slug + settings + theme + notifyPersonalisation: notify_personalisation + boundaryBBox: boundary_bbox + } + } + `, + { slug }, + ); + return response.teams[0]; +} diff --git a/src/types/team.ts b/src/types/team.ts new file mode 100644 index 00000000..59416a0b --- /dev/null +++ b/src/types/team.ts @@ -0,0 +1,36 @@ +import { GeoJsonObject } from "geojson"; + +export interface Team { + id: number; + name: string; + slug: string; + settings?: TeamSettings; + theme?: TeamTheme; + notifyPersonalisation?: NotifyPersonalisation; + boundaryBBox?: GeoJsonObject; +} + +export interface TeamTheme { + primary?: string; + logo?: string; +} + +export interface TeamSettings { + design?: { + color?: string; + }; + homepage?: string; + externalPlanningSite: { + name: string; + url: string; + }; + supportEmail?: string; + boundary?: string; +} + +export interface NotifyPersonalisation { + helpEmail: string; + helpPhone: string; + emailReplyToId: string; + helpOpeningHours: string; +}