From c1f8cee19ff5da80bc484301d6c73bb0645303d2 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 28 Dec 2023 12:19:52 +0000 Subject: [PATCH] Fix issues with mag tempalte saving --- project/src/callbacks/BuildsCallbacks.ts | 5 +++-- project/src/controllers/BuildController.ts | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/project/src/callbacks/BuildsCallbacks.ts b/project/src/callbacks/BuildsCallbacks.ts index d1b1f1e8..5ba1a1b9 100644 --- a/project/src/callbacks/BuildsCallbacks.ts +++ b/project/src/callbacks/BuildsCallbacks.ts @@ -2,6 +2,7 @@ import { BuildController } from "@spt-aki/controllers/BuildController"; import { ISetMagazineRequest } from "@spt-aki/models/eft/builds/ISetMagazineRequest"; import { IEmptyRequestData } from "@spt-aki/models/eft/common/IEmptyRequestData"; import { IGetBodyResponseData } from "@spt-aki/models/eft/httpResponse/IGetBodyResponseData"; +import { INullResponseData } from "@spt-aki/models/eft/httpResponse/INullResponseData"; import { IUserBuilds } from "@spt-aki/models/eft/profile/IAkiProfile"; import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil"; import { inject, injectable } from "tsyringe"; @@ -28,11 +29,11 @@ export class BuildsCallbacks * Handle client/builds/magazine/save */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - public createMagazineTemplate(url: string, request: ISetMagazineRequest, sessionID: string): IGetBodyResponseData + public createMagazineTemplate(url: string, request: ISetMagazineRequest, sessionID: string): INullResponseData { this.buildController.createMagazineTemplate(sessionID, request) - return this.httpResponse.emptyResponse(); + return this.httpResponse.nullResponse(); } /** diff --git a/project/src/controllers/BuildController.ts b/project/src/controllers/BuildController.ts index 16293e25..5b620754 100644 --- a/project/src/controllers/BuildController.ts +++ b/project/src/controllers/BuildController.ts @@ -243,6 +243,17 @@ export class BuildController }; const profile = this.profileHelper.getFullProfile(sessionId); - profile.userbuilds.magazineBuilds.push(result); + + const existingArrayId = profile.userbuilds.magazineBuilds.findIndex(item => item.Name === request.Name); + + if (existingArrayId === -1) + { + + profile.userbuilds.magazineBuilds.push(result); + } + else + { + profile.userbuilds.magazineBuilds.splice(existingArrayId, 1, result) + } } }