mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
feat: added getBotSubmit function
This commit is contained in:
parent
de21fd393b
commit
f5d6df91db
@ -159,6 +159,14 @@ async function getBotList(type: ListType, page = 1, query?: string):Promise<BotL
|
||||
return { type, data: (await Promise.all(res.map(async el => await getBot(el.id)))).map(r=> ({...r})), currentPage: page, totalPage: Math.ceil(Number(count) / 16) }
|
||||
}
|
||||
|
||||
async function getBotSubmit(id: string, date: string) {
|
||||
const res = await knex('submitted').select(['id', 'date', 'category', 'lib', 'prefix', 'intro', 'desc', 'url', 'web', 'git', 'discord', 'state', 'owners', 'reason']).where({ id, date })
|
||||
if(res.length === 0) return null
|
||||
res[0].category = JSON.parse(res[0].category)
|
||||
res[0].owners = await Promise.all(JSON.parse(res[0].owners).map(async (u: string)=> await get.user.load(u)))
|
||||
return res[0]
|
||||
}
|
||||
|
||||
async function getBotSubmits(id: string) {
|
||||
let res = await knex('submitted').select(['id', 'date', 'category', 'lib', 'prefix', 'intro', 'desc', 'url', 'web', 'git', 'discord', 'state', 'owners', 'reason']).orderBy('date', 'desc').where('owners', 'LIKE', `%${id}%`)
|
||||
res = await Promise.all(res.map(async el=> {
|
||||
@ -236,6 +244,13 @@ export const get = {
|
||||
async (ids: string[]) =>
|
||||
(await Promise.all(ids.map(async (el: string) => await getBotSubmits(el)))).map(row => serialize(row))
|
||||
, { cacheMap: new TLRU({ maxStoreSize: 50, maxAgeMs: 60000 }) }),
|
||||
botSubmit: new DataLoader(
|
||||
async (key: string[]) =>
|
||||
(await Promise.all(key.map(async (el: string) => {
|
||||
const json = JSON.parse(el)
|
||||
return await getBotSubmit(json.id, json.date)
|
||||
})))
|
||||
, { cacheMap: new TLRU({ maxStoreSize: 50, maxAgeMs: 60000 }) }),
|
||||
list: {
|
||||
category: new DataLoader(
|
||||
async (key: string[]) =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user