fix: editing question answers in a category with customTopic set

This commit is contained in:
Isaac 2023-06-25 13:39:42 +01:00
parent 8971c0ad13
commit 47fc7bde43
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33

View File

@ -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 {
});
}
}
};
};