Skip to content

Commit

Permalink
Check if attributes are present
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Oct 24, 2024
1 parent 5e49b77 commit 26cecd9
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/storage/loot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 26cecd9

Please sign in to comment.