From aad351c6ddf03c03b7b190249f89241e89a49af9 Mon Sep 17 00:00:00 2001 From: dev-737 <73829355+dev-737@users.noreply.github.com> Date: Sun, 20 Aug 2023 10:02:48 +0530 Subject: [PATCH] refactor(badge): fix parameter types --- src/Commands/Staff/badge.ts | 8 ++------ src/Scripts/badge/add.ts | 10 +++++----- src/Scripts/badge/list.ts | 6 +++--- src/Scripts/badge/remove.ts | 8 ++++---- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Commands/Staff/badge.ts b/src/Commands/Staff/badge.ts index d7ba62e7..e0e69008 100644 --- a/src/Commands/Staff/badge.ts +++ b/src/Commands/Staff/badge.ts @@ -1,5 +1,4 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; -import { getDb } from '../../Utils/functions/utils'; export default { staff: true, @@ -69,14 +68,11 @@ export default { const user = interaction.options.getUser('user'); const badge = interaction.options.getString('badge'); - const database = getDb(); - const userBadges = database?.userBadges; - if (subcommand === 'list') { - require('../../Scripts/badge/list').execute(interaction, userBadges, user); + require('../../Scripts/badge/list').execute(interaction, user); } else { - require(`../../Scripts/badge/${subcommand}`).execute(interaction, userBadges, user, badge); + require(`../../Scripts/badge/${subcommand}`).execute(interaction, user, badge); } }, }; diff --git a/src/Scripts/badge/add.ts b/src/Scripts/badge/add.ts index 289b5a95..c9deca41 100644 --- a/src/Scripts/badge/add.ts +++ b/src/Scripts/badge/add.ts @@ -1,14 +1,14 @@ -import { Prisma } from '@prisma/client'; import { ChatInputCommandInteraction, User } from 'discord.js'; +import { getDb } from '../../Utils/functions/utils'; module.exports = { async execute( interaction: ChatInputCommandInteraction, - dbCollection: Prisma.userBadgesDelegate, user: User, badge: string, ) { - const userInCollection = await dbCollection.findFirst({ where: { userId: user.id } }); + const db = getDb(); + const userInCollection = await db.userBadges.findFirst({ where: { userId: user.id } }); if (userInCollection) { const userBadges = userInCollection.badges; @@ -18,13 +18,13 @@ module.exports = { return; } else { - await dbCollection.update({ where: { userId: user.id }, data: { badges: [...userBadges, badge] } }); + await db.userBadges.update({ where: { userId: user.id }, data: { badges: [...userBadges, badge] } }); await interaction.reply(`Badge \`${badge}\` added to ${user.username}.`); return; } } else { - await dbCollection.create({ data: { userId: user.id, badges: [badge] } }); + await db.userBadges.create({ data: { userId: user.id, badges: [badge] } }); await interaction.reply(`Badge \`${badge}\` added to ${user.username}.`); return; } diff --git a/src/Scripts/badge/list.ts b/src/Scripts/badge/list.ts index 8bd7741d..c303757f 100644 --- a/src/Scripts/badge/list.ts +++ b/src/Scripts/badge/list.ts @@ -1,13 +1,13 @@ -import { Prisma } from '@prisma/client'; import { ChatInputCommandInteraction, User } from 'discord.js'; +import { getDb } from '../../Utils/functions/utils'; export = { async execute( interaction: ChatInputCommandInteraction, - dbCollection: Prisma.userBadgesDelegate, user: User, ) { - const userInCollection = await dbCollection.findFirst({ where: { userId: user.id } }); + const db = getDb(); + const userInCollection = await db.userBadges.findFirst({ where: { userId: user.id } }); if (!userInCollection) { await interaction.reply(`User ${user.username} doesn't have any badges!`); } diff --git a/src/Scripts/badge/remove.ts b/src/Scripts/badge/remove.ts index 1f7054c0..a435d4b0 100644 --- a/src/Scripts/badge/remove.ts +++ b/src/Scripts/badge/remove.ts @@ -1,21 +1,21 @@ -import { Prisma } from '@prisma/client'; import { ChatInputCommandInteraction, User } from 'discord.js'; +import { getDb } from '../../Utils/functions/utils'; export = { async execute( interaction: ChatInputCommandInteraction, - dbCollection: Prisma.userBadgesDelegate, user: User, badge: string, ) { - const userInCollection = await dbCollection.findFirst({ where: { userId: user.id } }); + const db = getDb(); + const userInCollection = await db.userBadges.findFirst({ where: { userId: user.id } }); if (userInCollection) { const userBadges = userInCollection.badges; if (userBadges.includes(badge)) { userBadges.splice(userBadges.indexOf(badge), 1); - await dbCollection.update({ where: { userId: user.id }, data: { badges: userBadges } }); + await db.userBadges.update({ where: { userId: user.id }, data: { badges: userBadges } }); await interaction.reply(`Removed badge \`${badge}\` from user ${user.username}.`); } else {