Add creators to the response
This commit is contained in:
3 files changed
+14
-3
No files matched your search
@@ -106,6 +106,7 @@ export const cdnFiles = mysqlTable('cdnfiles', {
|
||||
export const mods = mysqlTable('mods', {
|
||||
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement().notNull(),
|
||||
name: text('name').notNull(),
|
||||
creators: text('creators').default('{}').notNull(),
|
||||
description: text('description').notNull(),
|
||||
downloadCount: bigint('downloadCount', { mode: 'number' })
|
||||
.notNull()
|
||||
|
||||
@@ -2,9 +2,10 @@ import {
|
||||
games,
|
||||
launcherVersionManifest,
|
||||
mods,
|
||||
modVersions
|
||||
modVersions,
|
||||
users
|
||||
} from '../../../lib/tables'
|
||||
import { and, asc, desc, eq } from 'drizzle-orm'
|
||||
import { and, asc, desc, eq, inArray, sql } from 'drizzle-orm'
|
||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
||||
import { Context } from 'elysia'
|
||||
|
||||
@@ -83,6 +84,7 @@ export const handler = async (context: Context) => {
|
||||
.select({
|
||||
id: mods.id,
|
||||
name: mods.name,
|
||||
creators: mods.creators,
|
||||
description: mods.description,
|
||||
downloadCount: mods.downloadCount
|
||||
})
|
||||
@@ -126,10 +128,17 @@ export const handler = async (context: Context) => {
|
||||
|
||||
if (!download || !downloads[download]) return
|
||||
|
||||
const creators = await db
|
||||
.select({ username: users.username })
|
||||
.from(users)
|
||||
.where(inArray(users.id, JSON.parse(v.creators)))
|
||||
.execute()
|
||||
|
||||
return {
|
||||
id: v.id,
|
||||
name: v.name,
|
||||
description: v.description,
|
||||
creators: creators.map(u => u.username),
|
||||
downloads: v.downloadCount,
|
||||
released: vi[vi.length - 1].releaseDate,
|
||||
updated: vi[0].releaseDate,
|
||||
|
||||
Reference in new issue
Block a user