Commit cb939cc9 authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Extend Query.merge() to query functions

parent d4abb965
import { currentLanguage } from '../language';
import PaginationController from '../pagination';
import Query from '../query';
import Event from './Event';
/**
......@@ -9,7 +10,7 @@ import Event from './Event';
*/
export default class EventListController extends PaginationController {
constructor(query = {}, additionalQuery = {}) {
super('events', query, additionalQuery);
super('events', query, Query.merge(additionalQuery, { where: { show_website: true } }));
}
async _loadData(query) {
......
......@@ -30,7 +30,12 @@ export default class Query {
*/
static merge(...queries) {
const newQuery = {};
const queryFunctions = [];
queries.forEach(query => {
if (typeof query === 'function') {
queryFunctions.push(query);
return;
}
Object.entries(query).forEach(([key, value]) => {
if (newQuery[key]) {
if (key === '$or') {
......@@ -48,7 +53,9 @@ export default class Query {
}
});
});
return newQuery;
if (queryFunctions.length === 0) return newQuery;
return () => Query.merge(...newQuery, ...queryFunctions.map(queryFunction => queryFunction()));
}
/**
......
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