mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-06 10:11:27 +03:00
feat(api): privilege levels
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const { getPrivilegeLevel } = require('../../../../lib/users');
|
||||
const { iconURL } = require('../../../../lib/misc');
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
@@ -9,8 +10,9 @@ module.exports.get = fastify => ({
|
||||
id: guild.id,
|
||||
logo: iconURL(guild),
|
||||
name: guild.name,
|
||||
privilegeLevel: await getPrivilegeLevel(await guild.members.fetch(req.user.id)),
|
||||
});
|
||||
},
|
||||
onRequest: [fastify.authenticate],
|
||||
onRequest: [fastify.authenticate, fastify.isMember],
|
||||
});
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
const { getPrivilegeLevel } = require('../../../lib/users');
|
||||
const { iconURL } = require('../../../lib/misc');
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
@@ -5,13 +6,19 @@ module.exports.get = fastify => ({
|
||||
const { client } = req.routeOptions.config;
|
||||
const guilds = await (await fetch('https://discordapp.com/api/users/@me/guilds', { headers: { 'Authorization': `Bearer ${req.user.accessToken}` } })).json();
|
||||
res.send(
|
||||
guilds
|
||||
.filter(guild => client.guilds.cache.has(guild.id))
|
||||
.map(guild => ({
|
||||
id: guild.id,
|
||||
logo: iconURL(client.guilds.cache.get(guild.id)),
|
||||
name: guild.name,
|
||||
})),
|
||||
await Promise.all(
|
||||
guilds
|
||||
.filter(partialGuild => client.guilds.cache.has(partialGuild.id))
|
||||
.map(async partialGuild => {
|
||||
const guild = client.guilds.cache.get(partialGuild.id);
|
||||
return {
|
||||
id: guild.id,
|
||||
logo: iconURL(guild),
|
||||
name: guild.name,
|
||||
privilegeLevel: await getPrivilegeLevel(await guild.members.fetch(req.user.id)),
|
||||
};
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
onRequest: [fastify.authenticate],
|
||||
|
Reference in New Issue
Block a user