Fix createMagazineTemplate failing when no userbuilds.magazineBuilds array exists

This commit is contained in:
Dev 2024-01-11 11:53:19 +00:00
parent 9623bd5203
commit 3b255f3ce4

View File

@ -193,6 +193,9 @@ export class BuildController
this.logger.error(`Unable to delete preset, cannot find ${id} in weapon, equipment or magazine presets`); this.logger.error(`Unable to delete preset, cannot find ${id} in weapon, equipment or magazine presets`);
} }
/**
* Handle client/builds/magazine/save
*/
public createMagazineTemplate(sessionId: string, request: ISetMagazineRequest): void public createMagazineTemplate(sessionId: string, request: ISetMagazineRequest): void
{ {
const result: IMagazineBuild = { const result: IMagazineBuild = {
@ -206,6 +209,11 @@ export class BuildController
const profile = this.profileHelper.getFullProfile(sessionId); const profile = this.profileHelper.getFullProfile(sessionId);
if (!profile.userbuilds.magazineBuilds)
{
profile.userbuilds.magazineBuilds = [];
}
const existingArrayId = profile.userbuilds.magazineBuilds.findIndex(item => item.Name === request.Name); const existingArrayId = profile.userbuilds.magazineBuilds.findIndex(item => item.Name === request.Name);
if (existingArrayId === -1) if (existingArrayId === -1)