Giving up on encryption

and life
This commit is contained in:
Isaac
2022-07-19 15:57:19 +01:00
parent 28f1e85759
commit 5786c3598d
7 changed files with 95 additions and 121 deletions

View File

@@ -1,10 +1,14 @@
const { logAdminEvent } = require('../../../../../../lib/logging');
const { randomUUID } = require('crypto');
module.exports.delete = fastify => ({
handler: async (req, res) => {
/** @type {import('client')} */
const client = res.context.config.client;
const guildId = req.params.guild;
const categoryId = Number(req.params.category);
const original = req.params.category && await client.prisma.category.findUnique({ where: { id: categoryId } });
if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
const category = await client.prisma.category.delete({ where: { id: categoryId } });
logAdminEvent(client, {
@@ -27,12 +31,13 @@ module.exports.get = fastify => ({
handler: async (req, res) => {
/** @type {import('client')} */
const client = res.context.config.client;
const guildId = req.params.guild;
const categoryId = Number(req.params.category);
const category = await client.prisma.category.findUnique({
include: {
questions: {
select: {
createdAt: true,
// createdAt: true,
id: true,
label: true,
maxLength: true,
@@ -45,9 +50,11 @@ module.exports.get = fastify => ({
},
},
},
where: { id: categoryId },
where: { id: categoryId },
});
if (!category || category.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
return category;
},
onRequest: [fastify.authenticate, fastify.isAdmin],
@@ -57,11 +64,13 @@ module.exports.patch = fastify => ({
handler: async (req, res) => {
/** @type {import('client')} */
const client = res.context.config.client;
const guildId = req.params.guild;
const categoryId = Number(req.params.category);
const guild = client.guilds.cache.get(req.params.guild);
const data = req.body;
const original = req.params.category && await client.prisma.category.findUnique({ where: { id: categoryId } });
if (!original) return res.status(404);
if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
if (data.hasOwnProperty('id')) delete data.id;
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
@@ -70,11 +79,14 @@ module.exports.patch = fastify => ({
data: {
...data,
questions: {
upsert: data.questions?.map(q => ({
create: q,
update: q,
where: { id: q.id },
})),
upsert: data.questions?.map(q => {
if (!q.id) q.id = randomUUID();
return {
create: q,
update: q,
where: { id: q.id },
};
}),
},
},
where: { id: categoryId },

View File

@@ -8,29 +8,27 @@ module.exports.get = fastify => ({
const client = res.context.config.client;
const { categories } = await client.prisma.guild.findUnique({
select: {
categories: {
include: {
questions: {
select: {
createdAt: true,
id: true,
label: true,
maxLength: true,
minLength: true,
order: true,
placeholder: true,
required: true,
style: true,
value: true,
},
},
},
},
},
select: { categories: true },
where: { id: req.params.guild },
});
// include: {
// questions: {
// select: {
// createdAt: true,
// id: true,
// label: true,
// maxLength: true,
// minLength: true,
// order: true,
// placeholder: true,
// required: true,
// style: true,
// value: true,
// },
// },
// },
return categories;
},
onRequest: [fastify.authenticate, fastify.isAdmin],

View File

@@ -0,0 +1,32 @@
module.exports.get = fastify => ({
handler: async (req, res) => {
/** @type {import('client')} */
const client = res.context.config.client;
const id = req.params.guild;
const guild = client.guilds.cache.get(id);
const settings = await client.prisma.guild.findUnique({ where: { id } }) ??
await client.prisma.guild.create({ data: { id } });
const problems = [];
if (settings.logChannel) {
const permissions = guild.members.me.permissionsIn(settings.logChannel);
if (!permissions.has('SendMessages')) {
problems.push({
id: 'logChannelMissingPermission',
permission: 'SendMessages',
});
}
if (!permissions.has('EmbedLinks')) {
problems.push({
id: 'logChannelMissingPermission',
permission: 'EmbedLinks',
});
}
}
return problems;
},
onRequest: [fastify.authenticate, fastify.isAdmin],
});