From 088023d7590f6a535b3495b9f36f680dc67b1727 Mon Sep 17 00:00:00 2001 From: Mariano Benedettini Date: Wed, 7 Nov 2018 13:39:34 -0300 Subject: [PATCH 1/2] Handle replaceOrCreate (upsert) --- lib/read-only.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/read-only.js b/lib/read-only.js index 15d6ea1..ed9e438 100644 --- a/lib/read-only.js +++ b/lib/read-only.js @@ -33,7 +33,7 @@ module.exports = Model => { const AffectedModel = Model.app.loopback.getModel(modelName) const options = AffectedModel.settings.mixins.ReadOnly const properties = (Object.keys(options).length) ? options : null - const instanceId = ctx.args[AffectedModel.getIdName()] + const instanceId = ctx.args[AffectedModel.getIdName()] || body.id if (properties) { debug('Found read only properties for model %s: %o', modelName, properties) From 9c0d42069aee22d3b6bac07142b4a6ff6f9dcff7 Mon Sep 17 00:00:00 2001 From: Mariano Benedettini Date: Wed, 7 Nov 2018 14:42:48 -0300 Subject: [PATCH 2/2] Fix tests --- test/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index 2db2066..7956f39 100644 --- a/test/test.js +++ b/test/test.js @@ -153,7 +153,7 @@ describe('loopback datasource readonly property (mixin sources.js)', function() .send({ id: this.product.id, status: 'disabled' }) .expect(200) .then(() => app.models.Product.findById(this.product.id)) - .then(product => expect(product.status).to.equal('temp')) + .then(product => expect(product.status).to.equal('pending')) }) }) @@ -186,7 +186,7 @@ describe('loopback datasource readonly property (mixin sources.js)', function() .send(Object.assign(this.product.toJSON(), { status: 'disabled' })) .expect(200) .then(() => app.models.Product.findById(this.product.id)) - .then(product => expect(product.status).to.equal('temp')) + .then(product => expect(product.status).to.equal('pending')) }) })