mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-17 17:23:08 +02:00
Add logout & tags endpoints
This commit is contained in:
parent
cc97a58165
commit
08e757febf
@ -13,6 +13,7 @@ log:
|
|||||||
panel: 'a panel'
|
panel: 'a panel'
|
||||||
question: 'a question'
|
question: 'a question'
|
||||||
settings: 'the settings'
|
settings: 'the settings'
|
||||||
|
tag: 'a tag'
|
||||||
title:
|
title:
|
||||||
joined: '{targetType} {verb}'
|
joined: '{targetType} {verb}'
|
||||||
target:
|
target:
|
||||||
@ -20,6 +21,7 @@ log:
|
|||||||
panel: 'Panel'
|
panel: 'Panel'
|
||||||
question: 'Question'
|
question: 'Question'
|
||||||
settings: 'Settings'
|
settings: 'Settings'
|
||||||
|
tag: 'Tag'
|
||||||
verb:
|
verb:
|
||||||
create: 'created'
|
create: 'created'
|
||||||
delete: 'deleted'
|
delete: 'deleted'
|
||||||
|
42
src/routes/api/admin/guilds/[guild]/tags/[tag].js
Normal file
42
src/routes/api/admin/guilds/[guild]/tags/[tag].js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
const { logAdminEvent } = require('../../../../../../lib/logging');
|
||||||
|
|
||||||
|
module.exports.delete = fastify => ({
|
||||||
|
handler: async (req, res) => {
|
||||||
|
/** @type {import('client')} */
|
||||||
|
const client = res.context.config.client;
|
||||||
|
const guildId = req.params.guild;
|
||||||
|
const tagId = 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'));
|
||||||
|
const tag = await client.prisma.tag.delete({ where: { id: tagId } });
|
||||||
|
|
||||||
|
logAdminEvent(client, {
|
||||||
|
action: 'delete',
|
||||||
|
guildId: req.params.guild,
|
||||||
|
target: {
|
||||||
|
id: tag.id,
|
||||||
|
name: tag.name,
|
||||||
|
type: 'tag',
|
||||||
|
},
|
||||||
|
userId: req.user.payload.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
},
|
||||||
|
onRequest: [fastify.authenticate, fastify.isAdmin],
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports.get = fastify => ({
|
||||||
|
handler: async (req, res) => {
|
||||||
|
/** @type {import('client')} */
|
||||||
|
const client = res.context.config.client;
|
||||||
|
const guildId = req.params.guild;
|
||||||
|
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'));
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
},
|
||||||
|
onRequest: [fastify.authenticate, fastify.isAdmin],
|
||||||
|
});
|
46
src/routes/api/admin/guilds/[guild]/tags/index.js
Normal file
46
src/routes/api/admin/guilds/[guild]/tags/index.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
const { logAdminEvent } = require('../../../../../../lib/logging');
|
||||||
|
|
||||||
|
module.exports.get = fastify => ({
|
||||||
|
handler: async (req, res) => {
|
||||||
|
/** @type {import('client')} */
|
||||||
|
const client = res.context.config.client;
|
||||||
|
|
||||||
|
const { tags } = await client.prisma.guild.findUnique({
|
||||||
|
select: { tags: true },
|
||||||
|
where: { id: req.params.guild },
|
||||||
|
});
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
},
|
||||||
|
onRequest: [fastify.authenticate, fastify.isAdmin],
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.post = fastify => ({
|
||||||
|
handler: async (req, res) => {
|
||||||
|
/** @type {import('client')} */
|
||||||
|
const client = res.context.config.client;
|
||||||
|
const guild = client.guilds.cache.get(req.params.guild);
|
||||||
|
const data = req.body;
|
||||||
|
const tag = await client.prisma.tag.create({
|
||||||
|
data: {
|
||||||
|
guild: { connect: { id: guild.id } },
|
||||||
|
...data,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
logAdminEvent(client, {
|
||||||
|
action: 'create',
|
||||||
|
guildId: guild.id,
|
||||||
|
target: {
|
||||||
|
id: tag.id,
|
||||||
|
name: tag.name,
|
||||||
|
type: 'tag',
|
||||||
|
},
|
||||||
|
userId: req.user.payload.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
},
|
||||||
|
onRequest: [fastify.authenticate, fastify.isAdmin],
|
||||||
|
});
|
7
src/routes/auth/logout.js
Normal file
7
src/routes/auth/logout.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module.exports.get = () => ({
|
||||||
|
handler: async function (req, res) { // must NOT use arrow function syntax
|
||||||
|
res
|
||||||
|
.clearCookie('token', '/')
|
||||||
|
.send('Logged out.');
|
||||||
|
},
|
||||||
|
});
|
@ -20,3 +20,5 @@ logs:
|
|||||||
enabled: true
|
enabled: true
|
||||||
keepFor: 30 # days
|
keepFor: 30 # days
|
||||||
level: info
|
level: info
|
||||||
|
overrides:
|
||||||
|
disableArchives: false
|
Loading…
Reference in New Issue
Block a user