UNPKG

archidekt

Version:
60 lines (50 loc) 1.3 kB
import archidekt from './config' import { URIFormats, URIColors, URICards, URICommanders } from './utils' export const searchDecks = async ({ logicalAnd=false, owner=null, colors=['White', 'Blue', 'Black', 'Green', 'Red', 'Colorless'], cards=null, orderBy='createdAt', descending=true, formats=null, pageSize=10, commanders=null }) => { let params = processSearchParameters({ logicalAnd, owner, colors, cards, orderBy, descending, formats, pageSize, commanders, }) let response = await archidekt.get('decks/cards/', {params}) return response } const processSearchParameters = ({ logicalAnd=false, owner=null, colors=['White', 'Blue', 'Black', 'Green', 'Red', 'Colorless'], cards=null, orderBy='createdAt', descending=true, formats=null, pageSize=10, commanders=null }) => { let params = {} if (logicalAnd) params.andcolors = true if (colors) params.colors = URIColors(colors) if (owner) params.owner = owner if (cards) params.cards = URICards(cards) if (orderBy) params.orderBy = `${descending?'-':''}${orderBy}` if (formats) params.formats = URIFormats(formats) if (commanders) params.commanders = URICommanders(commanders) if (pageSize) params.pageSize = pageSize return params } const search = { decks }