Created
April 1, 2020 01:45
-
-
Save manakuro/0ea3bac444ca671fb5c840b39d3e4247 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const email = (query, params) => { | |
if (!params.email) return query | |
const isValid = isValidEmail(params.email) | |
if (!isValid) throw new Error('Invalid email') | |
return { ...query, ...{ email: params.email } } | |
} | |
const maxAge = (query, params) => { | |
const obj = { maxAge: '' } | |
if (!params.maxAge) obj.maxAge = JSON.parse(localStorage.getItem('defaultMaxAgeLimit') || '') | |
if (params.maxAge && params.maxAge < 25) obj.maxAge = params.maxAge | |
return { ...query, ...obj } | |
} | |
const limit = (query, params) => { | |
if (!params.limit) return query | |
return { ...query, ...{ limit: params.limit } } | |
} | |
const generateQuery = (params) => { | |
let query = {} | |
try { | |
query = email(query, params) | |
query = maxAge(query, params) | |
query = limit(query, params) | |
} catch(err) { | |
// error handing | |
} | |
return query | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment