mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-17 09:23:07 +02:00
Add logout & tags endpoints
This commit is contained in:
parent
cc97a58165
commit
08e757febf
@ -13,6 +13,7 @@ log:
|
||||
panel: 'a panel'
|
||||
question: 'a question'
|
||||
settings: 'the settings'
|
||||
tag: 'a tag'
|
||||
title:
|
||||
joined: '{targetType} {verb}'
|
||||
target:
|
||||
@ -20,6 +21,7 @@ log:
|
||||
panel: 'Panel'
|
||||
question: 'Question'
|
||||
settings: 'Settings'
|
||||
tag: 'Tag'
|
||||
verb:
|
||||
create: 'created'
|
||||
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.');
|
||||
},
|
||||
});
|
@ -19,4 +19,6 @@ logs:
|
||||
directory: ./logs
|
||||
enabled: true
|
||||
keepFor: 30 # days
|
||||
level: info
|
||||
level: info
|
||||
overrides:
|
||||
disableArchives: false
|
Loading…
Reference in New Issue
Block a user