From 69bf8939d5886ed1c3438038855d2d1bcb2380e7 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 28 Feb 2024 20:33:10 +0000 Subject: [PATCH] Add Optional chaining to `registerProduction()` to fix null error relating to crafts without tools --- project/src/helpers/HideoutHelper.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index 559f873f..ce99e96e 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -26,8 +26,8 @@ import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { PlayerService } from "@spt-aki/services/PlayerService"; import { HashUtil } from "@spt-aki/utils/HashUtil"; import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil"; -import { TimeUtil } from "@spt-aki/utils/TimeUtil"; import { JsonUtil } from "@spt-aki/utils/JsonUtil"; +import { TimeUtil } from "@spt-aki/utils/TimeUtil"; @injectable() export class HideoutHelper @@ -105,13 +105,13 @@ export class HideoutHelper // Store the tools used for this production, so we can return them later const bodyAsSingle = body as IHideoutSingleProductionStartRequestData; - if (bodyAsSingle && bodyAsSingle.tools.length > 0) + if (bodyAsSingle && bodyAsSingle.tools?.length > 0) { production.sptRequiredTools = []; for (const tool of bodyAsSingle.tools) { - const toolItem = this.jsonUtil.clone(pmcData.Inventory.items.find(x => x._id === tool.id)); + const toolItem = this.jsonUtil.clone(pmcData.Inventory.items.find((x) => x._id === tool.id)); // Make sure we only return as many as we took if (!toolItem.upd) @@ -123,7 +123,7 @@ export class HideoutHelper production.sptRequiredTools.push({ _id: this.hashUtil.generate(), _tpl: toolItem._tpl, - upd: toolItem.upd + upd: toolItem.upd, }); } }