From 26cecd91856c372551d1e4ac144dcf88f9756416 Mon Sep 17 00:00:00 2001 From: holzmaster Date: Fri, 25 Oct 2024 01:34:49 +0200 Subject: [PATCH] Check if attributes are present --- src/storage/loot.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/storage/loot.ts b/src/storage/loot.ts index eb78b442..cde44f9c 100644 --- a/src/storage/loot.ts +++ b/src/storage/loot.ts @@ -249,20 +249,22 @@ export async function transferLootToUser( .selectAll() .execute(); - const newLootAttributes = oldLootAttributes.map(attr => ({ - ...attr, - id: undefined, - lootId: newLoot.id, - })); - - const inserted = await ctx - .insertInto("lootAttribute") - .values(newLootAttributes) - .returningAll() - .execute(); + if (oldLootAttributes.length > 0) { + const newLootAttributes = oldLootAttributes.map(attr => ({ + ...attr, + id: undefined, + lootId: newLoot.id, + })); + + const inserted = await ctx + .insertInto("lootAttribute") + .values(newLootAttributes) + .returningAll() + .execute(); - if (inserted.length !== newLootAttributes.length) { - throw new Error("Not all attributes were inserted"); + if (inserted.length !== newLootAttributes.length) { + throw new Error("Not all attributes were inserted"); + } } return newLoot;