From 75c3c53c5ecb8bec7d687f659e1fafcb2a08a1a7 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Mon, 24 Apr 2023 21:28:38 +0200 Subject: [PATCH] fix 2 for offhand weapon --- .../2023-04-24-01 Offhand weapons patch.ts | 40 +++++++++---------- src/db/model.ts | 12 ++++-- src/server/server.ts | 34 +++++++++------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/db/migrations/2023-04-24-01 Offhand weapons patch.ts b/src/db/migrations/2023-04-24-01 Offhand weapons patch.ts index e8a9b77..162c4b0 100644 --- a/src/db/migrations/2023-04-24-01 Offhand weapons patch.ts +++ b/src/db/migrations/2023-04-24-01 Offhand weapons patch.ts @@ -10,33 +10,31 @@ const pgClient = new Client({ export async function up(db: Kysely): Promise { await pgClient.connect() - await pgClient.query( - `ALTER TABLE kill RENAME attacker_offhand_weapon_3 TO victim_offhand_weapon_3_mods;` - ) - await pgClient.query( - `ALTER TABLE kill RENAME attacker_offhand_weapon_2 TO victim_offhand_weapon_2_mods;` - ) - await pgClient.query( - `ALTER TABLE kill RENAME attacker_offhand_weapon_1 TO victim_offhand_weapon_1_mods;` - ) - await pgClient.query( - `ALTER TABLE kill RENAME victim_offhand_weapon_3 TO victim_offhand_weapon_3_mods;` - ) - await pgClient.query( - `ALTER TABLE kill RENAME victim_offhand_weapon_2 TO victim_offhand_weapon_2_mods;` - ) - await pgClient.query( - `ALTER TABLE kill RENAME victim_offhand_weapon_1 TO victim_offhand_weapon_1_mods;` - ) + await pgClient.query(`ALTER TABLE kill RENAME attacker_offhand_weapon_2 TO victim_offhand_weapon_2_mods;`) + await pgClient.query(`ALTER TABLE kill RENAME attacker_offhand_weapon_1 TO victim_offhand_weapon_1_mods;`) + await pgClient.query(`ALTER TABLE kill RENAME victim_offhand_weapon_2 TO victim_offhand_weapon_2_mods;`) + await pgClient.query(`ALTER TABLE kill RENAME victim_offhand_weapon_1 TO victim_offhand_weapon_1_mods;`) await pgClient.query(`ALTER TABLE kill ADD COLUMN IF NOT EXISTS victim_offhand_weapon_1 character varying NULL;`) await pgClient.query(`ALTER TABLE kill ADD COLUMN IF NOT EXISTS victim_offhand_weapon_2 character varying NULL;`) - await pgClient.query(`ALTER TABLE kill ADD COLUMN IF NOT EXISTS victim_offhand_weapon_3 character varying NULL;`) await pgClient.query(`ALTER TABLE kill ADD COLUMN IF NOT EXISTS attacker_offhand_weapon_1 character varying NULL;`) await pgClient.query(`ALTER TABLE kill ADD COLUMN IF NOT EXISTS attacker_offhand_weapon_2 character varying NULL;`) - await pgClient.query(`ALTER TABLE kill ADD COLUMN IF NOT EXISTS attacker_offhand_weapon_3 character varying NULL;`) //Update the hosts column once the hoster table is manually updated await pgClient.end() } -export async function down(db: Kysely): Promise { } +export async function down(db: Kysely): Promise { + await pgClient.connect() + + await pgClient.query(`ALTER TABLE kill DROP COLUMN IF EXISTS victim_offhand_weapon_1;`) + await pgClient.query(`ALTER TABLE kill DROP COLUMN IF EXISTS victim_offhand_weapon_2;`) + await pgClient.query(`ALTER TABLE kill DROP COLUMN IF EXISTS attacker_offhand_weapon_1;`) + await pgClient.query(`ALTER TABLE kill DROP COLUMN IF EXISTS attacker_offhand_weapon_2;`) + + await pgClient.query(`ALTER TABLE kill RENAME attacker_offhand_weapon_2_mods TO victim_offhand_weapon_2;`) + await pgClient.query(`ALTER TABLE kill RENAME attacker_offhand_weapon_1_mods TO victim_offhand_weapon_1;`) + await pgClient.query(`ALTER TABLE kill RENAME victim_offhand_weapon_2_mods TO victim_offhand_weapon_2;`) + await pgClient.query(`ALTER TABLE kill RENAME victim_offhand_weapon_1_mods TO victim_offhand_weapon_1;`) + + await pgClient.end() +} diff --git a/src/db/model.ts b/src/db/model.ts index 6939787..614b956 100644 --- a/src/db/model.ts +++ b/src/db/model.ts @@ -21,8 +21,10 @@ export interface KillTable { attacker_weapon_2_mods: number attacker_weapon_3: string attacker_weapon_3_mods: number - attacker_offhand_weapon_1: number - attacker_offhand_weapon_2: number + attacker_offhand_weapon_1: string + attacker_offhand_weapon_1_mods: number + attacker_offhand_weapon_2: string + attacker_offhand_weapon_2_mods: number victim_name: string victim_id: string victim_current_weapon: string @@ -33,8 +35,10 @@ export interface KillTable { victim_weapon_2_mods: number victim_weapon_3: string victim_weapon_3_mods: string - victim_offhand_weapon_1: number - victim_offhand_weapon_2: number + victim_offhand_weapon_1: string + victim_offhand_weapon_1_mods: number + victim_offhand_weapon_2: string + victim_offhand_weapon_2_mods: number cause_of_death: string distance: number titan?: string diff --git a/src/server/server.ts b/src/server/server.ts index d742446..16bac1b 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -56,14 +56,14 @@ router.post( 'attacker_weapon_1_mods', 'attacker_weapon_2_mods', 'attacker_weapon_3_mods', - 'attacker_offhand_weapon_1', - 'attacker_offhand_weapon_2', + 'attacker_offhand_weapon_1_mods', + 'attacker_offhand_weapon_2_mods', 'victim_current_weapon_mods', 'victim_weapon_1_mods', 'victim_weapon_2_mods', 'victim_weapon_3_mods', - 'victim_offhand_weapon_1', - 'victim_offhand_weapon_2' + 'victim_offhand_weapon_1_mods', + 'victim_offhand_weapon_2_mods' ]).customSanitizer((value) => { if (isNaN(value) || !value) { value = 0 @@ -75,14 +75,14 @@ router.post( 'attacker_weapon_1_mods', 'attacker_weapon_2_mods', 'attacker_weapon_3_mods', - 'attacker_offhand_weapon_1', - 'attacker_offhand_weapon_2', + 'attacker_offhand_weapon_1_mods', + 'attacker_offhand_weapon_2_mods', 'victim_current_weapon_mods', 'victim_weapon_1_mods', 'victim_weapon_2_mods', 'victim_weapon_3_mods', - 'victim_offhand_weapon_1', - 'victim_offhand_weapon_2' + 'victim_offhand_weapon_1_mods', + 'victim_offhand_weapon_2_mods' ]) .toInt() .isInt() @@ -107,19 +107,17 @@ router.post( 'attacker_name', 'attacker_current_weapon', 'attacker_weapon_1', - 'attacker_weapon_1_mods', 'attacker_weapon_2', - 'attacker_weapon_2_mods', 'attacker_weapon_3', - 'attacker_weapon_3_mods', + 'attacker_offhand_weapon_1', + 'attacker_offhand_weapon_2', 'victim_name', 'victim_current_weapon', 'victim_weapon_1', - 'victim_weapon_1_mods', 'victim_weapon_2', - 'victim_weapon_2_mods', 'victim_weapon_3', - 'victim_weapon_3_mods', + 'victim_offhand_weapon_1', + 'victim_offhand_weapon_2', 'cause_of_death', 'victim_titan', 'attacker_titan' @@ -161,7 +159,9 @@ router.post( attacker_weapon_3, attacker_weapon_3_mods, attacker_offhand_weapon_1, + attacker_offhand_weapon_1_mods, attacker_offhand_weapon_2, + attacker_offhand_weapon_2_mods, victim_name, victim_id, victim_current_weapon, @@ -173,7 +173,9 @@ router.post( victim_weapon_3, victim_weapon_3_mods, victim_offhand_weapon_1, + victim_offhand_weapon_1_mods, victim_offhand_weapon_2, + victim_offhand_weapon_2_mods, cause_of_death, distance } = req.body @@ -197,7 +199,9 @@ router.post( attacker_weapon_3, attacker_weapon_3_mods, attacker_offhand_weapon_1, + attacker_offhand_weapon_1_mods, attacker_offhand_weapon_2, + attacker_offhand_weapon_2_mods, victim_name, victim_id, victim_current_weapon, @@ -209,7 +213,9 @@ router.post( victim_weapon_3, victim_weapon_3_mods, victim_offhand_weapon_1, + victim_offhand_weapon_1_mods, victim_offhand_weapon_2, + victim_offhand_weapon_2_mods, cause_of_death, distance })