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: Update team.create() to match new table structure #448

Merged
merged 1 commit into from
Jul 15, 2024
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
69 changes: 18 additions & 51 deletions src/requests/team.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { GeoJsonObject } from "geojson";
import type { GraphQLClient } from "graphql-request";
import { gql } from "graphql-request";

Expand All @@ -19,13 +18,14 @@ interface RemoveMember {

type PlanXEnv = "pizza" | "staging" | "production";

interface CreateTeam {
interface NewTeam {
name: string;
slug: string;
homepage: string;
domain?: string;
reference?: string;
submissionEmail?: string;
boundary?: GeoJsonObject;
referenceCode: string;
settings?: Partial<TeamSettings>;
theme?: Partial<TeamTheme>;
}

export class TeamClient {
Expand All @@ -35,7 +35,7 @@ export class TeamClient {
this.client = client;
}

async create(args: CreateTeam): Promise<number> {
async create(args: NewTeam): Promise<number> {
return createTeam(this.client, args);
}

Expand Down Expand Up @@ -92,69 +92,36 @@ export class TeamClient {
}
}

const defaultNotifyPersonalisation = {
helpEmail: "[email protected]",
helpPhone: "(01234) 567890",
emailReplyToId: "727d48fa-cb8a-42f9-b8b2-55032f3bb451",
helpOpeningHours: "Monday - Friday, 9am - 5pm",
};

const defaultSettings = {
settings: {
homepage: "https://example.com",
externalPlanningSite: {
url: "https://planningportal.co.uk",
name: "Planning Portal",
},
},
};

export async function createTeam(
client: GraphQLClient,
{
name,
slug,
homepage,
submissionEmail,
boundary,
referenceCode,
}: CreateTeam,
newTeam: NewTeam,
): Promise<number> {
const input = {
name,
slug,
submissionEmail,
settings: {
...defaultSettings,
homepage,
},
notifyPersonalisation: defaultNotifyPersonalisation,
referenceCode,
...(boundary && { boundary }),
...newTeam,
settings: newTeam.settings ?? {},
theme: newTeam.theme ?? {},
};
const response: { insert_teams_one: { id: number } } = await client.request(
gql`
mutation CreateTeam(
$name: String!
$slug: String!
$settings: jsonb!
$domain: String
$submissionEmail: String
$notifyPersonalisation: jsonb!
$boundary: jsonb
$referenceCode: String!
$referenceCode: String
$settings: team_settings_insert_input!
$theme: team_themes_insert_input!
) {
insert_teams_one(
object: {
name: $name
slug: $slug
settings: $settings
domain: $domain
submission_email: $submissionEmail
notify_personalisation: $notifyPersonalisation
reference_code: $referenceCode
# Fall back to default values for optional values
${boundary ? "boundary: $boundary" : ""}
# Create empty records for theme and integrations - these can get populated later
theme: { data: {} }
# Create empty records for associated tables - these can get populated later
team_settings: { data: $settings }
theme: { data: $theme }
integrations: { data: {} }
}
) {
Expand Down