mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 22:10:24 +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) }
|
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) {
|
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}%`)
|
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=> {
|
res = await Promise.all(res.map(async el=> {
|
||||||
@ -236,6 +244,13 @@ export const get = {
|
|||||||
async (ids: string[]) =>
|
async (ids: string[]) =>
|
||||||
(await Promise.all(ids.map(async (el: string) => await getBotSubmits(el)))).map(row => serialize(row))
|
(await Promise.all(ids.map(async (el: string) => await getBotSubmits(el)))).map(row => serialize(row))
|
||||||
, { cacheMap: new TLRU({ maxStoreSize: 50, maxAgeMs: 60000 }) }),
|
, { 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: {
|
list: {
|
||||||
category: new DataLoader(
|
category: new DataLoader(
|
||||||
async (key: string[]) =>
|
async (key: string[]) =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user