Skip to content

Commit

Permalink
Reuse code
Browse files Browse the repository at this point in the history
  • Loading branch information
runely committed Jun 14, 2022
1 parent 6db7348 commit aac7bc9
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/mocks/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ import { rest } from 'msw'
import { API } from '../config'
import { add, get, put, remove } from './mock-data'
import { getRandomHex, getRandomNumber } from './lib/helpers'
import { getSearchParams } from '../lib/get-search-params'

import _apikeys from './data/apikeys.json'

const getReqSearchParams = req => {
const searchParams = new URLSearchParams(req.url.search)
const params = {}
for (const [key, value] of searchParams.entries()) {
params[key] = value
}
return params
}

const getTop = (req, defaultTop = 25) => {
const params = getReqSearchParams(req)
const params = getSearchParams(req)
const top = typeof params.top !== 'undefined' && Number.parseInt(params.top, 10)

if (Number.isInteger(top)) return top
Expand Down Expand Up @@ -87,7 +79,7 @@ export const handlers = [
)
}

const { fullitem } = getReqSearchParams(req)
const { fullitem } = getSearchParams(req)
const copyApiKey = apiKeys.data.length > 0 ? apiKeys.data[0] : _apikeys[0]
const newApiKey = JSON.parse(JSON.stringify(copyApiKey))

Expand Down

1 comment on commit aac7bc9

@vercel
Copy link

@vercel vercel bot commented on aac7bc9 Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

e18-web – ./

e18-web-vtfk.vercel.app
e18-web.vercel.app
e18-web-git-main-vtfk.vercel.app

Please sign in to comment.