feat: added error messages

This commit is contained in:
Junseo Park 2021-02-22 21:16:14 +09:00
parent 516a53399b
commit 176e7274f2
3 changed files with 13 additions and 4 deletions

View File

@ -28,7 +28,9 @@ const BotInfo = nc<ApiRequest, NextApiResponse>()
if(validated.id !== req.query.id) return ResponseWrapper(res, { code: 400, errors: ['요청 주소와 Body의 정보가 다릅니다.'] })
const result = await put.submitBot(user, validated)
if(result === 1) return ResponseWrapper(res, { code: 403, message: '이미 대기중인 봇이 있습니다.', errors: ['한 번에 최대 2개의 봇까지만 신청하실 수 있습니다.\n다른 봇들의 심사가 완료된 뒤에 신청해주세요.'] })
else if(result === 2) return ResponseWrapper(res, { code: 406, message: '해당 봇은 이미 심사중입니다.', errors: ['해당 아이디의 봇은 이미 심사중입니다. 본인 소유의 봇이고 신청하신 적이 없으시다면 문의해주세요.'] })
else if(result === 2) return ResponseWrapper(res, { code: 406, message: '해당 봇은 이미 심사중이거나 이미 등록되어있습니다.', errors: ['해당 아이디의 봇은 이미 심사중이거나 등록되어있습니다. 본인 소유의 봇이고 신청하신 적이 없으시다면 문의해주세요.'] })
else if(result === 3) return ResponseWrapper(res, { code: 404, message: '올바르지 않은 봇 아이디입니다.', errors: ['해당 아이디의 봇은 존재하지 않습니다. 다시 확인해주세요.'] })
else if(result === 4) return ResponseWrapper(res, { code: 403, message: '디스코드 서버에 참가해주세요.' , errors: ['봇 신청하시기 위해서는 공식 디스코드 서버에 참가해주셔야합니다.'] })
return ResponseWrapper(res, { code: 200, data: result })
})
.patch(async (req, res) => {

View File

@ -7,5 +7,5 @@ DiscordBot.on('ready', () => console.log('I\'m Ready'))
DiscordBot.login(process.env.DISCORD_TOKEN)
const getMainGuild = DiscordBot.guilds.cache.get(guildID)
const getMainGuild = () => DiscordBot.guilds.cache.get(guildID)
export { DiscordBot, getMainGuild }

View File

@ -9,7 +9,7 @@ import { Bot, User, ListType, BotList, TokenRegister, BotFlags, DiscordUserFlags
import { categories } from './Constants'
import knex from './Knex'
import DiscordBot from './DiscordBot'
import { DiscordBot, getMainGuild } from './DiscordBot'
import { sign, verify } from './Jwt'
import { serialize } from './Tools'
import { AddBotSubmit } from './Yup'
@ -181,6 +181,8 @@ async function getBotSubmits(id: string) {
/**
* @returns 1 - Has pending Bots
* @returns 2 - Already submitted ID
* @returns 3 - Bot User does not exists
* @returns 4 - Discord not Joined
* @returns obj - Success
*/
async function submitBot(id: string, data: AddBotSubmit):Promise<number|SubmittedBot> {
@ -189,7 +191,12 @@ async function submitBot(id: string, data: AddBotSubmit):Promise<number|Submitte
const botId = data.id
const date = Math.round(+new Date()/1000)
const sameID = await knex('submitted').select(['id']).where({ id: botId, state: 0 })
if(sameID.length !== 0) return 2
const bot = await get.bot.load(data.id)
if(sameID.length !== 0 || bot) return 2
const user = await get.discord.user.load(data.id)
if(!user) return 3
const member = await getMainGuild().members.fetch(id).then(() => true).catch(() => false)
if(!member) return 4
await knex('submitted').insert({
id: botId,
date: date,