From ff9c9b1ff26531a341f1df28ca1fddea667c448e Mon Sep 17 00:00:00 2001 From: hanshino Date: Sat, 7 Sep 2024 05:38:39 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3WorldBossControlle?= =?UTF-8?q?r=E4=B8=AD=E7=9A=84lodash=E5=BC=95=E5=85=A5=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正了WorldBossController中的lodash引入問題,添加了isNull方法,以解決totalCost為null時的問題。 --- app/src/controller/application/WorldBossController.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/controller/application/WorldBossController.js b/app/src/controller/application/WorldBossController.js index 98eb8aa..9a75421 100644 --- a/app/src/controller/application/WorldBossController.js +++ b/app/src/controller/application/WorldBossController.js @@ -18,7 +18,7 @@ const { DefaultLogger } = require("../../util/Logger"); const { delay, random } = require("../../util/index"); const LineClient = getClient("line"); const config = require("config"); -const { get, sample, sortBy } = require("lodash"); +const { get, sample, sortBy, isNull } = require("lodash"); const humanNumber = require("human-number"); const { format } = require("util"); const { table, getBorderCharacters } = require("table"); @@ -226,7 +226,7 @@ async function myStatus(context) { const character = makeCharacter(job_key, { level }); // 取得今日已經攻擊的次數 - const [{ totalCost = 0 }, sumLogs, { max: maxDamage = 0 }, { count: attendTimes = 0 }] = + const [costResult, sumLogs, { max: maxDamage = 0 }, { count: attendTimes = 0 }] = await Promise.all([ worldBossEventLogService.getTodayCost(id), worldBossLogModel.getBossLogs(id, { limit: 2 }), @@ -234,6 +234,8 @@ async function myStatus(context) { worldBossLogModel.getUserAttendance(id), ]); + const totalCost = isNull(costResult.totalCost) ? 0 : costResult.totalCost; + const data = { level, expPercentage, From 110fe5dca6c7b434ce7f3cbc97b36537bf34ead0 Mon Sep 17 00:00:00 2001 From: hanshino Date: Sat, 7 Sep 2024 05:42:13 +0000 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3WorldBossControlle?= =?UTF-8?q?r=E4=B8=AD=E7=9A=84lodash=E5=BC=95=E5=85=A5=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正WorldBossController中的lodash引入問題,將get函式改為isNull函式來處理totalCost的判斷,避免出現undefined的情況。 --- app/src/controller/application/WorldBossController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/controller/application/WorldBossController.js b/app/src/controller/application/WorldBossController.js index 9a75421..b37d692 100644 --- a/app/src/controller/application/WorldBossController.js +++ b/app/src/controller/application/WorldBossController.js @@ -639,7 +639,7 @@ async function isUserCanAttack(userId) { // 取得今日紀錄 const result = await worldBossEventLogService.getTodayCost(userId); - const totalCost = parseInt(get(result, "totalCost", 0)); + const totalCost = isNull(result.totalCost) ? 0 : parseInt(result.totalCost); // 如果完全沒有紀錄,代表可以攻擊 if (totalCost === 0) { await redis.set(key, 1, {