From 84e6311a83a6d7dc9fe946b70ecf87bd8993b39b Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Fri, 21 May 2021 22:04:58 +0900 Subject: [PATCH] feat: added approve --- utils/Query.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utils/Query.ts b/utils/Query.ts index fecb4b1..90a43f9 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -382,7 +382,15 @@ async function getBotSubmitList() { } async function denyBotSubmission(id: string, date: number, reason?: string) { - await knex('submitted').update({ state: 2 }).where({ state: 0, id, date, reason: reason || null }) + await knex('submitted').update({ state: 2, reason: reason || null }).where({ state: 0, id, date }) +} + +async function approveBotSubmission(id: string, date: number) { + const data = await knex('submitted').select(['id', 'date', 'category', 'lib', 'prefix', 'intro', 'desc', 'url', 'web', 'git', 'discord', 'state', 'owners', 'reason']).where({ state: 0, id, date }) + if(!data[0]) return false + await knex('submitted').where({ state: 0, id, date }).update({ state: 1 }) + await knex('bots').insert({ id, date, owners: data[0].owners, lib: data[0].lib, prefix: data[0].prefix, intro: data[0].intro, desc: data[0].desc, url: data[0].url, web: data[0].web, git: data[0].git, category: data[0].category, discord: data[0].discord, token: sign({ id }) }) + return true } export const get = { @@ -480,7 +488,8 @@ export const update = { Github, bot: updateBot, botOwners: updateOwner, - denyBotSubmission + denyBotSubmission, + approveBotSubmission } export const put = {