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

Database Hotifx #26

Merged
merged 68 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
d9e5554
feat: created DB file
Brandon-Harad Oct 10, 2024
8616432
feat: type model for scouting system
azaleacolburn Oct 23, 2024
3a9c864
chore: update svelte
azaleacolburn Oct 24, 2024
0b283c8
feat: tried
Brandon-Harad Oct 24, 2024
4cbe864
Merge branch 'main' of https://github.com/flamingchickens1540/inflate…
Brandon-Harad Oct 25, 2024
16ae2d3
feat: nothing
Brandon-Harad Oct 25, 2024
fc86844
feat: add none
azaleacolburn Oct 25, 2024
5bdf57d
feat: added DB.sql and migrations
Brandon-Harad Oct 25, 2024
63ad46c
Merge branch 'main' of https://github.com/flamingchickens1540/inflate…
Brandon-Harad Oct 25, 2024
a7fe051
refactor: type state model
azaleacolburn Oct 26, 2024
a0c787e
Merge branch 'azalea/input-grid' of https://github.com/flamingchicken…
azaleacolburn Oct 28, 2024
0b18cca
feat: state transforms
azaleacolburn Oct 30, 2024
0d37bc8
Merge branch 'azalea/input-grid' of https://github.com/flamingchicken…
azaleacolburn Oct 30, 2024
e294d06
add successfail screen
awwpotato Nov 5, 2024
f515290
theme fixes
awwpotato Nov 6, 2024
6ff4f16
Merge branch 'main' into azalea/input-grid
awwpotato Nov 9, 2024
4105ff5
fix: package.json
awwpotato Nov 9, 2024
a9571e0
fix: formating
awwpotato Nov 9, 2024
d80ad01
fix: dependencies
awwpotato Nov 9, 2024
040d95c
format thingy
awwpotato Nov 9, 2024
c9bc989
feat: implemented submit api
Brandon-Harad Nov 12, 2024
68dc558
fix: removed unnecessary line
Brandon-Harad Nov 12, 2024
c9dc82e
refactor: update types to match new schema
azaleacolburn Nov 12, 2024
9d24e18
Merge branch 'azalea/input-grid' of https://github.com/flamingchicken…
azaleacolburn Nov 12, 2024
3457625
fix: id after clarifying with Brandon
azaleacolburn Nov 12, 2024
8601e25
update dep
awwpotato Nov 12, 2024
01b0333
style: format files
awwpotato Nov 12, 2024
aa2acfa
Merge branch 'main' of https://github.com/flamingchickens1540/inflate…
Brandon-Harad Nov 13, 2024
d97b111
feat: pulled from main
Brandon-Harad Nov 13, 2024
abdf6d3
style: format files
Brandon-Harad Nov 13, 2024
bb94b2c
fix: dependencies
Brandon-Harad Nov 13, 2024
e8cf106
Merge branch 'Brandon/Database' of https://github.com/flamingchickens…
Brandon-Harad Nov 13, 2024
3263a75
style: format files
Brandon-Harad Nov 13, 2024
137b2fe
Merge branch 'azalea/input-grid' of https://github.com/flamingchicken…
Brandon-Harad Nov 14, 2024
9a506d6
Merge branch 'Brandon/Database' of https://github.com/flamingchickens…
Brandon-Harad Nov 14, 2024
f8e0d06
fix: dependencies
Brandon-Harad Nov 14, 2024
b0e280b
fix: skill property name
azaleacolburn Nov 14, 2024
e232fab
fix: removed npm config
Brandon-Harad Nov 15, 2024
1cdc2aa
Merge branch 'main' of https://github.com/flamingchickens1540/inflate…
Brandon-Harad Nov 15, 2024
71942fe
fix: bun dependencies
Brandon-Harad Nov 15, 2024
a76b60d
feat: finished submit function
Brandon-Harad Dec 1, 2024
b5d1325
feat: read route
Brandon-Harad Dec 1, 2024
2852564
feat: superscouting and pit scouting in db
Brandon-Harad Dec 3, 2024
9a4e757
fix: DB code
Brandon-Harad Dec 3, 2024
8e0a494
fix: updated queries to allow ids
Brandon-Harad Dec 3, 2024
25152cf
Merge branch 'main' of https://github.com/flamingchickens1540/inflate…
azaleacolburn Dec 3, 2024
c92db21
fix: tailwind to CommonJS module
azaleacolburn Dec 4, 2024
073c4e0
style: format files
azaleacolburn Dec 4, 2024
ce913f9
fix: queries
Brandon-Harad Dec 4, 2024
1d02a3c
Merge branch 'Brandon/Database' of https://github.com/flamingchickens…
Brandon-Harad Dec 4, 2024
74c4124
style: format files
Brandon-Harad Dec 4, 2024
8349ae7
Merge branch 'Brandon/Database' of https://github.com/flamingchickens…
Brandon-Harad Dec 5, 2024
68a204d
Merge branch 'main' of https://github.com/flamingchickens1540/inflate…
Brandon-Harad Dec 5, 2024
61ccb4c
fix: types
Brandon-Harad Dec 5, 2024
1a7cb06
style: format files
Brandon-Harad Dec 5, 2024
7460c08
feat: hooked up frontend to backend
Brandon-Harad Dec 5, 2024
9f75689
Merge branch 'Brandon/Database' of https://github.com/flamingchickens…
Brandon-Harad Dec 5, 2024
5e9cead
fix: queries
Brandon-Harad Dec 5, 2024
c72336b
feat: functional queries
Brandon-Harad Dec 10, 2024
e638740
style: format files
Brandon-Harad Dec 10, 2024
83976a7
fix: queries returning too much
Brandon-Harad Dec 10, 2024
e710b78
Merge branch 'main' of https://github.com/flamingchickens1540/inflate…
Brandon-Harad Dec 10, 2024
f292c6d
more merge
Brandon-Harad Dec 10, 2024
d8ee5d2
feat: insert to users and matches
Brandon-Harad Dec 12, 2024
6e7ef4b
style: format files
Brandon-Harad Dec 12, 2024
5236031
fix: database enums
Brandon-Harad Dec 12, 2024
048bccd
fix: missing comma
Brandon-Harad Dec 12, 2024
ddfdef0
Merge branch 'main' of https://github.com/flamingchickens1540/inflate…
azaleacolburn Dec 12, 2024
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
41 changes: 22 additions & 19 deletions migrations/DB.sql
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
CREATE TYPE tele_action_type AS ENUM (
'IntakeTote',
'IntakeBalloon',
'TakeBalloonFromCoral',

'ScoreYourHeldTote',
'ScoreOtherHeldTote',
'ScoreExternalTote',
'ScoreLowBalloon'
'IntakeTote',
'IntakeBalloon',
'ScoreBalloonInternalTote',
'ScoreBalloonExternalTote',
'ScoreBalloonUncontrolledTote',
'ScoreBalloonLow',
'EjectBalloon',
'EjectBunny',
'EjectTote'
);
CREATE TYPE auto_action_type as ENUM (
'IntakeTote',
'IntakeBalloon',
'TakeBalloonFromCoral',

'ScoreYourHeldTote',
'ScoreOtherHeldTote',
'ScoreExternalTote',
'ScoreLowBalloon',
'IntakeTote',
'IntakeBalloon',
'ScoreBalloonInternalTote',
'ScoreBalloonExternalTote',
'ScoreBalloonUncontrolledTote',
'ScoreBalloonLow',
'EjectBalloon',
'EjectBunny',
'EjectTote',

'IntakeBunny',
'ScoreBunnyTote',
'ScoreBunnyLowZone'
'ScoreBunnyInternalTote',
'ScoreBunnyExternalTote',
'ScoreBunnyUncontrolledTote',
'ScoreBunnyLow'
);
CREATE TYPE tele_action_data AS (
act tele_action_type,
Expand All @@ -39,7 +43,6 @@ CREATE TYPE drivetrain_enum as ENUM (
CREATE TABLE "Users"(
"id" SERIAL PRIMARY KEY,
"name" VARCHAR(255) NOT NULL,
"is_admin" BOOLEAN NOT NULL
);
CREATE TABLE "Teams"(
"team_key" VARCHAR(255) NOT NULL,
Expand Down
31 changes: 31 additions & 0 deletions src/lib/server-assets/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import type {
TeleActionsTM
} from '$lib/types';

// Const b/c of obvious reasons
const event_key = 'orbb2024';

// Whether or not the database is currently being used
const use_db: boolean = USE_DB === 'true';

Expand Down Expand Up @@ -218,10 +221,38 @@ export async function insertTeamMatch(match: TeamMatch): Promise<boolean> {
}
}

export async function insertUser(name: string): Promise<boolean> {
if (!use_db) return true;

try {
await db.query('INSERT INTO "Users" VALUES (DEFAULT, $1)', [name]);

return true;
} catch (error) {
console.error(error);
return false;
}
}

export async function select(matchkey: string, teamkey: string) {
if (!use_db) return null;

let response = await db.query(
'SELECT * FROM "TeamMatches" WHERE "match_key" = $1 AND "team_key" = $2',
[matchkey, teamkey]
);
return response.rows;
}

export async function insertMatch(match_key: string): Promise<boolean> {
if (!use_db) return true;

try {
await db.query('INSERT INTO "Matches" VALUES ($1, $2)', [match_key, event_key]);

return true;
} catch (error) {
console.error(error);
return false;
}
}
11 changes: 10 additions & 1 deletion src/routes/admin/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,18 @@
teams.map((team, i) => [team, colors[i]] as [string, 'red' | 'blue'])
);

const queue_match = () => {
const queue_match = async () => {
teams = teams.filter((team) => team != '');
socket.emit('send_match', [match_key, team_color]);

await fetch('/api/newmatch', {
method: 'POST',
body: JSON.stringify(match_key),
headers: {
'Content-Type': 'application/json'
}
});

match_key = '';
teams = ['', '', '', '', '', ''];
};
Expand Down
8 changes: 8 additions & 0 deletions src/routes/api/newmatch/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { insertMatch } from '$lib/server-assets/database';

export const POST: RequestHandler = async ({ request }) => {
const match_key: string = await request.json();
return json(await insertMatch(match_key));
};
4 changes: 2 additions & 2 deletions src/routes/api/submit/+server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { TeamMatch } from '$lib/types';
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { insertTeamMatch } from '$lib/server-assets/database';
import { insertTeamMatch, insertUser } from '$lib/server-assets/database';

export const POST: RequestHandler = async ({ request }) => {
const match: TeamMatch = await request.json();
return json(await insertTeamMatch(match));
return json((await insertTeamMatch(match)) && (await insertUser(match.scout_id)));
};
Loading