mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-01-11 02:16:26 +02:00
fix(api): use more appropriate status code
This commit is contained in:
parent
130f5dc590
commit
8818bf6d48
@ -9,7 +9,7 @@ module.exports.delete = fastify => ({
|
|||||||
const guild = client.guilds.cache.get(req.params.guild);
|
const guild = client.guilds.cache.get(req.params.guild);
|
||||||
const categoryId = Number(req.params.category);
|
const categoryId = Number(req.params.category);
|
||||||
const original = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } });
|
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 } });
|
const category = await client.prisma.category.delete({ where: { id: categoryId } });
|
||||||
|
|
||||||
await updateStaffRoles(guild);
|
await updateStaffRoles(guild);
|
||||||
@ -58,7 +58,7 @@ module.exports.get = fastify => ({
|
|||||||
where: { id: categoryId },
|
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;
|
return category;
|
||||||
},
|
},
|
||||||
@ -118,7 +118,7 @@ module.exports.patch = fastify => ({
|
|||||||
where: { id: categoryId },
|
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('id')) delete data.id;
|
||||||
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
|
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
|
||||||
|
@ -9,7 +9,7 @@ module.exports.delete = fastify => ({
|
|||||||
const questionId = req.params.question;
|
const questionId = req.params.question;
|
||||||
const original = questionId && await client.prisma.question.findUnique({ where: { id: questionId } });
|
const original = questionId && await client.prisma.question.findUnique({ where: { id: questionId } });
|
||||||
const category = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } });
|
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 } });
|
const question = await client.prisma.question.delete({ where: { id: questionId } });
|
||||||
|
|
||||||
logAdminEvent(client, {
|
logAdminEvent(client, {
|
||||||
|
@ -8,7 +8,7 @@ module.exports.delete = fastify => ({
|
|||||||
const guildId = req.params.guild;
|
const guildId = req.params.guild;
|
||||||
const tagId = Number(req.params.tag);
|
const tagId = Number(req.params.tag);
|
||||||
const original = tagId && await client.prisma.tag.findUnique({ where: { id: tagId } });
|
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 tag = await client.prisma.tag.delete({ where: { id: tagId } });
|
||||||
|
|
||||||
const cacheKey = `cache/guild-tags:${guildId}`;
|
const cacheKey = `cache/guild-tags:${guildId}`;
|
||||||
@ -46,7 +46,7 @@ module.exports.get = fastify => ({
|
|||||||
const tagId = Number(req.params.tag);
|
const tagId = Number(req.params.tag);
|
||||||
const tag = await client.prisma.tag.findUnique({ where: { id: tagId } });
|
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;
|
return tag;
|
||||||
},
|
},
|
||||||
@ -64,7 +64,7 @@ module.exports.patch = fastify => ({
|
|||||||
|
|
||||||
const original = req.params.tag && await client.prisma.tag.findUnique({ where: { id: tagId } });
|
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('id')) delete data.id;
|
||||||
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
|
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
|
||||||
|
Loading…
Reference in New Issue
Block a user