feathers-sequelize
Advanced tools
+49
-34
@@ -5,4 +5,2 @@ 'use strict'; | ||
| var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -64,8 +62,8 @@ | ||
| }, { | ||
| key: 'find', | ||
| value: function find(params) { | ||
| var _this = this; | ||
| key: '_find', | ||
| value: function _find(params) { | ||
| var getFilter = arguments.length <= 1 || arguments[1] === undefined ? _feathersQueryFilters2.default : arguments[1]; | ||
| var where = utils.getWhere(params.query); | ||
| var filters = (0, _feathersQueryFilters2.default)(where); | ||
| var filters = getFilter(where); | ||
| var order = utils.getOrder(filters.$sort); | ||
@@ -79,28 +77,31 @@ var query = { | ||
| if (this.paginate.default) { | ||
| var _ret = function () { | ||
| var limit = Math.min(filters.$limit || _this.paginate.default, _this.paginate.max || Number.MAX_VALUE); | ||
| return this.Model.findAndCount(query).then(function (result) { | ||
| return { | ||
| total: result.count, | ||
| limit: filters.$limit, | ||
| skip: filters.$skip || 0, | ||
| data: result.rows | ||
| }; | ||
| }).catch(utils.errorHandler); | ||
| } | ||
| }, { | ||
| key: 'find', | ||
| value: function find(params) { | ||
| var _this = this; | ||
| query.limit = limit; | ||
| var result = this._find(params, function (where) { | ||
| return (0, _feathersQueryFilters2.default)(where, _this.paginate); | ||
| }); | ||
| return { | ||
| v: _this.Model.findAndCount(query).then(function (result) { | ||
| return { | ||
| total: result.count, | ||
| limit: limit, | ||
| skip: filters.$skip || 0, | ||
| data: result.rows | ||
| }; | ||
| }).catch(utils.errorHandler) | ||
| }; | ||
| }(); | ||
| if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
| if (!this.paginate.default) { | ||
| return result.then(function (page) { | ||
| return page.data; | ||
| }); | ||
| } | ||
| return this.Model.findAll(query).catch(utils.errorHandler); | ||
| return result; | ||
| } | ||
| }, { | ||
| key: 'get', | ||
| value: function get(id) { | ||
| key: '_get', | ||
| value: function _get(id) { | ||
| return this.Model.findById(id).then(function (instance) { | ||
@@ -114,3 +115,23 @@ if (!instance) { | ||
| } | ||
| // returns either the model intance for an id or all unpaginated | ||
| // items for `params` if id is null | ||
| }, { | ||
| key: '_getOrFind', | ||
| value: function _getOrFind(id, params) { | ||
| if (id === null) { | ||
| return this._find(params).then(function (page) { | ||
| return page.data; | ||
| }); | ||
| } | ||
| return this._get(id, params); | ||
| } | ||
| }, { | ||
| key: 'get', | ||
| value: function get(id, params) { | ||
| return this._get(id, params); | ||
| } | ||
| }, { | ||
| key: 'create', | ||
@@ -138,7 +159,3 @@ value: function create(data) { | ||
| return this.Model.update(data, { where: where }).then(function () { | ||
| if (id === null) { | ||
| return _this2.find(params); | ||
| } | ||
| return _this2.get(id, params); | ||
| return _this2._getOrFind(id, params); | ||
| }).catch(utils.errorHandler); | ||
@@ -177,5 +194,3 @@ } | ||
| var promise = id === null ? this.find(params) : this.Model.findById(id); | ||
| return promise.then(function (data) { | ||
| return this._getOrFind(id, params).then(function (data) { | ||
| var where = _extends({}, params.query); | ||
@@ -182,0 +197,0 @@ |
+2
-2
| { | ||
| "name": "feathers-sequelize", | ||
| "description": "A service adapter for Sequelize an SQL ORM", | ||
| "version": "1.0.10", | ||
| "version": "1.1.0", | ||
| "homepage": "https://github.com/feathersjs/feathers-sequelize", | ||
@@ -54,3 +54,3 @@ "main": "lib/", | ||
| "feathers-errors": "^1.1.5", | ||
| "feathers-query-filters": "^1.1.1", | ||
| "feathers-query-filters": "^1.5.1", | ||
| "uberproto": "^1.1.2" | ||
@@ -57,0 +57,0 @@ }, |
+4
-0
@@ -84,2 +84,6 @@ # feathers-sequelize | ||
| __1.1.0__ | ||
| - Use internal methods instead of service methods directly ([#8](https://github.com/feathersjs/feathers-sequelize/issues/8)) | ||
| __1.0.0__ | ||
@@ -86,0 +90,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
22185
0.98%276
6.15%107
3.88%