From a014d3190b6e251fa691c5e154ca4a4e82999e0b Mon Sep 17 00:00:00 2001 From: devcayed Date: Wed, 28 Feb 2024 16:20:49 +0100 Subject: [PATCH] feat: endpoint for all users who created quotes --- server/src/elysia/plugins/DiscordPlugin.ts | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/server/src/elysia/plugins/DiscordPlugin.ts b/server/src/elysia/plugins/DiscordPlugin.ts index c4da620..eb3f975 100644 --- a/server/src/elysia/plugins/DiscordPlugin.ts +++ b/server/src/elysia/plugins/DiscordPlugin.ts @@ -1,11 +1,14 @@ import { Elysia, t } from 'elysia' import { getUserById } from '../../discord/Client' -import { discordClientDecorator } from '../Setup' +import { databaseDecorator, discordClientDecorator } from '../Setup' +import { Quote } from '../../common/Quote' const discordPlugin = new Elysia({ name: 'Discord' }) + .use(databaseDecorator) .use(discordClientDecorator) .group('/discord', (app) => - app.get('/:id', async ({ set, discordClient, params: { id } }) => { + app + .get('/:id', async ({ set, discordClient, params: { id } }) => { const user = await getUserById(discordClient, id) if (!user) { @@ -14,13 +17,22 @@ const discordPlugin = new Elysia({ name: 'Discord' }) } return user - }, - { + }, { params: t.Object({ id: t.String(), }), - }, - ), + }) + .get('/creators', async ({ database, discordClient }) => + await Promise.all(Array.from(new Set((await database.all('quote')).map(quote => quote.creator))) + .map(async creator => { + const user = await getUserById(discordClient, creator) + if (!user) { + return + } + + return user + })), + ), ) export { discordPlugin }