Skip to content

Commit

Permalink
feat: Get team by slug
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 22, 2023
1 parent e87e832 commit 51b0a4f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/requests/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +58,10 @@ export class TeamClient {
async _destroyAll(): Promise<boolean> {
return _destroyAllTeams(this.client);
}

async getBySlug(slug: string): Promise<Team> {
return getBySlug(this.client, slug);
}
}

const defaultNotifyPersonalisation = {
Expand Down Expand Up @@ -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];
}
36 changes: 36 additions & 0 deletions src/types/team.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 51b0a4f

Please sign in to comment.