From 4ef8f0edd0c803a54874242f980324ff7cc75915 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Mon, 12 Aug 2024 16:31:52 +0100 Subject: [PATCH] Remove need for MoonConstants file --- src/commands/304276391837302787/moons/list.ts | 7 ++++--- src/constants/MoonConstants.ts | 3 --- src/database/entities/Moon.ts | 7 +++---- 3 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 src/constants/MoonConstants.ts diff --git a/src/commands/304276391837302787/moons/list.ts b/src/commands/304276391837302787/moons/list.ts index 6339d03..35a14d6 100644 --- a/src/commands/304276391837302787/moons/list.ts +++ b/src/commands/304276391837302787/moons/list.ts @@ -1,20 +1,21 @@ import {ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder} from "discord.js"; import Moon from "../../../database/entities/Moon"; import EmbedColours from "../../../constants/EmbedColours"; -import MoonConstants from "../../../constants/MoonConstants"; export default async function ListMoons(interaction: CommandInteraction) { const user = interaction.options.get("user")?.user ?? interaction.user; const page = interaction.options.get("page")?.value as number ?? 0; - const moons = await Moon.FetchPaginatedMoonsByUserId(user.id, page); + const pageLength = 10; + + const moons = await Moon.FetchPaginatedMoonsByUserId(user.id, pageLength, page); if (!moons || moons[0].length == 0) { await interaction.reply(`${user.username} does not have any moons or page is invalid.`); return; } - const totalPages = Math.ceil(moons[1] / MoonConstants.ListPageLength); + const totalPages = Math.ceil(moons[1] / pageLength); const description = moons[0].flatMap(x => `${x.MoonNumber}. ${x.Description.slice(0, 15)}`); diff --git a/src/constants/MoonConstants.ts b/src/constants/MoonConstants.ts deleted file mode 100644 index 17f2340..0000000 --- a/src/constants/MoonConstants.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default class MoonConstants { - public static readonly ListPageLength = 10; -} diff --git a/src/database/entities/Moon.ts b/src/database/entities/Moon.ts index 02ebd30..b139530 100644 --- a/src/database/entities/Moon.ts +++ b/src/database/entities/Moon.ts @@ -1,7 +1,6 @@ import { Column, Entity } from "typeorm"; import BaseEntity from "../../contracts/BaseEntity"; import AppDataSource from "../dataSources/appDataSource"; -import MoonConstants from "../../constants/MoonConstants"; @Entity() export default class Moon extends BaseEntity { @@ -30,8 +29,8 @@ export default class Moon extends BaseEntity { return all; } - public static async FetchPaginatedMoonsByUserId(userId: string, page: number): Promise<[ Moon[], number ]> { - const rangeStart = page * MoonConstants.ListPageLength; + public static async FetchPaginatedMoonsByUserId(userId: string, pageLength: number, page: number): Promise<[ Moon[], number ]> { + const rangeStart = page * pageLength; const repository = AppDataSource.getRepository(Moon); @@ -39,7 +38,7 @@ export default class Moon extends BaseEntity { where: { UserId: userId }, order: { MoonNumber: "ASC" }, skip: rangeStart, - take: MoonConstants.ListPageLength, + take: pageLength, }); return moons;