Skip to content

Commit

Permalink
feat: endpoint for all users who created quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
devcayed committed Feb 28, 2024
1 parent 220e565 commit a014d31
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions server/src/elysia/plugins/DiscordPlugin.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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>('quote')).map(quote => quote.creator)))
.map(async creator => {
const user = await getUserById(discordClient, creator)
if (!user) {
return
}

return user
})),
),
)

export { discordPlugin }

0 comments on commit a014d31

Please sign in to comment.