Merge pull request #555 from strongloop/feature/include-remote-method-aliases
PersistedModel: add remote method aliases
This commit is contained in:
commit
aac230679f
|
@ -431,6 +431,7 @@ PersistedModel.setupRemoting = function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
setRemoting(PersistedModel, 'upsert', {
|
setRemoting(PersistedModel, 'upsert', {
|
||||||
|
aliases: ['updateOrCreate'],
|
||||||
description: 'Update an existing model instance or insert a new one into the data source',
|
description: 'Update an existing model instance or insert a new one into the data source',
|
||||||
accepts: {arg: 'data', type: 'object', description: 'Model instance data', http: {source: 'body'}},
|
accepts: {arg: 'data', type: 'object', description: 'Model instance data', http: {source: 'body'}},
|
||||||
returns: {arg: 'data', type: typeName, root: true},
|
returns: {arg: 'data', type: typeName, root: true},
|
||||||
|
@ -496,6 +497,7 @@ PersistedModel.setupRemoting = function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
setRemoting(PersistedModel, 'updateAll', {
|
setRemoting(PersistedModel, 'updateAll', {
|
||||||
|
aliases: ['update'],
|
||||||
description: 'Update instances of the model matched by where from the data source',
|
description: 'Update instances of the model matched by where from the data source',
|
||||||
accepts: [
|
accepts: [
|
||||||
{arg: 'where', type: 'object', http: {source: 'query'},
|
{arg: 'where', type: 'object', http: {source: 'query'},
|
||||||
|
@ -507,6 +509,7 @@ PersistedModel.setupRemoting = function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
setRemoting(PersistedModel, 'deleteById', {
|
setRemoting(PersistedModel, 'deleteById', {
|
||||||
|
aliases: ['destroyById', 'removeById'],
|
||||||
description: 'Delete a model instance by id from the data source',
|
description: 'Delete a model instance by id from the data source',
|
||||||
accepts: {arg: 'id', type: 'any', description: 'Model id', required: true,
|
accepts: {arg: 'id', type: 'any', description: 'Model id', required: true,
|
||||||
http: {source: 'path'}},
|
http: {source: 'path'}},
|
||||||
|
|
|
@ -482,4 +482,41 @@ describe.onServer('Remote Methods', function(){
|
||||||
assert.equal(model, acl);
|
assert.equal(model, acl);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('PersistelModel remote methods', function() {
|
||||||
|
it('includes all aliases', function() {
|
||||||
|
var app = loopback();
|
||||||
|
var model = PersistedModel.extend('persistedModel');
|
||||||
|
app.dataSource('db', { connector: 'memory' });
|
||||||
|
app.model(model, { dataSource: 'db' });
|
||||||
|
|
||||||
|
// this code is used by loopback-sdk-angular codegen
|
||||||
|
var metadata = app.handler('rest')
|
||||||
|
.adapter
|
||||||
|
.getClasses()
|
||||||
|
.filter(function(c) { return c.name === 'persistedModel'; })[0];
|
||||||
|
|
||||||
|
var methodNames = [];
|
||||||
|
metadata.methods.forEach(function(method) {
|
||||||
|
methodNames.push(method.name);
|
||||||
|
methodNames = methodNames.concat(method.sharedMethod.aliases || []);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(methodNames).to.have.members([
|
||||||
|
'destroyAll', 'deleteAll', 'remove',
|
||||||
|
'create',
|
||||||
|
'upsert', 'updateOrCreate',
|
||||||
|
'exists',
|
||||||
|
'findById',
|
||||||
|
'find',
|
||||||
|
'findOne',
|
||||||
|
'updateAll', 'update',
|
||||||
|
'deleteById',
|
||||||
|
'destroyById',
|
||||||
|
'removeById',
|
||||||
|
'count',
|
||||||
|
'prototype.updateAttributes'
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue