feathers-sequelize
Advanced tools
Comparing version 1.0.1 to 1.0.2
240
lib/index.js
'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
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; }; })(); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
@@ -31,150 +33,150 @@ exports.default = init; | ||
if (!global._babelPolyfill) { | ||
require('babel-polyfill'); | ||
require('babel-polyfill'); | ||
} | ||
var Service = (function () { | ||
function Service(options) { | ||
_classCallCheck(this, Service); | ||
function Service(options) { | ||
_classCallCheck(this, Service); | ||
this.paginate = options.paginate || {}; | ||
this.Model = options.Model; | ||
this.id = options.id || 'id'; | ||
} | ||
this.paginate = options.paginate || {}; | ||
this.Model = options.Model; | ||
this.id = options.id || 'id'; | ||
} | ||
_createClass(Service, [{ | ||
key: 'extend', | ||
value: function extend(obj) { | ||
return _uberproto2.default.extend(obj, this); | ||
} | ||
}, { | ||
key: 'find', | ||
value: function find(params) { | ||
var _this = this; | ||
_createClass(Service, [{ | ||
key: 'extend', | ||
value: function extend(obj) { | ||
return _uberproto2.default.extend(obj, this); | ||
} | ||
}, { | ||
key: 'find', | ||
value: function find(params) { | ||
var _this = this; | ||
var where = (0, _utils.getWhere)(params.query); | ||
var filters = (0, _feathersQueryFilters2.default)(where); | ||
var order = (0, _utils.getOrder)(filters.$sort || {}); | ||
var query = { | ||
where: where, order: order, | ||
limit: filters.$limit, | ||
offset: filters.$skip, | ||
attributes: filters.$select || null | ||
}; | ||
var where = (0, _utils.getWhere)(params.query); | ||
var filters = (0, _feathersQueryFilters2.default)(where); | ||
var order = (0, _utils.getOrder)(filters.$sort || {}); | ||
var query = { | ||
where: where, order: order, | ||
limit: filters.$limit, | ||
offset: filters.$skip, | ||
attributes: filters.$select || null | ||
}; | ||
if (this.paginate.default) { | ||
var _ret = (function () { | ||
var limit = Math.min(filters.$limit || _this.paginate.default, _this.paginate.max || Number.MAX_VALUE); | ||
if (this.paginate.default) { | ||
var _ret = (function () { | ||
var limit = Math.min(filters.$limit || _this.paginate.default, _this.paginate.max || Number.MAX_VALUE); | ||
query.limit = limit; | ||
query.limit = limit; | ||
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) | ||
}; | ||
})(); | ||
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 ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} | ||
return this.Model.findAll(query).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'get', | ||
value: function get(id) { | ||
return this.Model.findById(id).then(function (instance) { | ||
if (!instance) { | ||
throw new _feathersErrors2.default.NotFound('No record found for id \'' + id + '\''); | ||
} | ||
return this.Model.findAll(query).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'get', | ||
value: function get(id) { | ||
return this.Model.findById(id).then(function (instance) { | ||
if (!instance) { | ||
throw new _feathersErrors2.default.NotFound('No record found for id \'' + id + '\''); | ||
} | ||
return instance; | ||
}).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'create', | ||
value: function create(data) { | ||
if (Array.isArray(data)) { | ||
return this.Model.bulkCreate(data).catch(_utils.errorHandler); | ||
} | ||
return instance; | ||
}).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'create', | ||
value: function create(data) { | ||
if (Array.isArray(data)) { | ||
return this.Model.bulkCreate(data).catch(_utils.errorHandler); | ||
} | ||
return this.Model.create(data).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'patch', | ||
value: function patch(id, data, params) { | ||
var _this2 = this; | ||
return this.Model.create(data).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'patch', | ||
value: function patch(id, data, params) { | ||
var _this2 = this; | ||
var where = Object.assign({}, params.query); | ||
var where = _extends({}, params.query); | ||
if (id !== null) { | ||
where[this.id] = id; | ||
} | ||
if (id !== null) { | ||
where[this.id] = id; | ||
} | ||
delete data[this.id]; | ||
delete data[this.id]; | ||
return this.Model.update(data, { where: where }).then(function () { | ||
if (id === null) { | ||
return _this2.find(params); | ||
} | ||
return this.Model.update(data, { where: where }).then(function () { | ||
if (id === null) { | ||
return _this2.find(params); | ||
} | ||
return _this2.get(id, params); | ||
}).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'update', | ||
value: function update(id, data) { | ||
if (Array.isArray(data)) { | ||
return Promise.reject('Not replacing multiple records. Did you mean `patch`?'); | ||
} | ||
return _this2.get(id, params); | ||
}).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'update', | ||
value: function update(id, data) { | ||
if (Array.isArray(data)) { | ||
return Promise.reject('Not replacing multiple records. Did you mean `patch`?'); | ||
} | ||
delete data[this.id]; | ||
delete data[this.id]; | ||
return this.Model.findById(id).then(function (instance) { | ||
if (!instance) { | ||
throw new _feathersErrors2.default.NotFound('No record found for id \'' + id + '\''); | ||
} | ||
return this.Model.findById(id).then(function (instance) { | ||
if (!instance) { | ||
throw new _feathersErrors2.default.NotFound('No record found for id \'' + id + '\''); | ||
} | ||
var copy = {}; | ||
Object.keys(instance.toJSON()).forEach(function (key) { | ||
if (typeof data[key] === 'undefined') { | ||
copy[key] = null; | ||
} else { | ||
copy[key] = data[key]; | ||
} | ||
}); | ||
var copy = {}; | ||
Object.keys(instance.toJSON()).forEach(function (key) { | ||
if (typeof data[key] === 'undefined') { | ||
copy[key] = null; | ||
} else { | ||
copy[key] = data[key]; | ||
} | ||
}); | ||
return instance.update(copy); | ||
}).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'remove', | ||
value: function remove(id, params) { | ||
var _this3 = this; | ||
return instance.update(copy); | ||
}).catch(_utils.errorHandler); | ||
} | ||
}, { | ||
key: 'remove', | ||
value: function remove(id, params) { | ||
var _this3 = this; | ||
var promise = id === null ? this.find(params) : this.get(id); | ||
var promise = id === null ? this.find(params) : this.get(id); | ||
return promise.then(function (data) { | ||
var where = Object.assign({}, params.query); | ||
return promise.then(function (data) { | ||
var where = _extends({}, params.query); | ||
if (id !== null) { | ||
where.id = id; | ||
} | ||
if (id !== null) { | ||
where.id = id; | ||
} | ||
return _this3.Model.destroy({ where: where }).then(function () { | ||
return data; | ||
}); | ||
}).catch(_utils.errorHandler); | ||
} | ||
}]); | ||
return _this3.Model.destroy({ where: where }).then(function () { | ||
return data; | ||
}); | ||
}).catch(_utils.errorHandler); | ||
} | ||
}]); | ||
return Service; | ||
return Service; | ||
})(); | ||
function init(Model) { | ||
return new Service(Model); | ||
return new Service(Model); | ||
} | ||
@@ -181,0 +183,0 @@ |
'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -59,3 +61,3 @@ value: true | ||
function getWhere(query) { | ||
var where = Object.assign({}, query); | ||
var where = _extends({}, query); | ||
@@ -65,3 +67,3 @@ Object.keys(where).forEach(function (prop) { | ||
if (value.$nin) { | ||
value = Object.assign({}, value); | ||
value = _extends({}, value); | ||
@@ -68,0 +70,0 @@ value.$notIn = value.$nin; |
{ | ||
"name": "feathers-sequelize", | ||
"description": "A service adapter for Sequelize an SQL ORM", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"homepage": "https://github.com/feathersjs/feathers-sequelize", | ||
@@ -48,10 +48,2 @@ "main": "lib/", | ||
}, | ||
"babel": { | ||
"plugins": [ | ||
"add-module-exports" | ||
], | ||
"presets": [ | ||
"es2015" | ||
] | ||
}, | ||
"dependencies": { | ||
@@ -67,2 +59,3 @@ "babel-polyfill": "^6.3.14", | ||
"babel-plugin-add-module-exports": "^0.1.1", | ||
"babel-plugin-transform-object-assign": "^6.1.18", | ||
"babel-preset-es2015": "^6.1.2", | ||
@@ -69,0 +62,0 @@ "body-parser": "^1.14.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27391
248
13