How to use the @feathersjs/commons.select function in @feathersjs/commons

To help you get started, we’ve selected a few @feathersjs/commons examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github feathersjs-ecosystem / feathers-rethinkdb / lib / index.js View on Github external
// Find the original record(s), first, then patch them.
    return query.then(getData => {
      let query;
      let options = Object.assign({ returnChanges: true }, params.rethinkdb);

      if (Array.isArray(getData)) {
        query = this.table.getAll(...getData.map(item => item[this.id]));
      } else {
        query = this.table.get(id);
      }

      return query.update(data, options).run().then(response => {
        let changes = response.changes.map(change => change.new_val);
        return changes.length === 1 ? changes[0] : changes;
      });
    }).then(select(params, this.id));
  }
github feathersjs-ecosystem / feathers-rethinkdb / lib / index.js View on Github external
update (id, data, params = {}) {
    let options = Object.assign({ returnChanges: true }, params.rethinkdb);

    if (Array.isArray(data) || id === null) {
      return Promise.reject(new errors.BadRequest('Not replacing multiple records. Did you mean `patch`?'));
    }

    return this._get(id, params).then(getData => {
      data[this.id] = id;
      return this.table.get(getData[this.id])
        .replace(data, options).run().then(result =>
          (result.changes && result.changes.length) ? result.changes[0].new_val : data
        );
    }).then(select(params, this.id));
  }
github feathersjs-ecosystem / feathers-rethinkdb / lib / index.js View on Github external
if (res.generated_keys && res.generated_keys[index]) {
            return Object.assign({}, current, {
              [idField]: res.generated_keys[index]
            });
          }

          return current;
        };

        if (Array.isArray(data)) {
          return data.map(addId);
        }

        return addId(data, 0);
      }
    }).then(select(params, this.id));
  }
github feathersjs-ecosystem / feathers-rethinkdb / lib / index.js View on Github external
} else if (id === null) {
      query = this.createQuery(params.query);
    } else {
      return Promise.reject(new Error('You must pass either an id or params to remove.'));
    }

    return query.delete(options)
      .run()
      .then(res => {
        if (res.changes && res.changes.length) {
          let changes = res.changes.map(change => change.old_val);
          return changes.length === 1 ? changes[0] : changes;
        } else {
          return [];
        }
      }).then(select(params, this.id));
  }