mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
feat: added clean Object
This commit is contained in:
parent
5c596978b7
commit
90c3e57a66
@ -6,7 +6,7 @@ import Link from 'next/link'
|
||||
import { Form, Formik } from 'formik'
|
||||
|
||||
import { get } from '@utils/Query'
|
||||
import { parseCookie, redirectTo } from '@utils/Tools'
|
||||
import { cleanObject, parseCookie, redirectTo } from '@utils/Tools'
|
||||
import { AddBotSubmit, AddBotSubmitSchema } from '@utils/Yup'
|
||||
import { categories, library } from '@utils/Constants'
|
||||
import { ResponseProps, SubmittedBot, User } from '@types'
|
||||
@ -36,7 +36,7 @@ const AddBot:NextPage<AddBotProps> = ({ logged, user, csrfToken }) => {
|
||||
}
|
||||
|
||||
async function submitBot(value: AddBotSubmit) {
|
||||
const res = await Fetch<SubmittedBot>(`/bots/${value.id}`, { method: 'POST', body: JSON.stringify(value), headers: { 'content-type': 'application/json' } })
|
||||
const res = await Fetch<SubmittedBot>(`/bots/${value.id}`, { method: 'POST', body: JSON.stringify(cleanObject<AddBotSubmit>(value)), headers: { 'content-type': 'application/json' } })
|
||||
setData(res)
|
||||
}
|
||||
if(!logged) {
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
import { Readable } from 'stream'
|
||||
import { NextPageContext } from 'next'
|
||||
import cookie from 'cookie'
|
||||
|
||||
import { BotFlags, ImageOptions, UserFlags } from '@types'
|
||||
import { KoreanbotsEndPoints, Oauth } from './Constants'
|
||||
import { NextRouter } from 'next/router'
|
||||
import { IncomingMessage } from 'http'
|
||||
|
||||
export function formatNumber(value: number):string {
|
||||
const suffixes = ['', '만', '억', '조','해']
|
||||
@ -105,4 +103,14 @@ export function redirectTo(router: NextRouter, to: string) {
|
||||
return
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function cleanObject<T extends Record<any, any>>(obj: T): T {
|
||||
for (const propName in obj) {
|
||||
if (obj[propName] !== 0 && !obj[propName]) {
|
||||
delete obj[propName]
|
||||
}
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
export { anchorHeader, twemoji, customEmoji } from './ShowdownExtensions'
|
||||
Loading…
x
Reference in New Issue
Block a user