viewmodel
Advanced tools
Comparing version 0.5.0 to 0.5.1
var cradle = require('cradle') | ||
, _ = require('lodash'); | ||
, _ = require('lodash') | ||
, ConcurrencyError = require('../concurrencyError'); | ||
@@ -190,3 +191,3 @@ module.exports = { | ||
finish(); | ||
} | ||
} | ||
}); | ||
@@ -336,6 +337,9 @@ | ||
delete obj._revision; | ||
delete obj._rev; | ||
// delete obj._rev; | ||
obj.id = obj._id; | ||
obj.collectionName = this.collectionName; | ||
this.db.save(obj._id, obj, function(err) { | ||
if (err && err.error === 'conflict' && err.reason.indexOf('update conflict') >= 0) { | ||
return callback(new ConcurrencyError()); | ||
} | ||
vm.actionOnCommit = 'update'; | ||
@@ -342,0 +346,0 @@ callback(err, vm); |
var _ = require('lodash') | ||
, store = {} | ||
, uuid = require('../uuid'); | ||
, uuid = require('../uuid') | ||
, ConcurrencyError = require('../concurrencyError'); | ||
@@ -23,3 +24,3 @@ function deepFind(obj, pattern) { | ||
break; | ||
} | ||
} | ||
@@ -145,4 +146,9 @@ if (!found) { | ||
case 'update': | ||
col[vm.id] = this.fromViewModel(vm); | ||
if (col[vm.id] && vm._hash && col[vm.id]._hash && vm._hash !== col[vm.id]._hash) { | ||
return callback(new ConcurrencyError()); | ||
} | ||
vm.actionOnCommit = 'update'; | ||
var clone = _.clone(vm, true); | ||
clone._hash = uuid().toString(); | ||
col[clone.id] = this.fromViewModel(clone); | ||
break; | ||
@@ -149,0 +155,0 @@ default: |
var mongo = require('mongodb') | ||
, ObjectID = mongo.BSONPure.ObjectID | ||
, _ = require('lodash'); | ||
, _ = require('lodash') | ||
, ConcurrencyError = require('../concurrencyError'); | ||
@@ -139,2 +140,4 @@ module.exports = { | ||
var obj; | ||
switch(vm.actionOnCommit) { | ||
@@ -145,6 +148,5 @@ case 'delete': | ||
case 'create': | ||
// Intended Fall-through | ||
case 'update': | ||
var obj = this.fromViewModel(vm); | ||
obj = this.fromViewModel(vm); | ||
obj._id = obj.id; | ||
obj._hash = new ObjectID().toString(); | ||
this.collection.save(obj, { safe: true }, function(err) { | ||
@@ -155,2 +157,19 @@ vm.actionOnCommit = 'update'; | ||
break; | ||
case 'update': | ||
obj = this.fromViewModel(vm); | ||
obj._id = obj.id; | ||
var currentHash = obj._hash; | ||
obj._hash = new ObjectID().toString(); | ||
var query = { _id: obj._id }; | ||
if (currentHash) { | ||
query._hash = currentHash; | ||
} | ||
this.collection.update(query, obj, { safe: true, upsert: !currentHash }, function(err, modifiedCount) { | ||
if (modifiedCount === 0) { | ||
return callback(new ConcurrencyError()); | ||
} | ||
vm.actionOnCommit = 'update'; | ||
callback(err, vm); | ||
}); | ||
break; | ||
default: | ||
@@ -157,0 +176,0 @@ return callback(new Error()); |
var path = require('path') | ||
, _ = require('lodash') | ||
, ConcurrencyError = require('../concurrencyError') | ||
, tingodb = require('tingodb')(); | ||
@@ -119,6 +120,5 @@ | ||
case 'create': | ||
// Intended Fall-through | ||
case 'update': | ||
var obj = this.fromViewModel(vm); | ||
obj = this.fromViewModel(vm); | ||
obj._id = obj.id; | ||
obj._hash = new tingodb.ObjectID().toString(); | ||
this.collection.save(obj, { safe: true }, function(err) { | ||
@@ -129,2 +129,20 @@ vm.actionOnCommit = 'update'; | ||
break; | ||
case 'update': | ||
obj = this.fromViewModel(vm); | ||
obj._id = obj.id; | ||
var currentHash = obj._hash; | ||
obj._hash = new tingodb.ObjectID().toString(); | ||
var query = { _id: obj._id }; | ||
if (currentHash) { | ||
query._hash = currentHash; | ||
} | ||
this.collection.update(query, obj, { safe: true, upsert: !currentHash }, function(err, modifiedCount) { | ||
console.log(arguments); | ||
if (modifiedCount === 0) { | ||
return callback(new ConcurrencyError()); | ||
} | ||
vm.actionOnCommit = 'update'; | ||
callback(err, vm); | ||
}); | ||
break; | ||
default: | ||
@@ -131,0 +149,0 @@ return callback(new Error()); |
{ | ||
"author": "adrai", | ||
"name": "viewmodel", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43285
13
988