Skip to content

Commit

Permalink
fix(api): use more appropriate status code
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Apr 25, 2024
1 parent 130f5dc commit 8818bf6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports.delete = fastify => ({
const guild = client.guilds.cache.get(req.params.guild);
const categoryId = Number(req.params.category);
const original = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } });
if (!original || original.guildId !== guild.id) return res.status(404).send(new Error('Not Found'));
if (!original || original.guildId !== guild.id) return res.status(400).send(new Error('Bad Request'));
const category = await client.prisma.category.delete({ where: { id: categoryId } });

await updateStaffRoles(guild);
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports.get = fastify => ({
where: { id: categoryId },
});

if (!category || category.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
if (!category || category.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));

return category;
},
Expand Down Expand Up @@ -118,7 +118,7 @@ module.exports.patch = fastify => ({
where: { id: categoryId },
});

if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
if (!original || original.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));

if (data.hasOwnProperty('id')) delete data.id;
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports.delete = fastify => ({
const questionId = req.params.question;
const original = questionId && await client.prisma.question.findUnique({ where: { id: questionId } });
const category = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } });
if (original?.categoryId !== categoryId || category.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
if (original?.categoryId !== categoryId || category.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));
const question = await client.prisma.question.delete({ where: { id: questionId } });

logAdminEvent(client, {
Expand Down
6 changes: 3 additions & 3 deletions src/routes/api/admin/guilds/[guild]/tags/[tag].js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports.delete = fastify => ({
const guildId = req.params.guild;
const tagId = Number(req.params.tag);
const original = tagId && await client.prisma.tag.findUnique({ where: { id: tagId } });
if (original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
if (original.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));
const tag = await client.prisma.tag.delete({ where: { id: tagId } });

const cacheKey = `cache/guild-tags:${guildId}`;
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports.get = fastify => ({
const tagId = Number(req.params.tag);
const tag = await client.prisma.tag.findUnique({ where: { id: tagId } });

if (!tag || tag.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
if (!tag || tag.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));

return tag;
},
Expand All @@ -64,7 +64,7 @@ module.exports.patch = fastify => ({

const original = req.params.tag && await client.prisma.tag.findUnique({ where: { id: tagId } });

if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
if (!original || original.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));

if (data.hasOwnProperty('id')) delete data.id;
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
Expand Down

0 comments on commit 8818bf6

Please sign in to comment.