diff --git a/package-lock.json b/package-lock.json
index 8fc7570..f019838 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -38,7 +38,7 @@
"prettier": "^3.1.0",
"prettier-plugin-svelte": "^3.1.0",
"sass": "^1.69.5",
- "svelte": "^4.2.3",
+ "svelte": "^5.0.0-next.19",
"svelte-check": "^3.6.0",
"tailwindcss": "^3.3.5",
"tournament-pairings": "^1.5.2",
@@ -950,7 +950,7 @@
"vite": "^4.0.0"
}
},
- "node_modules/@sveltejs/vite-plugin-svelte-inspector": {
+ "node_modules/@sveltejs/vite-plugin-svelte/node_modules/@sveltejs/vite-plugin-svelte-inspector": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@sveltejs/vite-plugin-svelte-inspector/-/vite-plugin-svelte-inspector-1.0.4.tgz",
"integrity": "sha512-zjiuZ3yydBtwpF3bj0kQNV0YXe+iKE545QGZVTaylW3eAzFr+pJ/cwK8lZEaRp4JtaJXhD5DyWAV4AxLh6DgaQ==",
@@ -967,6 +967,18 @@
"vite": "^4.0.0"
}
},
+ "node_modules/@sveltejs/vite-plugin-svelte/node_modules/svelte-hmr": {
+ "version": "0.15.3",
+ "resolved": "https://registry.npmjs.org/svelte-hmr/-/svelte-hmr-0.15.3.tgz",
+ "integrity": "sha512-41snaPswvSf8TJUhlkoJBekRrABDXDMdpNpT2tfHIv4JuhgvHqLMhEPGtaQn0BmbNSTkuz2Ed20DF2eHw0SmBQ==",
+ "dev": true,
+ "engines": {
+ "node": "^12.20 || ^14.13.1 || >= 16"
+ },
+ "peerDependencies": {
+ "svelte": "^3.19.0 || ^4.0.0"
+ }
+ },
"node_modules/@tootallnate/once": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz",
@@ -998,9 +1010,9 @@
"dev": true
},
"node_modules/@types/estree": {
- "version": "1.0.1",
- "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz",
- "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA=="
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
+ "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw=="
},
"node_modules/@types/json-schema": {
"version": "7.0.15",
@@ -1421,6 +1433,14 @@
"acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
}
},
+ "node_modules/acorn-typescript": {
+ "version": "1.4.12",
+ "resolved": "https://registry.npmjs.org/acorn-typescript/-/acorn-typescript-1.4.12.tgz",
+ "integrity": "sha512-G/oj3oiBmYlc+6SJZYMRz+SPgSgBWqEXPzhO55dYvT4x8SJM+HkxU5o5OPFstxsMMk1tXPYtYCyd7jUdHZy8Eg==",
+ "peerDependencies": {
+ "acorn": ">=8.9.0"
+ }
+ },
"node_modules/acorn-walk": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz",
@@ -1629,9 +1649,9 @@
}
},
"node_modules/axobject-query": {
- "version": "3.2.1",
- "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz",
- "integrity": "sha512-jsyHu61e6N4Vbz/v18DHwWYKK0bSWLqn47eeDSKPB7m8tqMHF9YJ+mhIk2lVteyZrY8tnSj/jHOv4YiTCuCJgg==",
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.0.0.tgz",
+ "integrity": "sha512-+60uv1hiVFhHZeO+Lz0RYzsVHy5Wr1ayX0mwda9KPDVLNJgZ1T9Ny7VmFbLDzxsH0D87I86vgj3gFrjTJUYznw==",
"dependencies": {
"dequal": "^2.0.3"
}
@@ -1877,26 +1897,6 @@
"node": ">=10"
}
},
- "node_modules/code-red": {
- "version": "1.0.4",
- "resolved": "https://registry.npmjs.org/code-red/-/code-red-1.0.4.tgz",
- "integrity": "sha512-7qJWqItLA8/VPVlKJlFXU+NBlo/qyfs39aJcuMT/2ere32ZqvF5OSxgdM5xOfJJ7O429gg2HM47y8v9P+9wrNw==",
- "dependencies": {
- "@jridgewell/sourcemap-codec": "^1.4.15",
- "@types/estree": "^1.0.1",
- "acorn": "^8.10.0",
- "estree-walker": "^3.0.3",
- "periscopic": "^3.1.0"
- }
- },
- "node_modules/code-red/node_modules/estree-walker": {
- "version": "3.0.3",
- "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
- "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
- "dependencies": {
- "@types/estree": "^1.0.0"
- }
- },
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
@@ -1980,18 +1980,6 @@
"node": ">= 8"
}
},
- "node_modules/css-tree": {
- "version": "2.3.1",
- "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz",
- "integrity": "sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==",
- "dependencies": {
- "mdn-data": "2.0.30",
- "source-map-js": "^1.0.1"
- },
- "engines": {
- "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0"
- }
- },
"node_modules/cssesc": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",
@@ -2515,6 +2503,33 @@
}
}
},
+ "node_modules/eslint-plugin-svelte/node_modules/svelte-eslint-parser": {
+ "version": "0.33.1",
+ "resolved": "https://registry.npmjs.org/svelte-eslint-parser/-/svelte-eslint-parser-0.33.1.tgz",
+ "integrity": "sha512-vo7xPGTlKBGdLH8T5L64FipvTrqv3OQRx9d2z5X05KKZDlF4rQk8KViZO4flKERY+5BiVdOh7zZ7JGJWo5P0uA==",
+ "dev": true,
+ "dependencies": {
+ "eslint-scope": "^7.0.0",
+ "eslint-visitor-keys": "^3.0.0",
+ "espree": "^9.0.0",
+ "postcss": "^8.4.29",
+ "postcss-scss": "^4.0.8"
+ },
+ "engines": {
+ "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ota-meshi"
+ },
+ "peerDependencies": {
+ "svelte": "^3.37.0 || ^4.0.0"
+ },
+ "peerDependenciesMeta": {
+ "svelte": {
+ "optional": true
+ }
+ }
+ },
"node_modules/eslint-plugin-svelte/node_modules/yaml": {
"version": "1.10.2",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz",
@@ -2555,8 +2570,7 @@
"node_modules/esm-env": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/esm-env/-/esm-env-1.0.0.tgz",
- "integrity": "sha512-Cf6VksWPsTuW01vU9Mk/3vRue91Zevka5SjyNf3nEpokFRuqt/KjUQoGAwq9qMmhpLTHmXzSIrFRw8zxWzmFBA==",
- "dev": true
+ "integrity": "sha512-Cf6VksWPsTuW01vU9Mk/3vRue91Zevka5SjyNf3nEpokFRuqt/KjUQoGAwq9qMmhpLTHmXzSIrFRw8zxWzmFBA=="
},
"node_modules/espree": {
"version": "9.6.1",
@@ -2587,6 +2601,15 @@
"node": ">=0.10"
}
},
+ "node_modules/esrap": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/esrap/-/esrap-1.2.1.tgz",
+ "integrity": "sha512-dhkcOLfN/aDdMFI1iwPEcy/XqAZzGNfgfEJjZozy2tia6u0dQoZyXzkRshHTckuNsM+c0CYQndY+uRFe3N+AIQ==",
+ "dependencies": {
+ "@jridgewell/sourcemap-codec": "^1.4.15",
+ "@types/estree": "^1.0.1"
+ }
+ },
"node_modules/esrecurse": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz",
@@ -3516,11 +3539,6 @@
"node": ">= 12"
}
},
- "node_modules/mdn-data": {
- "version": "2.0.30",
- "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz",
- "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA=="
- },
"node_modules/merge2": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
@@ -3969,24 +3987,6 @@
"node": "*"
}
},
- "node_modules/periscopic": {
- "version": "3.1.0",
- "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-3.1.0.tgz",
- "integrity": "sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw==",
- "dependencies": {
- "@types/estree": "^1.0.0",
- "estree-walker": "^3.0.0",
- "is-reference": "^3.0.0"
- }
- },
- "node_modules/periscopic/node_modules/estree-walker": {
- "version": "3.0.3",
- "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
- "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
- "dependencies": {
- "@types/estree": "^1.0.0"
- }
- },
"node_modules/picocolors": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
@@ -4193,9 +4193,9 @@
}
},
"node_modules/postcss-scss": {
- "version": "4.0.8",
- "resolved": "https://registry.npmjs.org/postcss-scss/-/postcss-scss-4.0.8.tgz",
- "integrity": "sha512-Cr0X8Eu7xMhE96PJck6ses/uVVXDtE5ghUTKNUYgm8ozgP2TkgV3LWs3WgLV1xaSSLq8ZFiXaUrj0LVgG1fGEA==",
+ "version": "4.0.9",
+ "resolved": "https://registry.npmjs.org/postcss-scss/-/postcss-scss-4.0.9.tgz",
+ "integrity": "sha512-AjKOeiwAitL/MXxQW2DliT28EKukvvbEWx3LBmJIRN8KfBGZbRTxNYW0kSqi1COiTZ57nZ9NW06S6ux//N1c9A==",
"dev": true,
"funding": [
{
@@ -4698,6 +4698,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
"integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==",
+ "dev": true,
"engines": {
"node": ">=0.10.0"
}
@@ -4852,26 +4853,25 @@
}
},
"node_modules/svelte": {
- "version": "4.2.3",
- "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.3.tgz",
- "integrity": "sha512-sqmG9KC6uUc7fb3ZuWoxXvqk6MI9Uu4ABA1M0fYDgTlFYu1k02xp96u6U9+yJZiVm84m9zge7rrA/BNZdFpOKw==",
+ "version": "5.0.0-next.19",
+ "resolved": "https://registry.npmjs.org/svelte/-/svelte-5.0.0-next.19.tgz",
+ "integrity": "sha512-yFlkjYIRCLsKsDG8AlEplrAN6lJ00rFP2I5sYm51mwsdLRWUG/yPgPwl91fXNp/q1LZOo7sbHgWZ5ABTm8bdcg==",
"dependencies": {
"@ampproject/remapping": "^2.2.1",
"@jridgewell/sourcemap-codec": "^1.4.15",
- "@jridgewell/trace-mapping": "^0.3.18",
- "acorn": "^8.9.0",
+ "acorn": "^8.10.0",
+ "acorn-typescript": "^1.4.11",
"aria-query": "^5.3.0",
- "axobject-query": "^3.2.1",
- "code-red": "^1.0.3",
- "css-tree": "^2.3.1",
- "estree-walker": "^3.0.3",
+ "axobject-query": "^4.0.0",
+ "esm-env": "^1.0.0",
+ "esrap": "^1.2.1",
"is-reference": "^3.0.1",
"locate-character": "^3.0.0",
"magic-string": "^0.30.4",
- "periscopic": "^3.1.0"
+ "zimmerframe": "^1.1.0"
},
"engines": {
- "node": ">=16"
+ "node": ">=18"
}
},
"node_modules/svelte-check": {
@@ -4896,33 +4896,6 @@
"svelte": "^3.55.0 || ^4.0.0-next.0 || ^4.0.0 || ^5.0.0-next.0"
}
},
- "node_modules/svelte-eslint-parser": {
- "version": "0.33.0",
- "resolved": "https://registry.npmjs.org/svelte-eslint-parser/-/svelte-eslint-parser-0.33.0.tgz",
- "integrity": "sha512-5awZ6Bs+Tb/zQwa41PSdcLynAVQTwW0HGyCBjtbAQ59taLZqDgQSMzRlDmapjZdDtzERm0oXDZNE0E+PKJ6ryg==",
- "dev": true,
- "dependencies": {
- "eslint-scope": "^7.0.0",
- "eslint-visitor-keys": "^3.0.0",
- "espree": "^9.0.0",
- "postcss": "^8.4.28",
- "postcss-scss": "^4.0.7"
- },
- "engines": {
- "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
- },
- "funding": {
- "url": "https://github.com/sponsors/ota-meshi"
- },
- "peerDependencies": {
- "svelte": "^3.37.0 || ^4.0.0"
- },
- "peerDependenciesMeta": {
- "svelte": {
- "optional": true
- }
- }
- },
"node_modules/svelte-hamburgers": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/svelte-hamburgers/-/svelte-hamburgers-4.2.0.tgz",
@@ -4931,18 +4904,6 @@
"svelte": "^3.46.4 || ^4.0.0"
}
},
- "node_modules/svelte-hmr": {
- "version": "0.15.3",
- "resolved": "https://registry.npmjs.org/svelte-hmr/-/svelte-hmr-0.15.3.tgz",
- "integrity": "sha512-41snaPswvSf8TJUhlkoJBekRrABDXDMdpNpT2tfHIv4JuhgvHqLMhEPGtaQn0BmbNSTkuz2Ed20DF2eHw0SmBQ==",
- "dev": true,
- "engines": {
- "node": "^12.20 || ^14.13.1 || >= 16"
- },
- "peerDependencies": {
- "svelte": "^3.19.0 || ^4.0.0"
- }
- },
"node_modules/svelte-preprocess": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/svelte-preprocess/-/svelte-preprocess-5.1.0.tgz",
@@ -5017,14 +4978,6 @@
"node": ">=12"
}
},
- "node_modules/svelte/node_modules/estree-walker": {
- "version": "3.0.3",
- "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
- "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
- "dependencies": {
- "@types/estree": "^1.0.0"
- }
- },
"node_modules/svg.draggable.js": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/svg.draggable.js/-/svg.draggable.js-2.2.2.tgz",
@@ -5917,6 +5870,11 @@
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
+ },
+ "node_modules/zimmerframe": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/zimmerframe/-/zimmerframe-1.1.0.tgz",
+ "integrity": "sha512-+AmV37r9NPUy7KcuG0Fde9AAFSD88kN5pnqvD7Pkp5WLLK0jct7hAtIDXXFDCRk3l5Mc1r2Sth3gfP2ZLE+/Qw=="
}
}
}
diff --git a/package.json b/package.json
index a91d5ae..738de77 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
"prettier": "^3.1.0",
"prettier-plugin-svelte": "^3.1.0",
"sass": "^1.69.5",
- "svelte": "^4.2.3",
+ "svelte": "^5.0.0-next.19",
"svelte-check": "^3.6.0",
"tailwindcss": "^3.3.5",
"tournament-pairings": "^1.5.2",
diff --git a/src/lib/components/tournament/Teams.svelte b/src/lib/components/tournament/Teams.svelte
index 2840c26..23d670c 100644
--- a/src/lib/components/tournament/Teams.svelte
+++ b/src/lib/components/tournament/Teams.svelte
@@ -2,7 +2,7 @@
import { success, error } from '$lib/toast';
import type { Tournament } from '$lib/tournament';
import type { HttpError_1 } from '@sveltejs/kit';
- import { TableBody, TableBodyCell, Table, TableBodyRow, TableSearch } from 'flowbite-svelte';
+ import { TableBody, TableBodyCell, TableBodyRow, TableSearch } from 'flowbite-svelte';
export let tournament: Tournament;
// TODO: Handle alerting that adding or removing a team will wipe out
@@ -43,7 +43,7 @@
}
let searchTerm: string = '';
- $: filteredTeams = tournament.settings.teams.filter(
+ $: filteredTeams = tournament?.settings?.teams?.filter(
(team: TeamRow) => team.name.toLowerCase().indexOf(searchTerm.toLowerCase()) !== -1
);
let newTeamName = '';
@@ -58,36 +58,39 @@
hoverable={true}
bind:inputValue={searchTerm}
>
-
- {#each filteredTeams as team}
+ {#if filteredTeams && filteredTeams.length > 0}
+
+ {#each filteredTeams as team}
+
+ {team.name}
+
+
+
+ {/each}
- {team.name}
+
+
+
createTeam()}
+ class="font-medium text-blue-600 hover:underline dark:text-primary-500"
+ >Add new team
- {/each}
-
-
-
-
-
-
-
-
+
+ {/if}
diff --git a/src/lib/tournament.ts b/src/lib/tournament.ts
index d8e2a13..f7d33f2 100644
--- a/src/lib/tournament.ts
+++ b/src/lib/tournament.ts
@@ -3,261 +3,266 @@ import type { PostgrestSingleResponse, PostgrestResponse } from '@supabase/supab
import { RoundRobin } from 'tournament-pairings';
export class Tournament {
- supabaseClient: supabaseClient;
- id?: string;
- settings: EventRow;
- matches?: MatchRow[];
-
- constructor(supabaseClient: supabaseClient) {
- this.supabaseClient = supabaseClient;
- this.settings = {};
- }
- /*
+ supabaseClient: supabaseClient;
+ id?: string;
+ settings: EventRow;
+ matches?: MatchRow[];
+
+ constructor(supabaseClient: supabaseClient) {
+ this.supabaseClient = supabaseClient;
+ this.settings = {};
+ }
+ /*
Create a new event, this creates our event ONLY (tournament settings).
*/
- async createEvent(input: EventRow): Promise {
- if (!input.name || !input.pools || !input.courts) {
- throw error(400, `Tournament create call does not have all required values`);
- }
-
- const ownerId = (await this.supabaseClient.auth.getUser()).data.user?.id;
-
- const res: PostgrestSingleResponse = await this.supabaseClient
- .from('events')
- .insert({
- owner: ownerId,
- name: input.name,
- pools: input.pools,
- courts: input.courts,
- date: input.date
- })
- .select()
- .single();
-
- if (res.error) {
- console.error('Failed to create new event');
- throw error(res.status, res.error);
- }
-
- this.id = res.data.id;
- this.settings = res.data;
-
- return this;
- }
-
- // TODO: Handle adding/removing teams
- async updateTournament(id: string, input: EventRow): Promise {
- if (!input.name || !input.date || !input.pools || !input.courts) {
- throw error(400, `Tournament update call does not have all required values`);
- }
-
- const res: PostgrestSingleResponse = await this.supabaseClient
- .from('events')
- .update({
- name: input.name,
- pools: input.pools,
- courts: input.courts,
- date: input.date
- })
- .eq('id', id)
- .select();
-
- if (res.error) {
- throw error(res.status, res.error);
- }
-
- // TODO: Reload this if it was changed
- input.teams = this.settings.teams;
-
- this.settings = input;
-
- return this;
- }
-
- /*
+ async createEvent(input: EventRow): Promise {
+ if (!input.name || !input.pools || !input.courts) {
+ throw error(400, `Tournament create call does not have all required values`);
+ }
+
+ const ownerId = (await this.supabaseClient.auth.getUser()).data.user?.id;
+
+ const res: PostgrestSingleResponse = await this.supabaseClient
+ .from('events')
+ .insert({
+ owner: ownerId,
+ name: input.name,
+ pools: input.pools,
+ courts: input.courts,
+ date: input.date
+ })
+ .select()
+ .single();
+
+ if (res.error) {
+ console.error('Failed to create new event');
+ throw error(res.status, res.error);
+ }
+
+ this.id = res.data.id;
+ this.settings = res.data;
+
+ return this;
+ }
+
+ async deleteEvent(): Promise {
+ throw new Error('Function not implemented.');
+ }
+
+
+ // TODO: Handle adding/removing teams
+ async updateTournament(id: string, input: EventRow): Promise {
+ if (!input.name || !input.date || !input.pools || !input.courts) {
+ throw error(400, `Tournament update call does not have all required values`);
+ }
+
+ const res: PostgrestSingleResponse = await this.supabaseClient
+ .from('events')
+ .update({
+ name: input.name,
+ pools: input.pools,
+ courts: input.courts,
+ date: input.date
+ })
+ .eq('id', id)
+ .select();
+
+ if (res.error) {
+ throw error(res.status, res.error);
+ }
+
+ // TODO: Reload this if it was changed
+ input.teams = this.settings.teams;
+
+ this.settings = input;
+
+ return this;
+ }
+
+ /*
Attempt to load our event (tournament settings) via SupaBase, we load matches and teams elsewhere.
*/
- async loadEvent(eventId?: string): Promise {
- if (!eventId) {
- throw error(400, 'Invalid event ID, are you sure your link is correct?');
- }
-
- try {
- const eventResponse: PostgrestSingleResponse = await this.supabaseClient
- .from('events')
- .select('*')
- .eq('id', eventId)
- .single();
-
- if (eventResponse.error) {
- throw error(eventResponse.status, eventResponse.error.details);
- }
-
- this.id = eventResponse.data.id;
- this.settings = eventResponse.data;
-
- this.settings.teams = await this.loadEventTeams();
-
- return this;
- } catch (err) {
- // Handle and log the error appropriately
- console.error('Failed to load event:', err);
- throw err;
- }
- }
-
- async saveTournament(): Promise {
- throw new Error('Function not implemented.');
- }
-
- /*
+ async loadEvent(eventId?: string): Promise {
+ if (!eventId) {
+ throw error(400, 'Invalid event ID, are you sure your link is correct?');
+ }
+
+ try {
+ const eventResponse: PostgrestSingleResponse = await this.supabaseClient
+ .from('events')
+ .select('*')
+ .eq('id', eventId)
+ .single();
+
+ if (eventResponse.error) {
+ throw error(eventResponse.status, eventResponse.error.details);
+ }
+
+ this.id = eventResponse.data.id;
+ this.settings = eventResponse.data;
+
+ this.settings.teams = await this.loadEventTeams();
+
+ return this;
+ } catch (err) {
+ // Handle and log the error appropriately
+ console.error('Failed to load event:', err);
+ throw err;
+ }
+ }
+
+ async saveTournament(): Promise {
+ throw new Error('Function not implemented.');
+ }
+
+ /*
Load all matches for the current tournament.
*/
- async loadMatches(): Promise {
- const res: PostgrestSingleResponse = await this.supabaseClient
- .from('matches')
- .select('*, matches_team1_fkey(name), matches_team2_fkey(name)')
- .eq('event_id', this.id);
-
- if (res.error) {
- throw error(res.status, res.error);
- }
- this.matches = res.data;
- return res.data;
- }
-
- /**
- * Insert new match.
- */
- async saveMatch() {
- throw new Error('Function not implemented.');
- }
-
- async createMatches() {
- const matches = RoundRobin(this.settings.teams);
-
- // Delete all old matches as they are now invalid
- const deleteRes = await this.supabaseClient.from('matches').delete().eq('event_id', this.id);
-
- if (deleteRes.error) {
- console.error(`Failed to delete old matches: ${JSON.stringify(deleteRes.error)}`);
- throw error(deleteRes.status, deleteRes.error);
- }
-
- let courtsAvailable = this.settings.courts;
- let teamsAvailable = this.settings.teams.length;
- let round = 0;
-
- let totalRounds = 0;
- let userMatches: UserMatch[] = [];
- matches.forEach((match: UserMatch) => {
- // Short circuit if we have more matches than pool play games
- // (you don't play every team).
- if (totalRounds === this.settings.pools) {
- return;
- }
-
- if (courtsAvailable === 0 || teamsAvailable.length < 2) {
- courtsAvailable = this.settings.courts;
- teamsAvailable = this.settings.teams.length;
- round = round + 1;
- totalRounds = totalRounds + 1;
- }
-
- match.court = this.settings.courts - courtsAvailable;
- match.round = round;
-
- courtsAvailable = courtsAvailable - 1;
- teamsAvailable = teamsAvailable - 2;
-
- userMatches.push({
- event_id: this.id,
- team1: match.player1.id,
- team2: match.player2.id,
- court: match.court,
- round: match.round
- });
- });
-
- // Call multi insert:
- const res = await this.supabaseClient
- .from('matches')
- .insert(userMatches)
- .select('*, matches_team1_fkey(name), matches_team2_fkey(name)');
-
- if (res.error) {
- console.error(`Failed to create new matches: ${JSON.stringify(res.error)}`);
- throw error(res.status, res.error);
- }
-
- this.matches = res.data;
- return this;
- }
-
- /*
+ async loadMatches(): Promise {
+ const res: PostgrestSingleResponse = await this.supabaseClient
+ .from('matches')
+ .select('*, matches_team1_fkey(name), matches_team2_fkey(name)')
+ .eq('event_id', this.id);
+
+ if (res.error) {
+ throw error(res.status, res.error);
+ }
+ this.matches = res.data;
+ return res.data;
+ }
+
+ /**
+ * Insert new match.
+ */
+ async saveMatch() {
+ throw new Error('Function not implemented.');
+ }
+
+ async createMatches() {
+ const matches = RoundRobin(this.settings.teams);
+
+ // Delete all old matches as they are now invalid
+ const deleteRes = await this.supabaseClient.from('matches').delete().eq('event_id', this.id);
+
+ if (deleteRes.error) {
+ console.error(`Failed to delete old matches: ${JSON.stringify(deleteRes.error)}`);
+ throw error(deleteRes.status, deleteRes.error);
+ }
+
+ let courtsAvailable = this.settings.courts;
+ let teamsAvailable = this.settings.teams.length;
+ let round = 0;
+
+ let totalRounds = 0;
+ let userMatches: UserMatch[] = [];
+ matches.forEach((match: UserMatch) => {
+ // Short circuit if we have more matches than pool play games
+ // (you don't play every team).
+ if (totalRounds === this.settings.pools) {
+ return;
+ }
+
+ if (courtsAvailable === 0 || teamsAvailable.length < 2) {
+ courtsAvailable = this.settings.courts;
+ teamsAvailable = this.settings.teams.length;
+ round = round + 1;
+ totalRounds = totalRounds + 1;
+ }
+
+ match.court = this.settings.courts - courtsAvailable;
+ match.round = round;
+
+ courtsAvailable = courtsAvailable - 1;
+ teamsAvailable = teamsAvailable - 2;
+
+ userMatches.push({
+ event_id: this.id,
+ team1: match.player1.id,
+ team2: match.player2.id,
+ court: match.court,
+ round: match.round
+ });
+ });
+
+ // Call multi insert:
+ const res = await this.supabaseClient
+ .from('matches')
+ .insert(userMatches)
+ .select('*, matches_team1_fkey(name), matches_team2_fkey(name)');
+
+ if (res.error) {
+ console.error(`Failed to create new matches: ${JSON.stringify(res.error)}`);
+ throw error(res.status, res.error);
+ }
+
+ this.matches = res.data;
+ return this;
+ }
+
+ /*
Either adding updating match metadata such as teams in the match or adding results.
*/
- async updateMatch() {
- throw new Error('Function not implemented.');
- }
+ async updateMatch() {
+ throw new Error('Function not implemented.');
+ }
- /*
+ /*
Inserts new team into supabase, if a team exists where team name and event id match what we
are trying to create, then return that team Id.
*/
- async createTeam(team: TeamRow): Promise {
- let res: PostgrestSingleResponse;
- res = await this.supabaseClient
- .from('teams')
- .upsert({ ...team })
- .select();
-
- if (res.error) {
- console.error('Failed to create new team');
- throw error(res.status, res.error);
- }
- return res.data.id;
- }
-
- async deleteTeam(team: TeamRow): Promise {
- let res: PostgrestSingleResponse;
- res = await this.supabaseClient.from('teams').delete().eq('id', team.id);
-
- if (res.error) {
- console.error('Failed to delete team');
- throw error(res.status, res.error);
- }
- }
-
- async loadEventTeams() {
- const teamsResponse: PostgrestResponse = await this.supabaseClient
- .from('teams')
- .select()
- .eq('event_id', this.id);
-
- if (teamsResponse.error) {
- throw error(teamsResponse?.status, teamsResponse.error);
- }
- this.settings.teams = teamsResponse.data;
- return this.settings.teams;
- }
+ async createTeam(team: TeamRow): Promise {
+ let res: PostgrestSingleResponse;
+ res = await this.supabaseClient
+ .from('teams')
+ .upsert({ ...team })
+ .select();
+
+ if (res.error) {
+ console.error('Failed to create new team');
+ throw error(res.status, res.error);
+ }
+ return res.data.id;
+ }
+
+ async deleteTeam(team: TeamRow): Promise {
+ let res: PostgrestSingleResponse;
+ res = await this.supabaseClient.from('teams').delete().eq('id', team.id);
+
+ if (res.error) {
+ console.error('Failed to delete team');
+ throw error(res.status, res.error);
+ }
+ }
+
+ async loadEventTeams() {
+ const teamsResponse: PostgrestResponse = await this.supabaseClient
+ .from('teams')
+ .select()
+ .eq('event_id', this.id);
+
+ if (teamsResponse.error) {
+ throw error(teamsResponse?.status, teamsResponse.error);
+ }
+ this.settings.teams = teamsResponse.data;
+ return this.settings.teams;
+ }
}
/*
Load all events for the provided owner Id.
*/
export async function loadEvents(
- supabaseClient: supabaseClient,
- ownerId: string
+ supabaseClient: supabaseClient,
+ ownerId: string
): Promise {
- return await supabaseClient
- .from('events')
- .select('*')
- .eq('owner', ownerId)
- .then((res: PostgrestResponse) => {
- if (res?.error) {
- throw error(res.status, res?.error);
- }
- return res.data;
- });
+ return await supabaseClient
+ .from('events')
+ .select('*')
+ .eq('owner', ownerId)
+ .then((res: PostgrestResponse) => {
+ if (res?.error) {
+ throw error(res.status, res?.error);
+ }
+ return res.data;
+ });
}