From 580d438c3a7222c733662ce92eaea40fb0062cdd Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 8 Aug 2026 05:11:25 +0200 Subject: [PATCH] ToGuildSource -> ToDiscoverableGuild --- src/api/routes/discoverable-guilds.ts | 13 +++--- src/api/routes/stickers/#sticker_id/index.ts | 2 +- src/database/entities/Guild.ts | 42 +++++++++++++------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/api/routes/discoverable-guilds.ts b/src/api/routes/discoverable-guilds.ts index e79db8f15..afe7f84ae 100644 --- a/src/api/routes/discoverable-guilds.ts +++ b/src/api/routes/discoverable-guilds.ts @@ -49,7 +49,7 @@ router.get( where: { id: Not(In(hiddenGuildIds)), discovery_excluded: false, - ...(categories == undefined ? {} : { primary_category_id: categories.toString() }), // TODO: isnt this an array? + ...(categories == undefined ? {} : { primary_category_id: Number(categories as string) }), // TODO: isnt this an array? ...(showAllGuilds ? {} : { features: ArrayContains(["DISCOVERABLE"]) }), }, order: { @@ -64,11 +64,12 @@ router.get( res.send({ total: total, - guilds: guilds.map((g) => ({ - ...g, - discovery_weight: undefined, - discovery_splash: undefined, - })), + // guilds: guilds.map((g) => ({ + // ...g, + // discovery_weight: undefined, + // discovery_splash: undefined, + // })), + guilds: guilds.map((g) => g.toDiscoverableGuild()), offset: Number(offset || Config.get().guild.discovery.offset), limit: Number(limit || configLimit), }); diff --git a/src/api/routes/stickers/#sticker_id/index.ts b/src/api/routes/stickers/#sticker_id/index.ts index 20426086f..ab2b20a96 100644 --- a/src/api/routes/stickers/#sticker_id/index.ts +++ b/src/api/routes/stickers/#sticker_id/index.ts @@ -49,7 +49,7 @@ router.get( async (req: Request, res: Response) => { const { sticker_id } = req.params as { [key: string]: string }; const sticker = await Sticker.findOne({ where: { id: sticker_id }, relations: { guild: true } }); - res.json(await sticker?.guild?.ToGuildSource()); + res.json(await sticker?.guild?.toDiscoverableGuild()); }, ); diff --git a/src/database/entities/Guild.ts b/src/database/entities/Guild.ts index d7a82667c..62df60113 100644 --- a/src/database/entities/Guild.ts +++ b/src/database/entities/Guild.ts @@ -31,7 +31,8 @@ import { Template } from "./Template"; import { User } from "./User"; import { VoiceState } from "./VoiceState"; import { Webhook } from "./Webhook"; -import { IntegrationGuild } from "@spacebar/schemas"; +import { DiscoverableGuild, IntegrationGuild } from "@spacebar/schemas"; +import { Categories } from "@spacebar/database"; // TODO: application_command_count, application_command_counts: {1: 0, 2: 0, 3: 0} // TODO: guild_scheduled_events // TODO: stage_instances @@ -305,42 +306,53 @@ export class Guild extends BaseClass { @Column({ default: false }) discovery_excluded: boolean = false; - async ToGuildSource() { + async toDiscoverableGuild(): Promise { if (!this.features.includes("DISCOVERABLE")) { return null; } + return { id: this.id, name: this.name, - icon: this.icon, - description: this.description, - banner: this.banner, - splash: this.splash, - discovery_splash: this.discovery_splash, + icon: this.icon ?? null, + description: this.description ?? null, + banner: this.banner ?? null, + splash: this.splash ?? null, + discovery_splash: this.discovery_splash ?? null, features: this.features, vanity_url_code: null, preferred_locale: this.preferred_locale || "en", - premium_subscription_count: this.premium_subscription_count, - approximate_member_count: await Member.countBy({ + premium_subscription_count: this.premium_subscription_count ?? 0, + approximate_member_count: this.member_count ?? 1, + /*await Member.countBy({ guild_id: this.id, - }), - approximate_presence_count: await Member.countBy({ + }),*/ + approximate_presence_count: this.presence_count ?? 0, + /* await Member.countBy({ guild_id: this.id, user: { sessions: { status: "online", }, }, - }), - emojis: this.emojis ?? undefined, + }),*/ + emojis: this.emojis.map((e) => e.toJSON()) ?? undefined, emoji_count: this.emojis ? this.emojis.length : undefined, - stickers: this.stickers ?? undefined, + stickers: this.stickers.map((s) => s.toJSON()) ?? undefined, sticker_count: this.stickers ? this.stickers.length : undefined, auto_removed: false, - primary_category_id: this.primary_category_id, + primary_category_id: this.primary_category_id!, keywords: [], is_published: false, reasons_to_join: [], + created_at: new Date(Snowflake.deconstruct(this.id).timestamp).toISOString(), // TODO: make column + primary_category: ( + await Categories.findOneOrFail({ + where: { + id: this.primary_category_id!, + }, + }) + ).toJSON(), }; }