diff --git a/src/server/api/routers/card.ts b/src/server/api/routers/card.ts index 5258eeed..8bca36d1 100644 --- a/src/server/api/routers/card.ts +++ b/src/server/api/routers/card.ts @@ -214,9 +214,10 @@ export const cardRouter = createTRPCRouter({ if (!newList) return; - if (!newIndex) { - const lastCardIndex = newList.cards[0]?.index; - newIndex = lastCardIndex ? lastCardIndex + 1 : 0; + if (newIndex === undefined) { + const lastCardIndex = newList.cards.length ? newList.cards[0]?.index : undefined; + + newIndex = lastCardIndex !== undefined ? lastCardIndex + 1 : 0; } if (!currentList?.id || !newList?.id) return;