From 8d7b3909f61682c7d8d2efa78ed24df364ec5585 Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Sat, 20 Aug 2022 21:44:17 +0700 Subject: [PATCH] fix if value is 0 will not update to db --- src/modules/cars.ts | 48 ++++++++++++++++++++--------------------- src/util/common.ts | 4 ++++ src/util/games/ghost.ts | 42 +++++++++++++++++++----------------- src/util/games/story.ts | 15 ++++++------- 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/modules/cars.ts b/src/modules/cars.ts index 3b3b369..5358a9c 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -530,24 +530,24 @@ export default class CarModule extends Module { { // Car update data data = { - customColor: cars.customColor || undefined, - wheel: cars.wheel || undefined, - wheelColor: cars.wheelColor || undefined, - aero: cars.aero || undefined, - bonnet: cars.bonnet || undefined, - wing: cars.wing || undefined, - mirror: cars.mirror || undefined, - neon: cars.neon || undefined, - trunk: cars.trunk || undefined, - plate: cars.plate || undefined, - plateColor: cars.plateColor || undefined, - plateNumber: cars.plateNumber || undefined, - windowSticker: cars.windowSticker || undefined, - windowDecoration: cars.windowDecoration || undefined, - rivalMarker: cars.rivalMarker || undefined, - aura: cars.aura || undefined, - auraMotif: cars.auraMotif || undefined, - rgStamp: body?.rgStamp! || undefined, + customColor: common.sanitizeInput(cars.customColor), + wheel: common.sanitizeInput(cars.wheel), + wheelColor: common.sanitizeInput(cars.wheelColor), + aero: common.sanitizeInput(cars.aero), + bonnet: common.sanitizeInput(cars.bonnet), + wing: common.sanitizeInput(cars.wing), + mirror: common.sanitizeInput(cars.mirror), + neon: common.sanitizeInput(cars.neon), + trunk: common.sanitizeInput(cars.trunk), + plate: common.sanitizeInput(cars.plate), + plateColor: common.sanitizeInput(cars.plateColor), + plateNumber: common.sanitizeInput(cars.plateNumber), + windowSticker: common.sanitizeInput(cars.windowSticker), + windowDecoration: common.sanitizeInput(cars.windowDecoration), + rivalMarker: common.sanitizeInput(cars.rivalMarker), + aura: common.sanitizeInput(cars.aura), + auraMotif: common.sanitizeInput(cars.auraMotif), + rgStamp: common.sanitizeInput(body.rgStamp), } // Update the car info @@ -634,12 +634,12 @@ export default class CarModule extends Module { if (gtWing) { let dataGTWing : any = { - pillar: gtWing.pillar || undefined, - pillarMaterial: gtWing.pillarMaterial || undefined, - mainWing: gtWing.mainWing || undefined, - mainWingColor: gtWing.mainWingColor || undefined, - wingTip: gtWing.wingTip || undefined, - material: gtWing.material || undefined, + pillar: common.sanitizeInput(gtWing.pillar), + pillarMaterial: common.sanitizeInput(gtWing.pillarMaterial), + mainWing: common.sanitizeInput(gtWing.mainWing), + mainWingColor: common.sanitizeInput(gtWing.mainWingColor), + wingTip: common.sanitizeInput(gtWing.wingTip), + material: common.sanitizeInput(gtWing.material), } await prisma.carGTWing.update({ diff --git a/src/util/common.ts b/src/util/common.ts index ef3bdcc..db84cde 100644 --- a/src/util/common.ts +++ b/src/util/common.ts @@ -41,4 +41,8 @@ export function getBigIntFromLong(n: Long) // Return the finished value return Number(bigInt); +} + +export function sanitizeInput(value: any){ + return (value == null || value == undefined) ? undefined : value; } \ No newline at end of file diff --git a/src/util/games/ghost.ts b/src/util/games/ghost.ts index 7752c2c..b7f3a07 100644 --- a/src/util/games/ghost.ts +++ b/src/util/games/ghost.ts @@ -3,8 +3,10 @@ import { prisma } from "../.."; // Import Proto import { wm } from "../../wmmt/wm.proto"; import wmproto from "../../wmmt/wm.proto"; -import * as ghost_history from "../games/games_util/ghost_history"; +// Import Util +import * as common from "../../util/common"; +import * as ghost_history from "../games/games_util/ghost_history"; // Save ghost battle result export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequest, car: any) @@ -34,10 +36,10 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ { // Ghost update data dataGhost = { - rgRegionMapScore: ghostResult.rgRegionMapScore || undefined, - rgPlayCount: ghostResult.rgPlayCount || undefined, - dressupLevel: ghostResult.dressupLevel || undefined, - dressupPoint: ghostResult.dressupPoint || undefined, + rgRegionMapScore: common.sanitizeInput(ghostResult.rgRegionMapScore), + rgPlayCount: common.sanitizeInput(ghostResult.rgPlayCount), + dressupLevel: common.sanitizeInput(ghostResult.dressupLevel), + dressupPoint: common.sanitizeInput(ghostResult.dressupPoint), } } @@ -62,18 +64,18 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ // Car update data dataCar = { - wheel: cars.wheel || undefined, - wheelColor: cars.wheelColor || undefined, - aero: cars.aero || undefined, - bonnet: cars.bonnet || undefined, - wing: cars.wing || undefined, - mirror: cars.mirror || undefined, - neon: cars.neon || undefined, - trunk: cars.trunk || undefined, - plate: cars.plate || undefined, - plateColor: cars.plateColor || undefined, - plateNumber: cars.plateNumber || undefined, - ghostLevel: cars.ghostLevel || undefined, + wheel: common.sanitizeInput(cars.wheel), + wheelColor: common.sanitizeInput(cars.wheelColor), + aero: common.sanitizeInput(cars.aero), + bonnet: common.sanitizeInput(cars.bonnet), + wing: common.sanitizeInput(cars.wing), + mirror: common.sanitizeInput(cars.mirror), + neon: common.sanitizeInput(cars.neon), + trunk: common.sanitizeInput(cars.trunk), + plate: common.sanitizeInput(cars.plate), + plateColor: common.sanitizeInput(cars.plateColor), + plateNumber: common.sanitizeInput(cars.plateNumber), + ghostLevel: common.sanitizeInput(cars.ghostLevel), } } @@ -205,9 +207,9 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ // Ghost Crown update data dataCrown = { carId: carId, - playedAt: body.playedAt || undefined, - tunePower: body.car?.tunePower || undefined, - tuneHandling: body.car?.tuneHandling || undefined, + playedAt: common.sanitizeInput(body.playedAt), + tunePower: common.sanitizeInput(body.car?.tunePower), + tuneHandling: common.sanitizeInput(body.car?.tuneHandling), } // Get the area id and ramp id diff --git a/src/util/games/story.ts b/src/util/games/story.ts index df6688c..ec2ed05 100644 --- a/src/util/games/story.ts +++ b/src/util/games/story.ts @@ -23,12 +23,12 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c { // Story update data let data : any = { - stClearDivCount: storyResult.stClearDivCount || undefined, - stPlayCount: storyResult.stPlayCount || undefined, - stClearCount: storyResult.stClearCount || undefined, - stConsecutiveWins: storyResult.stConsecutiveWins || undefined, - tuningPoints: storyResult.tuningPoint || 0, - stCompleted100Episodes: storyResult.stCompleted_100Episodes || undefined, + stClearDivCount: common.sanitizeInput(storyResult.stClearDivCount), + stPlayCount: common.sanitizeInput(storyResult.stPlayCount), + stClearCount: common.sanitizeInput(storyResult.stClearCount), + stConsecutiveWins: common.sanitizeInput(storyResult.stConsecutiveWins), + tuningPoints: common.sanitizeInput(storyResult.tuningPoint), + stCompleted100Episodes: common.sanitizeInput(storyResult.stCompleted_100Episodes), } // If the current consecutive wins is greater than the previous max @@ -53,8 +53,7 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c } // Check if clearBits is not null, and not lose the story - if (storyResult.stClearBits !== null && storyResult.stClearBits !== undefined - && data.stLoseBits === 0) + if (common.sanitizeInput(storyResult.stClearBits) && data.stLoseBits === 0) { data.stClearBits = storyResult.stClearBits; }