export class ElasticUtils { findAndUpdateValue(obj: any, key: any, newValue: any) { // Anahtar, objenin kendisinde mi yoksa içinde mi bulunuyor? if (obj.hasOwnProperty(key)) { // Anahtar mevcut, yeni değerle güncelleniyor obj[key] = { ...obj[key], ...newValue, } } else { // Anahtar mevcut değil, alt nesnelere bakılacak for (let k in obj) { if (typeof obj[k] === 'object') { // İç içe nesneler varsa, alt nesnelere bakılacak this.findAndUpdateValue(obj[k], key, newValue); } } } return obj; } parentResolver() { // @ts-ignore if (this.parents.length > 0) { // @ts-ignore var recentTrees = this.query; // @ts-ignore for (let index = 0; index < this.parents.length; index++) { // @ts-ignore if (this.parents[index] == 'bool') { // @ts-ignore if (!recentTrees[this.parents[index]]) { recentTrees = { bool: this.endParent(index, {}) } } } // @ts-ignore else if (this.parents[index] == 'should' || this.parents[index] == 'must') { // @ts-ignore if (this.parents.length > 0) { // @ts-ignore recentTrees = this.findAndUpdateValue(recentTrees, this.parents[0], { [this.parents[index]]: this.children }) } else { // @ts-ignore recentTrees = this.endParent(index, value, {}) } } } // @ts-ignore this.query = recentTrees; } } endParent(index: any, empty: any) { // @ts-ignore return this.parents.length == (index + 1) ? this.children : empty } isDefined(key: any, value: any) { return key != undefined && key != null && value != undefined && value != null } }