2
1
mirror of https://github.com/Thream/api.git synced 2024-07-21 03:38:31 +02:00

fix: sort public guilds with descending members count

This commit is contained in:
Divlo 2022-06-29 04:16:48 +00:00
parent 4d565e4f1f
commit 2f78604116
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9

View File

@ -18,7 +18,8 @@ const querySchema = Type.Object({
export type QuerySchemaType = Static<typeof querySchema> export type QuerySchemaType = Static<typeof querySchema>
const getServiceSchema: FastifySchema = { const getServiceSchema: FastifySchema = {
description: 'GET all the public guilds.', description:
'GET all the public guilds (ordered by descending members count).',
tags: ['guilds'] as string[], tags: ['guilds'] as string[],
security: [ security: [
{ {
@ -55,7 +56,11 @@ export const getGuildsPublic: FastifyPluginAsync = async (fastify) => {
} }
const guildsRequest = await prisma.guild.findMany({ const guildsRequest = await prisma.guild.findMany({
...getPaginationOptions(request.query), ...getPaginationOptions(request.query),
orderBy: { createdAt: 'desc' }, orderBy: {
members: {
_count: 'desc'
}
},
...(request.query.search != null && { ...(request.query.search != null && {
where: { where: {
name: { contains: request.query.search } name: { contains: request.query.search }