Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rashmihunt committed Aug 22, 2017
1 parent 9ab10f4 commit 7b16edd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
14 changes: 6 additions & 8 deletions lib/model.js
Expand Up @@ -758,13 +758,11 @@ module.exports = function(registry) {
var pathName =
(scope.options && scope.options.http && scope.options.http.path) || scopeName;

var updateOnlyProps = this.getUpdateOnlyProperties();
var createOnly = false;
// if there is atleast one updateOnly property, then we set createOnlyInstance flag in __create__
// to indicate loopback-swagger code to create a separate model instance for create operation only
if (updateOnlyProps && updateOnlyProps.length > 0) {
createOnly = true;
}
// if there is atleast one updateOnly property, then we set
// createOnlyInstance flag in __create__ to indicate loopback-swagger
// code to create a separate model instance for create operation only
const updateOnlyProps = this.getUpdateOnlyProperties();
const hasUpdateOnlyProps = updateOnlyProps && updateOnlyProps.length > 0;

var isStatic = scope.isStatic;
var toModelName = scope.modelTo.modelName;
Expand Down Expand Up @@ -799,7 +797,7 @@ module.exports = function(registry) {
type: 'object',
allowArray: true,
model: toModelName,
createOnlyInstance: createOnly,
createOnlyInstance: hasUpdateOnlyProps,
http: {source: 'body'},
},
{arg: 'options', type: 'object', http: 'optionsFromRequest'},
Expand Down
14 changes: 6 additions & 8 deletions lib/persisted-model.js
Expand Up @@ -627,13 +627,11 @@ module.exports = function(registry) {
var typeName = PersistedModel.modelName;
var options = PersistedModel.settings;

var updateOnlyProps = PersistedModel.getUpdateOnlyProperties();
var createOnly = false;
// if there is atleast one updateOnly property, then we set createOnlyInstance flag in __create__
// to indicate loopback-swagger code to create a separate model instance for create operation only
if (updateOnlyProps && updateOnlyProps.length > 0) {
createOnly = true;
}
// if there is atleast one updateOnly property, then we set
// createOnlyInstance flag in __create__ to indicate loopback-swagger
// code to create a separate model instance for create operation only
const updateOnlyProps = this.getUpdateOnlyProperties();
const hasUpdateOnlyProps = updateOnlyProps && updateOnlyProps.length > 0;

// This is just for LB 3.x
options.replaceOnPUT = options.replaceOnPUT !== false;
Expand All @@ -651,7 +649,7 @@ module.exports = function(registry) {
accepts: [
{
arg: 'data', type: 'object', model: typeName, allowArray: true,
createOnlyInstance: createOnly,
createOnlyInstance: hasUpdateOnlyProps,
description: 'Model instance data',
http: {source: 'body'},
},
Expand Down
6 changes: 3 additions & 3 deletions test/remoting.integration.js
Expand Up @@ -200,13 +200,13 @@ describe('remoting - integration', function() {
function() {
var storeClass = findClass('store');
var createMethod = getCreateMethod(storeClass.methods);
assert(createMethod[0].accepts[0].createOnlyInstance === true);
assert(createMethod.accepts[0].createOnlyInstance === true);
});

it('sets createOnlyInstance to false if forceId is set to false in the model', function() {
var customerClass = findClass('customerforceidfalse');
var createMethod = getCreateMethod(customerClass.methods);
assert(createMethod[0].accepts[0].createOnlyInstance === false);
assert(createMethod.accepts[0].createOnlyInstance === false);
});
});
});
Expand Down Expand Up @@ -332,7 +332,7 @@ function getFormattedMethodsExcludingRelations(methods) {
}

function getCreateMethod(methods) {
return methods.filter(function(m) {
return methods.find(function(m) {
return (m.name === 'create');
});
}
Expand Down

0 comments on commit 7b16edd

Please sign in to comment.