Commit fd379ac3 authored by DESKTOP-J7QTMBR\mikke's avatar DESKTOP-J7QTMBR\mikke
Browse files

filter sorter and more

parent cee0197b
......@@ -5,12 +5,18 @@ module.exports = {
country: async (args) => {
try {
let kontinent = String(args.continent_contains || "")
//let query = filter ? {$or: buildFilters(resolvers)} : {};
let search = String(args.search || "")
sortOrder = {};
//if(args.sort !== void 0){
sortOrder = { capital: -1};
const countryFetched = await Country.find({continent: {$in: kontinent}})
if(args.order !== null){
sortOrder = { capital: (args.order === "ASC" ? 1 : -1)};
}
let start = parseInt(args.start || 0);
let limit = parseInt(args.limit || -1);
const countryFetched = await Country.find({
continent: {$regex: kontinent, '$options' : 'i'},
name: {$regex: search, '$options' : 'i'}})
.limit(limit === -1 ? '$count' : limit)
.skip(start)
.sort(sortOrder);
return countryFetched.map((country) => {
return {
......
......@@ -17,7 +17,7 @@ module.exports = buildSchema(`
capital: String!
}
type Query {
country(continent_contains: String, skip: Int, take: Int, order: String): [Country!]
country(continent_contains: String, start: Int, limit: Int, order: String, search: String): [Country!]
}
input NameOrder {
nameOrder: String
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment