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) { if (id.edit) {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
const { category } = await client.prisma.ticket.findUnique({ const { category } = await client.prisma.ticket.findUnique({
select: { category: { select: { customTopic: true } } }, select: { category: { select: { customTopic: true } } },
where: { id: interaction.channel.id }, where: { id: interaction.channel.id },
}); });
let topic;
if (category.customTopic) topic = interaction.fields.getTextInputValue(category.customTopic);
const select = { const select = {
createdById: true, createdById: true,
guild: { guild: {
@ -50,6 +49,14 @@ module.exports = class QuestionsModal extends Modal {
select, select,
where: { id: interaction.channel.id }, 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({ const ticket = await client.prisma.ticket.update({
data: { data: {
questionAnswers: { questionAnswers: {