From ee08cef94161d424d51ac891397d02e39cb8f271 Mon Sep 17 00:00:00 2001 From: Jonathan Casarrubias Date: Wed, 17 Aug 2016 17:23:49 -0500 Subject: [PATCH] Release 2.0.0-rc.9.1 - Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/90 - Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/89 --- CHANGELOG.md | 5 + README.md | 2 +- lib/angular2/index.js | 29 +- lib/utils.js | 8 +- package.json | 2 +- tests/angular2/package.json | 8 +- .../app/shared/sdk/services/custom/Account.ts | 232 +++++++---- .../services/custom/ApplicationCredential.ts | 96 ++++- .../shared/sdk/services/custom/Category.ts | 170 +++++--- .../app/shared/sdk/services/custom/Like.ts | 96 ++++- .../app/shared/sdk/services/custom/Room.ts | 370 +++++++++++------- .../shared/sdk/services/custom/RoomAccount.ts | 96 ++++- .../app/shared/sdk/services/custom/User.ts | 164 +++++--- .../sdk/services/custom/UserCredential.ts | 96 ++++- .../sdk/services/custom/UserIdentity.ts | 96 ++++- 15 files changed, 1026 insertions(+), 444 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22668d72..4e8da143 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ This file is created to keep history of the LoopBack SDK Builder, it does not co ## Release 2.0.0-rc.9 +- Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/90 +- Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/89 + +## Release 2.0.0-rc.9 + - Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/88 - Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/87 - Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/85 diff --git a/README.md b/README.md index 85e9f7d3..7789e180 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ You don't have to manually write any static code. ````sh $ cd to/api/project -$ npm install --save-dev loopback-sdk-builder@2.0.0-rc.9 +$ npm install --save-dev loopback-sdk-builder@2.0.0-rc.9.1 ```` # LoopBack SDK CLI Options diff --git a/lib/angular2/index.js b/lib/angular2/index.js index 4a51fc12..82c7c5fc 100644 --- a/lib/angular2/index.js +++ b/lib/angular2/index.js @@ -266,19 +266,33 @@ module.exports = function generate(ctx) { * @method buildServiceImports * @description * Define import statement for those model who are related to other scopes + * IMPORTANT: This method have a very specific flow, changing it may create + * multiple issues on multiple different use cases. */ function buildServiceImports(model) { let output = [` ${capitalize(model.name)}`]; let loaded = {}; loaded[model.name] = true; getModelRelations(model).forEach((relationName, i) => { let targetClass = model.sharedClass.ctor.relations[relationName].targetClass; + // It is imperative to check first for through models, else we may miss some + // Through Models. This is because multiple relationships to the same model may have + // different Through models, in the next validation we avoid duplicating models, which + // can lead to miss some through models. + if ( + model.sharedClass.ctor.relations[relationName].modelThrough && + model.sharedClass.ctor.relations[relationName].modelThrough.sharedClass.name !== 'Model' + ) { + let through = capitalize(model.sharedClass.ctor.relations[relationName].modelThrough.sharedClass.name); + if (!loaded[through]) { + loaded[through] = true; + output.push(` ${through}`); + } + } + // Now and after the through model was included is the right time to verify if the current model + // was loaded by another relationship, this way we don't duplicate the class during imports' if (!loaded[targetClass]) { loaded[targetClass] = true; output.push(` ${targetClass}`); - if (model.sharedClass.ctor.relations[relationName].modelThrough && - model.sharedClass.ctor.relations[relationName].modelThrough.sharedClass.name !== 'Model') - output.push(` ${capitalize(model.sharedClass.ctor.relations[relationName] - .modelThrough.sharedClass.name)}`); } }); output.push(' LoopBackFilter'); @@ -421,9 +435,8 @@ function capitalize(string) { } function getModelRelations(model) { - return Object.keys(model.sharedClass.ctor.relations).filter(relationName => { - return model.sharedClass.ctor.relations[relationName].targetClass && - model.sharedClass.ctor.relations[relationName].targetClass !== model.name - } + return Object.keys(model.sharedClass.ctor.relations).filter(relationName => + model.sharedClass.ctor.relations[relationName].targetClass && + model.sharedClass.ctor.relations[relationName].targetClass !== model.name ); } \ No newline at end of file diff --git a/lib/utils.js b/lib/utils.js index fce9bc94..ad735412 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -28,18 +28,17 @@ exports.describeModels = function describeModels(app) { console.error('Skipping %j as it is not a LoopBack model', name); return; } - // The URL of prototype methods include sharedCtor parameters like ":id" // Because all $resource methods are static (non-prototype) in ngResource, // the sharedCtor parameters should be added to the parameters // of prototype methods. c.methods.forEach(function fixArgsOfPrototypeMethods(method, key) { - if (method.name.match(/(^createMany)/)) return; + if (method.name.match(/(^createMany)/)) return if (method.name.match(/(^create$|__create__)/)) { var createMany = Object.create(method); createMany.name = method.name.replace(/create/g, 'createMany'); createMany.isReturningArray = function () { return true; }; - c.methods.splice(key + 1, 0, createMany); + c.methods.push(createMany); } var ctor = method.restClass.ctor; if (!ctor || method.sharedMethod.isStatic) return; @@ -55,7 +54,6 @@ exports.describeModels = function describeModels(app) { } }); } - if (!method.accepts) return; // Any extra http action arguments in the path need to be added to the @@ -76,7 +74,7 @@ exports.describeModels = function describeModels(app) { c.properties = c.sharedClass.ctor.definition.properties; c.isUser = c.sharedClass.ctor.prototype instanceof app.loopback.User || - c.sharedClass.ctor.prototype === app.loopback.User.prototype; + c.sharedClass.ctor.prototype === app.loopback.User.prototype; models[name] = c; }); diff --git a/package.json b/package.json index 6d359950..fe9fc383 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-sdk-builder", - "version": "2.0.0-rc.9", + "version": "2.0.0-rc.9.1", "description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack", "bin": { "lb-ng": "bin/lb-ng", diff --git a/tests/angular2/package.json b/tests/angular2/package.json index 86015c86..526dbeed 100644 --- a/tests/angular2/package.json +++ b/tests/angular2/package.json @@ -17,7 +17,7 @@ "@angular/common": "2.0.0-rc.4", "@angular/compiler": "2.0.0-rc.4", "@angular/core": "2.0.0-rc.4", - "@angular/http": "^2.0.0-rc.4", + "@angular/http": "2.0.0-rc.4", "@angular/platform-browser": "2.0.0-rc.4", "@angular/platform-browser-dynamic": "2.0.0-rc.4", "@angular/router": "3.0.0-alpha.8", @@ -36,10 +36,10 @@ "reflect-metadata": "0.1.3", "requirejs": "^2.2.0", "rxjs": "5.0.0-beta.6", - "serve-favicon": "^2.0.1", - "socket.io-client": "^1.4.8", + "serve-favicon": "2.0.1", + "socket.io-client": "1.4.8", "systemjs": "0.19.26", - "zone.js": "^0.6.12" + "zone.js": "0.6.12" }, "devDependencies": { "angular-cli": "0.0.*", diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Account.ts b/tests/angular2/src/app/shared/sdk/services/custom/Account.ts index 33a1a0a7..ff499caf 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/Account.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/Account.ts @@ -9,8 +9,8 @@ import { } from '../core/index'; import { Account, - Room, RoomAccount, + Room, LoopBackFilter } from '../../models/index'; import { LoopBackConfig } from '../../lb.config'; @@ -377,39 +377,6 @@ export class AccountApi extends BaseLoopBackApi { return result; } - /** - * Creates a new instance in accessTokens of this model. - * - * @param any id User id - * - * @param object data Request data. - * - * This method expects a subset of model properties as request parameters. - * - * @returns object[] An empty reference that will be - * populated with the actual data once the response is returned - * from the server. - * - * - * (The remote method definition does not provide any description. - * This usually means the response is a `Account` object.) - * - */ - public createManyAccessTokens(id: any, data: any = undefined) { - let method: string = "POST"; - let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/Accounts/:id/accessTokens"; - let routeParams: any = { - id: id - }; - let postBody: any = { - data: data - }; - let urlParams: any = {}; - let result = this.request(method, url, routeParams, urlParams, postBody); - return result; - } - /** * Deletes all accessTokens of this model. * @@ -526,39 +493,6 @@ export class AccountApi extends BaseLoopBackApi { return result; } - /** - * Creates a new instance in rooms of this model. - * - * @param any id User id - * - * @param object data Request data. - * - * This method expects a subset of model properties as request parameters. - * - * @returns object[] An empty reference that will be - * populated with the actual data once the response is returned - * from the server. - * - * - * (The remote method definition does not provide any description. - * This usually means the response is a `Account` object.) - * - */ - public createManyRooms(id: any, data: Room = undefined) { - let method: string = "POST"; - let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/Accounts/:id/rooms"; - let routeParams: any = { - id: id - }; - let postBody: any = { - data: data - }; - let urlParams: any = {}; - let result = this.request(method, url, routeParams, urlParams, postBody); - return result; - } - /** * Deletes all rooms of this model. * @@ -642,13 +576,13 @@ export class AccountApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -657,8 +591,8 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts"; let routeParams: any = {}; @@ -667,13 +601,11 @@ export class AccountApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: Account) => new Account(instance)) - ); + return result.map((instance: Account) => new Account(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -688,17 +620,17 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/Accounts"; + "/Accounts/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: Account) => new Account(instance)); + return result; } /** @@ -728,7 +660,7 @@ export class AccountApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -757,6 +689,39 @@ export class AccountApi extends BaseLoopBackApi { return result.map((instance: Account) => new Account(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Account` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Accounts/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -812,7 +777,7 @@ export class AccountApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -841,7 +806,7 @@ export class AccountApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -893,7 +858,7 @@ export class AccountApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. * * @param any id User id * @@ -911,7 +876,7 @@ export class AccountApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PUT"; + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id"; let routeParams: any = { @@ -974,7 +939,7 @@ export class AccountApi extends BaseLoopBackApi { * The response body contains properties of the AccessToken created on login. * Depending on the value of `include` parameter, the body may contain additional properties: * - * - `user` - `{User}` - Data of the currently logged in user. (`include=user`) + * - `user` - `U+007BUserU+007D` - Data of the currently logged in user. (`include=user`) * * */ @@ -1084,6 +1049,103 @@ export class AccountApi extends BaseLoopBackApi { let result = this.request(method, url, routeParams, urlParams, postBody); return result; } + + /** + * Creates a new instance in accessTokens of this model. + * + * @param any id User id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Account` object.) + * + */ + public createManyAccessTokens(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Accounts/:id/accessTokens"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + + /** + * Creates a new instance in rooms of this model. + * + * @param any id User id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Account` object.) + * + */ + public createManyRooms(id: any, data: Room = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Accounts/:id/rooms"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Account` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Accounts"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: Account) => new Account(instance)) + ); + } /** * @ngdoc method * @name sdk.Account#getCurrent diff --git a/tests/angular2/src/app/shared/sdk/services/custom/ApplicationCredential.ts b/tests/angular2/src/app/shared/sdk/services/custom/ApplicationCredential.ts index 9a8977d4..3134eee5 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/ApplicationCredential.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/ApplicationCredential.ts @@ -63,13 +63,13 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -78,8 +78,8 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { * This usually means the response is a `ApplicationCredential` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/ApplicationCredentials"; let routeParams: any = {}; @@ -88,13 +88,11 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: ApplicationCredential) => new ApplicationCredential(instance)) - ); + return result.map((instance: ApplicationCredential) => new ApplicationCredential(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -109,17 +107,17 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { * This usually means the response is a `ApplicationCredential` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/ApplicationCredentials"; + "/ApplicationCredentials/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: ApplicationCredential) => new ApplicationCredential(instance)); + return result; } /** @@ -149,7 +147,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -178,6 +176,39 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { return result.map((instance: ApplicationCredential) => new ApplicationCredential(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `ApplicationCredential` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/ApplicationCredentials/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -233,7 +264,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -262,7 +293,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -314,7 +345,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. * * @param any id PersistedModel id * @@ -332,7 +363,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PUT"; + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/ApplicationCredentials/:id"; let routeParams: any = { @@ -374,6 +405,37 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { return result; } + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `ApplicationCredential` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/ApplicationCredentials"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: ApplicationCredential) => new ApplicationCredential(instance)) + ); + } + /** * The name of the model represented by this $resource, diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Category.ts b/tests/angular2/src/app/shared/sdk/services/custom/Category.ts index 318c3cf2..930c83db 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/Category.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/Category.ts @@ -283,39 +283,6 @@ export class CategoryApi extends BaseLoopBackApi { return result; } - /** - * Creates a new instance in rooms of this model. - * - * @param any id PersistedModel id - * - * @param object data Request data. - * - * This method expects a subset of model properties as request parameters. - * - * @returns object[] An empty reference that will be - * populated with the actual data once the response is returned - * from the server. - * - * - * (The remote method definition does not provide any description. - * This usually means the response is a `Category` object.) - * - */ - public createManyRooms(id: any, data: Room = undefined) { - let method: string = "POST"; - let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/Categories/:id/rooms"; - let routeParams: any = { - id: id - }; - let postBody: any = { - data: data - }; - let urlParams: any = {}; - let result = this.request(method, url, routeParams, urlParams, postBody); - return result; - } - /** * Deletes all rooms of this model. * @@ -399,13 +366,13 @@ export class CategoryApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -414,8 +381,8 @@ export class CategoryApi extends BaseLoopBackApi { * This usually means the response is a `Category` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Categories"; let routeParams: any = {}; @@ -424,13 +391,11 @@ export class CategoryApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: Category) => new Category(instance)) - ); + return result.map((instance: Category) => new Category(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -445,17 +410,17 @@ export class CategoryApi extends BaseLoopBackApi { * This usually means the response is a `Category` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/Categories"; + "/Categories/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: Category) => new Category(instance)); + return result; } /** @@ -485,7 +450,7 @@ export class CategoryApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -514,6 +479,39 @@ export class CategoryApi extends BaseLoopBackApi { return result.map((instance: Category) => new Category(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Category` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Categories/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -569,7 +567,7 @@ export class CategoryApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -598,7 +596,7 @@ export class CategoryApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -650,7 +648,9 @@ export class CategoryApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. + * + * @param any id PersistedModel id * * @param object data Request data. * @@ -665,11 +665,13 @@ export class CategoryApi extends BaseLoopBackApi { * This usually means the response is a `Category` object.) * */ - public updateAttributes(data: any = undefined) { - let method: string = "PUT"; + public updateAttributes(id: any, data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Categories/:id"; - let routeParams: any = {}; + let routeParams: any = { + id: id + }; let postBody: any = { data: data }; @@ -706,6 +708,70 @@ export class CategoryApi extends BaseLoopBackApi { return result; } + /** + * Creates a new instance in rooms of this model. + * + * @param any id PersistedModel id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Category` object.) + * + */ + public createManyRooms(id: any, data: Room = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Categories/:id/rooms"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Category` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Categories"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: Category) => new Category(instance)) + ); + } + /** * The name of the model represented by this $resource, diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Like.ts b/tests/angular2/src/app/shared/sdk/services/custom/Like.ts index 93188579..c6590a7f 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/Like.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/Like.ts @@ -124,13 +124,13 @@ export class LikeApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -139,8 +139,8 @@ export class LikeApi extends BaseLoopBackApi { * This usually means the response is a `Like` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/likes"; let routeParams: any = {}; @@ -149,13 +149,11 @@ export class LikeApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: Like) => new Like(instance)) - ); + return result.map((instance: Like) => new Like(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -170,17 +168,17 @@ export class LikeApi extends BaseLoopBackApi { * This usually means the response is a `Like` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/likes"; + "/likes/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: Like) => new Like(instance)); + return result; } /** @@ -210,7 +208,7 @@ export class LikeApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -239,6 +237,39 @@ export class LikeApi extends BaseLoopBackApi { return result.map((instance: Like) => new Like(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Like` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/likes/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -294,7 +325,7 @@ export class LikeApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -323,7 +354,7 @@ export class LikeApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -375,7 +406,7 @@ export class LikeApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. * * @param any id PersistedModel id * @@ -393,7 +424,7 @@ export class LikeApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PUT"; + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/likes/:id"; let routeParams: any = { @@ -435,6 +466,37 @@ export class LikeApi extends BaseLoopBackApi { return result; } + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Like` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/likes"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: Like) => new Like(instance)) + ); + } + /** * The name of the model represented by this $resource, diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Room.ts b/tests/angular2/src/app/shared/sdk/services/custom/Room.ts index b5a2e9fa..e2d74814 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/Room.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/Room.ts @@ -11,8 +11,8 @@ import { Room, Like, Category, - Account, RoomAccount, + Account, LoopBackFilter } from '../../models/index'; import { LoopBackConfig } from '../../lb.config'; @@ -658,39 +658,6 @@ export class RoomApi extends BaseLoopBackApi { return result; } - /** - * Creates a new instance in messages of this model. - * - * @param any id PersistedModel id - * - * @param object data Request data. - * - * This method expects a subset of model properties as request parameters. - * - * @returns object[] An empty reference that will be - * populated with the actual data once the response is returned - * from the server. - * - * - * (The remote method definition does not provide any description. - * This usually means the response is a `Room` object.) - * - */ - public createManyMessages(id: any, data: any = undefined) { - let method: string = "POST"; - let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/rooms/:id/messages"; - let routeParams: any = { - id: id - }; - let postBody: any = { - data: data - }; - let urlParams: any = {}; - let result = this.request(method, url, routeParams, urlParams, postBody); - return result; - } - /** * Deletes all messages of this model. * @@ -807,39 +774,6 @@ export class RoomApi extends BaseLoopBackApi { return result; } - /** - * Creates a new instance in likes of this model. - * - * @param any id PersistedModel id - * - * @param object data Request data. - * - * This method expects a subset of model properties as request parameters. - * - * @returns object[] An empty reference that will be - * populated with the actual data once the response is returned - * from the server. - * - * - * (The remote method definition does not provide any description. - * This usually means the response is a `Room` object.) - * - */ - public createManyLikes(id: any, data: Like = undefined) { - let method: string = "POST"; - let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/rooms/:id/likes"; - let routeParams: any = { - id: id - }; - let postBody: any = { - data: data - }; - let urlParams: any = {}; - let result = this.request(method, url, routeParams, urlParams, postBody); - return result; - } - /** * Deletes all likes of this model. * @@ -956,39 +890,6 @@ export class RoomApi extends BaseLoopBackApi { return result; } - /** - * Creates a new instance in categories of this model. - * - * @param any id PersistedModel id - * - * @param object data Request data. - * - * This method expects a subset of model properties as request parameters. - * - * @returns object[] An empty reference that will be - * populated with the actual data once the response is returned - * from the server. - * - * - * (The remote method definition does not provide any description. - * This usually means the response is a `Room` object.) - * - */ - public createManyCategories(id: any, data: Category = undefined) { - let method: string = "POST"; - let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/rooms/:id/categories"; - let routeParams: any = { - id: id - }; - let postBody: any = { - data: data - }; - let urlParams: any = {}; - let result = this.request(method, url, routeParams, urlParams, postBody); - return result; - } - /** * Deletes all categories of this model. * @@ -1105,39 +1006,6 @@ export class RoomApi extends BaseLoopBackApi { return result; } - /** - * Creates a new instance in accounts of this model. - * - * @param any id PersistedModel id - * - * @param object data Request data. - * - * This method expects a subset of model properties as request parameters. - * - * @returns object[] An empty reference that will be - * populated with the actual data once the response is returned - * from the server. - * - * - * (The remote method definition does not provide any description. - * This usually means the response is a `Room` object.) - * - */ - public createManyAccounts(id: any, data: Account = undefined) { - let method: string = "POST"; - let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/rooms/:id/accounts"; - let routeParams: any = { - id: id - }; - let postBody: any = { - data: data - }; - let urlParams: any = {}; - let result = this.request(method, url, routeParams, urlParams, postBody); - return result; - } - /** * Deletes all accounts of this model. * @@ -1221,13 +1089,13 @@ export class RoomApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -1236,8 +1104,8 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms"; let routeParams: any = {}; @@ -1246,13 +1114,11 @@ export class RoomApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: Room) => new Room(instance)) - ); + return result.map((instance: Room) => new Room(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -1267,17 +1133,17 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/rooms"; + "/rooms/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: Room) => new Room(instance)); + return result; } /** @@ -1307,7 +1173,7 @@ export class RoomApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -1336,6 +1202,39 @@ export class RoomApi extends BaseLoopBackApi { return result.map((instance: Room) => new Room(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Room` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/rooms/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -1391,7 +1290,7 @@ export class RoomApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -1420,7 +1319,7 @@ export class RoomApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -1472,7 +1371,9 @@ export class RoomApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. + * + * @param any id PersistedModel id * * @param object data Request data. * @@ -1487,11 +1388,13 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public updateAttributes(data: any = undefined) { - let method: string = "PUT"; + public updateAttributes(id: any, data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id"; - let routeParams: any = {}; + let routeParams: any = { + id: id + }; let postBody: any = { data: data }; @@ -1634,6 +1537,169 @@ export class RoomApi extends BaseLoopBackApi { return result; } + /** + * Creates a new instance in messages of this model. + * + * @param any id PersistedModel id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Room` object.) + * + */ + public createManyMessages(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/rooms/:id/messages"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + + /** + * Creates a new instance in likes of this model. + * + * @param any id PersistedModel id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Room` object.) + * + */ + public createManyLikes(id: any, data: Like = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/rooms/:id/likes"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + + /** + * Creates a new instance in categories of this model. + * + * @param any id PersistedModel id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Room` object.) + * + */ + public createManyCategories(id: any, data: Category = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/rooms/:id/categories"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + + /** + * Creates a new instance in accounts of this model. + * + * @param any id PersistedModel id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Room` object.) + * + */ + public createManyAccounts(id: any, data: Account = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/rooms/:id/accounts"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Room` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/rooms"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: Room) => new Room(instance)) + ); + } + /** * The name of the model represented by this $resource, diff --git a/tests/angular2/src/app/shared/sdk/services/custom/RoomAccount.ts b/tests/angular2/src/app/shared/sdk/services/custom/RoomAccount.ts index a72f9b84..df78a3c4 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/RoomAccount.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/RoomAccount.ts @@ -125,13 +125,13 @@ export class RoomAccountApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -140,8 +140,8 @@ export class RoomAccountApi extends BaseLoopBackApi { * This usually means the response is a `RoomAccount` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/room-accounts"; let routeParams: any = {}; @@ -150,13 +150,11 @@ export class RoomAccountApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: RoomAccount) => new RoomAccount(instance)) - ); + return result.map((instance: RoomAccount) => new RoomAccount(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -171,17 +169,17 @@ export class RoomAccountApi extends BaseLoopBackApi { * This usually means the response is a `RoomAccount` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/room-accounts"; + "/room-accounts/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: RoomAccount) => new RoomAccount(instance)); + return result; } /** @@ -211,7 +209,7 @@ export class RoomAccountApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -240,6 +238,39 @@ export class RoomAccountApi extends BaseLoopBackApi { return result.map((instance: RoomAccount) => new RoomAccount(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `RoomAccount` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/room-accounts/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -295,7 +326,7 @@ export class RoomAccountApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -324,7 +355,7 @@ export class RoomAccountApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -376,7 +407,7 @@ export class RoomAccountApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. * * @param any id PersistedModel id * @@ -394,7 +425,7 @@ export class RoomAccountApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PUT"; + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/room-accounts/:id"; let routeParams: any = { @@ -436,6 +467,37 @@ export class RoomAccountApi extends BaseLoopBackApi { return result; } + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `RoomAccount` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/room-accounts"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: RoomAccount) => new RoomAccount(instance)) + ); + } + /** * The name of the model represented by this $resource, diff --git a/tests/angular2/src/app/shared/sdk/services/custom/User.ts b/tests/angular2/src/app/shared/sdk/services/custom/User.ts index f955f7be..dec5e39a 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/User.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/User.ts @@ -189,39 +189,6 @@ export class UserApi extends BaseLoopBackApi { return result; } - /** - * Creates a new instance in accessTokens of this model. - * - * @param any id User id - * - * @param object data Request data. - * - * This method expects a subset of model properties as request parameters. - * - * @returns object[] An empty reference that will be - * populated with the actual data once the response is returned - * from the server. - * - * - * (The remote method definition does not provide any description. - * This usually means the response is a `User` object.) - * - */ - public createManyAccessTokens(id: any, data: any = undefined) { - let method: string = "POST"; - let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/Users/:id/accessTokens"; - let routeParams: any = { - id: id - }; - let postBody: any = { - data: data - }; - let urlParams: any = {}; - let result = this.request(method, url, routeParams, urlParams, postBody); - return result; - } - /** * Deletes all accessTokens of this model. * @@ -305,13 +272,13 @@ export class UserApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -320,8 +287,8 @@ export class UserApi extends BaseLoopBackApi { * This usually means the response is a `User` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Users"; let routeParams: any = {}; @@ -330,13 +297,11 @@ export class UserApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: User) => new User(instance)) - ); + return result.map((instance: User) => new User(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -351,17 +316,17 @@ export class UserApi extends BaseLoopBackApi { * This usually means the response is a `User` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/Users"; + "/Users/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: User) => new User(instance)); + return result; } /** @@ -391,7 +356,7 @@ export class UserApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -420,6 +385,39 @@ export class UserApi extends BaseLoopBackApi { return result.map((instance: User) => new User(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `User` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Users/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -475,7 +473,7 @@ export class UserApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -504,7 +502,7 @@ export class UserApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -556,7 +554,7 @@ export class UserApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. * * @param any id User id * @@ -574,7 +572,7 @@ export class UserApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PUT"; + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Users/:id"; let routeParams: any = { @@ -637,7 +635,7 @@ export class UserApi extends BaseLoopBackApi { * The response body contains properties of the AccessToken created on login. * Depending on the value of `include` parameter, the body may contain additional properties: * - * - `user` - `{User}` - Data of the currently logged in user. (`include=user`) + * - `user` - `U+007BUserU+007D` - Data of the currently logged in user. (`include=user`) * * */ @@ -747,6 +745,70 @@ export class UserApi extends BaseLoopBackApi { let result = this.request(method, url, routeParams, urlParams, postBody); return result; } + + /** + * Creates a new instance in accessTokens of this model. + * + * @param any id User id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `User` object.) + * + */ + public createManyAccessTokens(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Users/:id/accessTokens"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `User` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Users"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: User) => new User(instance)) + ); + } /** * @ngdoc method * @name sdk.User#getCurrent diff --git a/tests/angular2/src/app/shared/sdk/services/custom/UserCredential.ts b/tests/angular2/src/app/shared/sdk/services/custom/UserCredential.ts index 327eb619..4086daf6 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/UserCredential.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/UserCredential.ts @@ -63,13 +63,13 @@ export class UserCredentialApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -78,8 +78,8 @@ export class UserCredentialApi extends BaseLoopBackApi { * This usually means the response is a `UserCredential` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/UserCredentials"; let routeParams: any = {}; @@ -88,13 +88,11 @@ export class UserCredentialApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: UserCredential) => new UserCredential(instance)) - ); + return result.map((instance: UserCredential) => new UserCredential(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -109,17 +107,17 @@ export class UserCredentialApi extends BaseLoopBackApi { * This usually means the response is a `UserCredential` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/UserCredentials"; + "/UserCredentials/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: UserCredential) => new UserCredential(instance)); + return result; } /** @@ -149,7 +147,7 @@ export class UserCredentialApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -178,6 +176,39 @@ export class UserCredentialApi extends BaseLoopBackApi { return result.map((instance: UserCredential) => new UserCredential(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `UserCredential` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/UserCredentials/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -233,7 +264,7 @@ export class UserCredentialApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -262,7 +293,7 @@ export class UserCredentialApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -314,7 +345,7 @@ export class UserCredentialApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. * * @param any id PersistedModel id * @@ -332,7 +363,7 @@ export class UserCredentialApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PUT"; + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/UserCredentials/:id"; let routeParams: any = { @@ -374,6 +405,37 @@ export class UserCredentialApi extends BaseLoopBackApi { return result; } + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `UserCredential` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/UserCredentials"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: UserCredential) => new UserCredential(instance)) + ); + } + /** * The name of the model represented by this $resource, diff --git a/tests/angular2/src/app/shared/sdk/services/custom/UserIdentity.ts b/tests/angular2/src/app/shared/sdk/services/custom/UserIdentity.ts index ac233ae7..a07acae1 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/UserIdentity.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/UserIdentity.ts @@ -94,13 +94,13 @@ export class UserIdentityApi extends BaseLoopBackApi { } /** - * Create a new instance of the model and persist it into the data source. + * Patch an existing model instance or insert a new one into the data source. * * @param object data Request data. * * This method expects a subset of model properties as request parameters. * - * @returns object[] An empty reference that will be + * @returns object An empty reference that will be * populated with the actual data once the response is returned * from the server. * @@ -109,8 +109,8 @@ export class UserIdentityApi extends BaseLoopBackApi { * This usually means the response is a `UserIdentity` object.) * */ - public createMany(data: any = undefined) { - let method: string = "POST"; + public upsert(data: any = undefined) { + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/UserIdentities"; let routeParams: any = {}; @@ -119,13 +119,11 @@ export class UserIdentityApi extends BaseLoopBackApi { }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instances: Array) => - instances.map((instance: UserIdentity) => new UserIdentity(instance)) - ); + return result.map((instance: UserIdentity) => new UserIdentity(instance)); } /** - * Update an existing model instance or insert a new one into the data source. + * Replace an existing model instance or insert a new one into the data source. * * @param object data Request data. * @@ -140,17 +138,17 @@ export class UserIdentityApi extends BaseLoopBackApi { * This usually means the response is a `UserIdentity` object.) * */ - public upsert(data: any = undefined) { - let method: string = "PUT"; + public replaceOrCreate(data: any = undefined) { + let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + - "/UserIdentities"; + "/UserIdentities/replaceOrCreate"; let routeParams: any = {}; let postBody: any = { data: data }; let urlParams: any = {}; let result = this.request(method, url, routeParams, urlParams, postBody); - return result.map((instance: UserIdentity) => new UserIdentity(instance)); + return result; } /** @@ -180,7 +178,7 @@ export class UserIdentityApi extends BaseLoopBackApi { } /** - * Find a model instance by id from the data source. + * Find a model instance by {{id}} from the data source. * * @param any id Model id * @@ -209,6 +207,39 @@ export class UserIdentityApi extends BaseLoopBackApi { return result.map((instance: UserIdentity) => new UserIdentity(instance)); } + /** + * Replace attributes for a model instance and persist it into the data source. + * + * @param any id Model id + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `UserIdentity` object.) + * + */ + public replaceById(id: any, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/UserIdentities/:id/replace"; + let routeParams: any = { + id: id + }; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result; + } + /** * Find all instances of the model matched by filter from the data source. * @@ -264,7 +295,7 @@ export class UserIdentityApi extends BaseLoopBackApi { } /** - * Update instances of the model matched by where from the data source. + * Update instances of the model matched by {{where}} from the data source. * * @param object where Criteria to match model instances * @@ -293,7 +324,7 @@ export class UserIdentityApi extends BaseLoopBackApi { } /** - * Delete a model instance by id from the data source. + * Delete a model instance by {{id}} from the data source. * * @param any id Model id * @@ -345,7 +376,7 @@ export class UserIdentityApi extends BaseLoopBackApi { } /** - * Update attributes for a model instance and persist it into the data source. + * Patch attributes for a model instance and persist it into the data source. * * @param any id PersistedModel id * @@ -363,7 +394,7 @@ export class UserIdentityApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PUT"; + let method: string = "PATCH"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/UserIdentities/:id"; let routeParams: any = { @@ -405,6 +436,37 @@ export class UserIdentityApi extends BaseLoopBackApi { return result; } + /** + * Create a new instance of the model and persist it into the data source. + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object[] An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `UserIdentity` object.) + * + */ + public createMany(data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/UserIdentities"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instances: Array) => + instances.map((instance: UserIdentity) => new UserIdentity(instance)) + ); + } + /** * The name of the model represented by this $resource,