import { Injectable } from '@angular/core'; import { RuleContract, ConditionContract, FilterContract } from "./contracts"; import { UtilsService } from "../utils"; import { StorageService } from "../storage"; @Injectable() export class CleverQueryService{ private conditions: ConditionContract[]; private joiners: ('and' | 'or')[]; private filters: FilterContract[]; private query: string; private domain: string[]; private operatorsNValues: { operator: string; value: string }[]; private categories: string[]; private sorters: { operator: 'asc' | 'desc'; column: string }[]; private limit: number = 6; constructor( private _: UtilsService, private store: StorageService ){ this.store = this.store.local(); } simple(conditions: ConditionContract[] = null, joiners: ('and' | 'or')[] = null, page: number = 1, limit?: number){ limit = (limit) ? limit : this.limit; this.conditions = conditions; this.joiners = joiners; this.filters = [{ order: ['id', 'desc']}, { limit: limit }, { offset: limit*(page - 1) }]; return this.make(); } advance(conditions: ConditionContract[] = null, joiners: ('and' | 'or')[] = null, filters: FilterContract[]){ this.conditions = conditions; this.joiners = joiners; this.filters = (filters) ? filters : [{ order: ['id', 'desc']}, { limit: this.limit }, { offset: 0 }]; return this.make(); } make(){ return { conditions: this.conditions, joiners: this.joiners, filters: this.filters }; } public setQuery(query: string){ // this.query = query; return this; } public getCleverQuery(asString: boolean = false): Object[]{ //take the trigger groups //turn it into: //{keywords: string, domains(that corresonds to domains name): [strings], // columns(to search): [string], orderBy: string } return [{ key: '', //columnName operator: '', value: '' }]; } /** * takes getCleverQuery and turn into raw SQL */ public raw(){ return; } } /** * let sampleRawQueryObject = { conditions: [{ 'and' : [['key', 'operator', 'value'],['key', 'operator', 'value']] },{ 'or' : [['key', 'operator', 'value'],['key', 'operator', 'value']] },{ 'year' : [['key', 'operator', 'value'],['key', 'operator', 'value']] }], joiners: ['and', 'or'], filters: [{ 'order': ['column', 'value'] },{ 'offset': 'number' },{ 'limit': 'number' }] }; */