Skip to content

Commit

Permalink
fix: fix not being able to delete hubs
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Nov 18, 2024
1 parent 0056b4b commit 7968f46
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/commands/slash/Main/hub/delete.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { emojis } from '#utils/Constants.js';
import { RegisterInteractionHandler } from '#main/decorators/RegisterInteractionHandler.js';
import { HubService } from '#main/services/HubService.js';
import { setComponentExpiry } from '#utils/ComponentUtils.js';
import { emojis } from '#utils/Constants.js';
import { CustomID } from '#utils/CustomID.js';
import db from '#utils/Db.js';
import { InfoEmbed } from '#utils/EmbedUtils.js';
import { deleteHubs } from '#utils/hub/utils.js';
import { t } from '#utils/Locale.js';
import {
ActionRowBuilder,
Expand Down Expand Up @@ -96,8 +96,11 @@ export default class Delete extends HubCommand {

await interaction.update({ embeds: [embed], components: [] });

const hubInDb = await db.hub.findFirst({ where: { id: hubId, ownerId: interaction.user.id } });
if (!hubInDb) {
const hubService = new HubService(db);
const hubInDb = await hubService.fetchHub(hubId);

// only the owner can delete the hub
if (hubInDb?.ownerId !== interaction.user.id) {
const infoEmbed = new InfoEmbed().setDescription(
t('hub.notFound', locale, { emoji: emojis.no }),
);
Expand All @@ -106,10 +109,12 @@ export default class Delete extends HubCommand {
return;
}

await deleteHubs([hubInDb.id]);
// Delete the hub and all related data
await hubService.deleteHub(hubInDb.id);

await interaction.editReply({
content: t('hub.delete.success', locale, { emoji: emojis.tick, hub: hubInDb.name }),
embeds: [],
});
}
}

0 comments on commit 7968f46

Please sign in to comment.