first executing the code that returns a promise, performing operations on it and then awaiting at last
class APIFeatures { constructor(query, queryString) { this.query = query; this.queryString = queryString; } filter() { const queryObj = { …this.queryString }; const excludedFields = [‘page’, ‘sort’, ‘limit’, ‘fields’]; excludedFields.forEach(el => delete queryObj[el]); // 1B) Advanced filtering let queryStr = JSON.stringify(queryObj); queryStr = queryStr.replace(/b(gte|gt|lte|lt)b/g, match => `$${match}`); this.query = this.query.find(JSON.parse(queryStr)); return this; } const features = […]