From 47fc7bde4333c7e5533e7b4d4015d1a89a199d07 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 25 Jun 2023 13:39:42 +0100 Subject: [PATCH] fix: editing question answers in a category with `customTopic` set --- src/modals/questions.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/modals/questions.js b/src/modals/questions.js index 6874783..f74c620 100644 --- a/src/modals/questions.js +++ b/src/modals/questions.js @@ -27,12 +27,11 @@ module.exports = class QuestionsModal extends Modal { if (id.edit) { await interaction.deferReply({ ephemeral: true }); + const { category } = await client.prisma.ticket.findUnique({ select: { category: { select: { customTopic: true } } }, where: { id: interaction.channel.id }, }); - let topic; - if (category.customTopic) topic = interaction.fields.getTextInputValue(category.customTopic); const select = { createdById: true, guild: { @@ -50,6 +49,14 @@ module.exports = class QuestionsModal extends Modal { select, where: { id: interaction.channel.id }, }); + + let topic; + if (category.customTopic) { + const customTopicAnswer = original.questionAnswers.find(a => a.question.id === category.customTopic); + if (!customTopicAnswer) throw new Error('Custom topic answer not found'); + topic = interaction.fields.getTextInputValue(String(customTopicAnswer.id)); + } + const ticket = await client.prisma.ticket.update({ data: { questionAnswers: { @@ -121,4 +128,4 @@ module.exports = class QuestionsModal extends Modal { }); } } -}; \ No newline at end of file +};