'use strict' import { getBotsFromStorage, saveBotToStorage } from './bots/storageService' import { WrongInputError, NotFoundError, InternalError } from '../utils/customErrors' import { Request } from 'express' import { Bot } from '../../../schema' /** * Operations on /bots */ export default { /**Returns all bots in store */ async getBots() { try { return await getBotsFromStorage() } catch (error) { throw new NotFoundError(error) } }, /**Creates a new bot in the store. */ async postBot(req: Request) { if (req && req.body && req.body.bot) { const bot: Bot = req.body.bot if (bot && bot.id && bot.version) { try { return await saveBotToStorage(bot) } catch (error) { throw new InternalError(error) } } else { throw new WrongInputError('id or version not found in bot body') } } else { throw new WrongInputError('request body doesnt have parameter bot') } } }