From be4e7e9a633ba54ed1aba576bb1dfe00a78bb4e0 Mon Sep 17 00:00:00 2001 From: Corey Blais Date: Tue, 14 Apr 2026 14:41:13 -0400 Subject: [PATCH] chanmged app.ts based on Onyxoasis's recommendations --- backend/src/app.ts | 50 -------------------------- backend/src/clients/arsenalIqClient.ts | 30 ++++++++++++++++ 2 files changed, 30 insertions(+), 50 deletions(-) diff --git a/backend/src/app.ts b/backend/src/app.ts index f752fd4..304c62d 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -172,57 +172,7 @@ const decodeJwtPayload = (token: string) => { }; const ensureProfileDefaults = async (profileId: string) => { -<<<<<<< HEAD - await pool.query( - `UPDATE calibers - SET name = '12 Gauge - Sporting', - is_default = TRUE - WHERE profile_id = $1 - AND name = '12 Gauge' - AND NOT EXISTS ( - SELECT 1 - FROM calibers existing - WHERE existing.profile_id = $1 - AND existing.name = '12 Gauge - Sporting' - )`, - [profileId], - ); - - await pool.query( - `UPDATE calibers - SET name = '12 Gauge - Sporting', - is_default = TRUE - WHERE profile_id = $1 - AND name = '12 Gauge Sporting' - AND NOT EXISTS ( - SELECT 1 - FROM calibers existing - WHERE existing.profile_id = $1 - AND existing.name = '12 Gauge - Sporting' - )`, - [profileId], - ); - - for (const caliber of defaultCalibers) { - const caliberResult = await pool.query( - `INSERT INTO calibers (profile_id, name, is_default, is_active) - VALUES ($1, $2, TRUE, TRUE) - ON CONFLICT (profile_id, name) DO UPDATE - SET is_default = TRUE - RETURNING id, name, is_default, is_active`, - [profileId, caliber], - ); - - await pool.query( - `INSERT INTO ammo_inventory (profile_id, caliber_id, rounds_on_hand, cost_per_round) - VALUES ($1, $2, 0, 0) - ON CONFLICT (profile_id, caliber_id) DO NOTHING`, - [profileId, caliberResult.rows[0].id], - ); - } -======= await db.ensureProfileDefaults(profileId, defaultCalibers); ->>>>>>> bcd4459 (chanmged app.ts based on Onyxoasis's recommendations) }; const getUserProfiles = async (userId: string) => db.getUserProfiles(userId); diff --git a/backend/src/clients/arsenalIqClient.ts b/backend/src/clients/arsenalIqClient.ts index ae9b43a..d882ff9 100644 --- a/backend/src/clients/arsenalIqClient.ts +++ b/backend/src/clients/arsenalIqClient.ts @@ -243,6 +243,36 @@ export class ArsenalIqClient { } async ensureProfileDefaults(profileId: string, defaultCalibers: string[]) { + await this.pool.query( + `UPDATE calibers + SET name = '12 Gauge - Sporting', + is_default = TRUE + WHERE profile_id = $1 + AND name = '12 Gauge' + AND NOT EXISTS ( + SELECT 1 + FROM calibers existing + WHERE existing.profile_id = $1 + AND existing.name = '12 Gauge - Sporting' + )`, + [profileId], + ); + + await this.pool.query( + `UPDATE calibers + SET name = '12 Gauge - Sporting', + is_default = TRUE + WHERE profile_id = $1 + AND name = '12 Gauge Sporting' + AND NOT EXISTS ( + SELECT 1 + FROM calibers existing + WHERE existing.profile_id = $1 + AND existing.name = '12 Gauge - Sporting' + )`, + [profileId], + ); + for (const caliber of defaultCalibers) { const caliberResult = await this.pool.query( `INSERT INTO calibers (profile_id, name, is_default, is_active)