From 8c2b17150bc61a95dfa7ca37edc648c37e4b863f Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 21 Oct 2019 15:24:14 +0300 Subject: [PATCH] api articles typing fix --- pages/api/articles/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pages/api/articles/index.ts b/pages/api/articles/index.ts index 3592a507..9af32d14 100644 --- a/pages/api/articles/index.ts +++ b/pages/api/articles/index.ts @@ -1,10 +1,15 @@ import { findArticles } from '../../../src/server/articles' import { withMiddleware } from '../../../src/middlewares/withMiddleware' +const int = (value: string | string[]) => parseInt(Array.isArray(value) + ? value[0] + : value +) + export default withMiddleware(async (req, res) => { const { query } = req - const page = parseInt(query.page) - const pageSize = parseInt(query.pageSize) + const page = int(query.page) + const pageSize = int(query.pageSize) const data = await findArticles(page, pageSize)