summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorCyberL1 <cyber.hf18@gmail.com>2025-10-20 18:04:28 +0200
committerCyberL1 <cyber.hf18@gmail.com>2025-10-20 18:04:28 +0200
commitf7a64ec7340b4929d91ae9e4f050976a8cc8f4f5 (patch)
treeb37824cc92bb1138e699f062159936897f6f5c2d /src/api
parentMerge pull request #1353 from CyberL1/fix/refereced-messages-deletion (diff)
downloadserver-ts-f7a64ec7340b4929d91ae9e4f050976a8cc8f4f5.tar.xz
fix: remove commands not present in array
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/applications/#application_id/commands/index.ts11
-rw-r--r--src/api/routes/applications/#application_id/guilds/#guild_id/commands/index.ts10
2 files changed, 21 insertions, 0 deletions
diff --git a/src/api/routes/applications/#application_id/commands/index.ts b/src/api/routes/applications/#application_id/commands/index.ts

index a855b15e..86057f59 100644 --- a/src/api/routes/applications/#application_id/commands/index.ts +++ b/src/api/routes/applications/#application_id/commands/index.ts
@@ -20,6 +20,7 @@ import { ApplicationCommandCreateSchema, ApplicationCommandSchema } from "@space import { route } from "@spacebar/api"; import { Request, Response, Router } from "express"; import { Application, ApplicationCommand, FieldErrors, Snowflake } from "@spacebar/util"; +import { IsNull } from "typeorm"; const router = Router({ mergeParams: true }); @@ -110,6 +111,16 @@ router.put( const body = req.body as ApplicationCommandCreateSchema[]; + // Remove commands not present in array + const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: IsNull() } }); + + const commandNamesInArray = body.map((c) => c.name); + const commandsNotInArray = applicationCommands.filter((c) => !commandNamesInArray.includes(c.name)); + + for (const command of commandsNotInArray) { + await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: IsNull(), id: command.id }); + } + for (const command of body) { if (!command.type) { command.type = 1; diff --git a/src/api/routes/applications/#application_id/guilds/#guild_id/commands/index.ts b/src/api/routes/applications/#application_id/guilds/#guild_id/commands/index.ts
index 8e6fb787..111c26f4 100644 --- a/src/api/routes/applications/#application_id/guilds/#guild_id/commands/index.ts +++ b/src/api/routes/applications/#application_id/guilds/#guild_id/commands/index.ts
@@ -147,6 +147,16 @@ router.put( const body = req.body as ApplicationCommandCreateSchema[]; + // Remove commands not present in array + const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id } }); + + const commandNamesInArray = body.map((c) => c.name); + const commandsNotInArray = applicationCommands.filter((c) => !commandNamesInArray.includes(c.name)); + + for (const command of commandsNotInArray) { + await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: req.params.guild_id, id: command.id }); + } + for (const command of body) { if (!command.type) { command.type = 1;