Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bookshelf-modelbase-plus

Package Overview
Dependencies
Maintainers
6
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bookshelf-modelbase-plus - npm Package Compare versions

Comparing version 2.10.2 to 2.10.3

32

lib/index.js

@@ -171,3 +171,12 @@ const _ = require('lodash');

if (options.order_by || options.order_by === '') {
q.orderBy(options.order_by || new this().idAttribute || 'id');
const order = _.castArray(options.order_by || new this().idAttribute || 'id')
.forEach((column) => {
if (column) {
if (column[0] === '-') {
q.query(qb => qb.orderBy(column.slice(1), 'desc'));
} else {
q.query(qb => qb.orderBy(column, 'asc'));
}
}
});
}

@@ -327,6 +336,8 @@ if (options.select) {

}
const debug = options.debug;
let previousAttrs = null;
let unchanged = false;
this
.query({where: findArgs})
.fetch({ require: true })
.fetch({ require: true, debug })
.then((model) => {

@@ -347,2 +358,7 @@ if (_.isEmpty(data)) {

const toSave = _.extend({}, existing, data);
if (_.isEqual(existing, toSave)) {
unchanged = true;
return model;
}
// set updated_at column automatically

@@ -356,9 +372,15 @@ if (model.hasTimestamps) {

return model
.save(toSave, { method: 'update', patch: true, require: true });
.save(toSave, { method: 'update', patch: true, require: true, debug });
})
.then((model) => {
return this.query({ where: findArgs }).fetch({ softDelete: false });
if (unchanged) {
return model;
}
const newWhere = _.mapValues(findArgs, (v, k) => _.has(data, k) ? data[k] : v);
return this.query({ where: newWhere }).fetch({ softDelete: false, debug });
})
.then((model) => {
model.saveAttributes(previousAttrs);
if (!model.unchanged) {
model.saveAttributes(previousAttrs);
}
resolve(model);

@@ -365,0 +387,0 @@ })

2

package.json
{
"name": "bookshelf-modelbase-plus",
"version": "2.10.2",
"version": "2.10.3",
"description": "Extended functionality for REST operations with validation, filtering, ordering, importing records.",

@@ -5,0 +5,0 @@ "main": "./lib",

@@ -134,2 +134,22 @@ /* global jest */

test('should be able to order by multiple', () => {
return User
.getList({ order_by: ['email', 'first_name'] }, User.columns)
.then((models) => {
expect(models.toJSON().map(m => m.email)).toEqual([
'email@user0.com',
'email@user1.com',
'email@user2.com',
]);
})
.then(() => User.getList({ order_by: ['-email', '-first_name'] }))
.then((models) => {
expect(models.toJSON().map(m => m.email)).toEqual([
'email@user2.com',
'email@user1.com',
'email@user0.com',
]);
});
});
it('should be able to skip pagination with !paginate', () => {

@@ -336,2 +356,11 @@ return User

it('should update an entry when in query', () => {
return User
.getList({ email: 'emailtest@user2.com', limit: 1 }, User.columns)
.then(models => User.updateOne(
{ email: 'emailtest-updated', findBy: { email: 'emailtest@user2.com' } },
User.columns
)).then(updatedModel => expect(updatedModel.get('email')).toBe('emailtest-updated'));
});
it('should destroy an entry by composite key', () => {

@@ -338,0 +367,0 @@ return User

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc