Merge pull request #1362 from spacebarchat/revert-1361-fix/application-command-index
Revert "fix: no sense it doing it twice when it could be done in one query"
This commit is contained in:
commit
f6fa2d0d07
@ -19,6 +19,7 @@
|
|||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Application, ApplicationCommand, Member, Snowflake } from "@spacebar/util";
|
import { Application, ApplicationCommand, Member, Snowflake } from "@spacebar/util";
|
||||||
|
import { IsNull } from "typeorm";
|
||||||
|
|
||||||
const router = Router({ mergeParams: true });
|
const router = Router({ mergeParams: true });
|
||||||
|
|
||||||
@ -30,7 +31,6 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
applications.push(await Application.findOneOrFail({ where: { id: member.id } }));
|
applications.push(await Application.findOneOrFail({ where: { id: member.id } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const applicationCommands: ApplicationCommand[] = [];
|
|
||||||
const applicationsSendable = [];
|
const applicationsSendable = [];
|
||||||
|
|
||||||
for (const application of applications) {
|
for (const application of applications) {
|
||||||
@ -42,13 +42,19 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
id: application.id,
|
id: application.id,
|
||||||
name: application.name,
|
name: application.name,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
applicationCommands.push(await ApplicationCommand.findOneOrFail({ where: { application_id: application.id } }));
|
const globalApplicationCommands: ApplicationCommand[] = [];
|
||||||
|
const guildApplicationCommands: ApplicationCommand[] = [];
|
||||||
|
|
||||||
|
for (const application of applications) {
|
||||||
|
globalApplicationCommands.push(await ApplicationCommand.findOneOrFail({ where: { application_id: application.id, guild_id: IsNull() } }));
|
||||||
|
guildApplicationCommands.push(await ApplicationCommand.findOneOrFail({ where: { application_id: application.id, guild_id: req.params.guild_id } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const applicationCommandsSendable = [];
|
const applicationCommandsSendable = [];
|
||||||
|
|
||||||
for (const command of applicationCommands) {
|
for (const command of [...globalApplicationCommands, ...guildApplicationCommands]) {
|
||||||
applicationCommandsSendable.push({
|
applicationCommandsSendable.push({
|
||||||
application_id: command.application_id,
|
application_id: command.application_id,
|
||||||
description: command.description,
|
description: command.description,
|
||||||
|
|||||||
Reference in New Issue
Block a user