From c1643f45ad435087f128ce107d306e397228150a Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 12 Feb 2025 02:35:08 +0000 Subject: [PATCH] fix: `/move` into new category (fixes #531) --- src/commands/slash/move.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/commands/slash/move.js b/src/commands/slash/move.js index 85baa7f..5b5e83b 100644 --- a/src/commands/slash/move.js +++ b/src/commands/slash/move.js @@ -103,15 +103,25 @@ module.exports = class MoveSlashCommand extends SlashCommand { where: { id: ticket.id }, }); - const $oldCategory = client.tickets.$count.categories[ticket.categoryId]; - const $newCategory = client.tickets.$count.categories[newCategory.id]; + // alias + const $counters = client.tickets.$count.categories; + // make sure new category exist (#531) + $counters[newCategory.id] ??= {}; + + // more specific aliases + const $oldCategory = $counters[ticket.categoryId]; + const $newCategory = $counters[newCategory.id]; + + // decrement old's total and member count $oldCategory.total--; $oldCategory[ticket.createdById]--; + // increment new's totaL count $newCategory.total ||= 0; $newCategory.total++; + // increment new's member count $newCategory[ticket.createdById] ||= 0; $newCategory[ticket.createdById]++;