Skip to content

Commit

Permalink
fix: Remove duplicated referenceCode from CreateTeam query (#454)
Browse files Browse the repository at this point in the history
## What does this PR do?
- Follow up to #448 
- Fixes a few things missed in this PR
  - Proper handling of camelCase → snake_case
  - Updated query when building DPA payload
  • Loading branch information
DafyddLlyr authored Jul 15, 2024
1 parent 042e381 commit 6e330a9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/export/digitalPlanning/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const mockMetadataForSession = (
team: {
name: teamSlug,
slug: teamSlug,
referenceCode: referenceCode,
settings: {
referenceCode: referenceCode,
},
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/export/digitalPlanning/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ export class DigitalPlanning {
private getMetadata(): Payload["metadata"] {
return {
id: this.sessionId,
organisation: this.metadata.flow.team.referenceCode,
organisation: this.metadata.flow.team.settings.referenceCode,
submittedAt: new Date().toISOString(),
source: "PlanX",
service: {
Expand Down
4 changes: 3 additions & 1 deletion src/requests/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export async function getSessionMetadata(
team {
name
slug
referenceCode: reference_code
settings: team_settings {
referenceCode: reference_code
}
}
}
}
Expand Down
31 changes: 23 additions & 8 deletions src/requests/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,13 @@ export async function createTeam(
client: GraphQLClient,
newTeam: NewTeam,
): Promise<number> {
const input = {
...newTeam,
settings: newTeam.settings ?? {},
theme: newTeam.theme ?? {},
};
const response: { insert_teams_one: { id: number } } = await client.request(
gql`
mutation CreateTeam(
$name: String!
$slug: String!
$domain: String
$submissionEmail: String
$referenceCode: String
$settings: team_settings_insert_input!
$theme: team_themes_insert_input!
) {
Expand All @@ -118,7 +112,6 @@ export async function createTeam(
slug: $slug
domain: $domain
submission_email: $submissionEmail
reference_code: $referenceCode
# Create empty records for associated tables - these can get populated later
team_settings: { data: $settings }
theme: { data: $theme }
Expand All @@ -129,7 +122,29 @@ export async function createTeam(
}
}
`,
input,
{
...newTeam,
settings: {
boundary_url: newTeam?.settings?.boundaryUrl,
boundary_bbox: newTeam?.settings?.boundaryBBox,
reference_code: newTeam?.settings?.referenceCode,
help_email: newTeam?.settings?.helpEmail,
help_phone: newTeam?.settings?.helpPhone,
help_opening_hours: newTeam?.settings?.helpOpeningHours,
email_reply_to_id: newTeam?.settings?.emailReplyToId,
homepage: newTeam?.settings?.homepage,
external_planning_site_url: newTeam?.settings?.externalPlanningSiteUrl,
external_planning_site_name:
newTeam?.settings?.externalPlanningSiteName,
},
theme: {
primary_colour: newTeam.theme?.primaryColour,
action_colour: newTeam.theme?.actionColour,
link_colour: newTeam.theme?.linkColour,
logo: newTeam.theme?.logo,
favicon: newTeam.theme?.favicon,
},
},
);
return response.insert_teams_one.id;
}
Expand Down
4 changes: 3 additions & 1 deletion src/types/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export type SessionMetadata = {
team: {
name: string;
slug: string;
referenceCode: string;
settings: {
referenceCode: string;
};
};
};
};

0 comments on commit 6e330a9

Please sign in to comment.