From 1314cfb1e3a05b8d7162e9ca48129ffdede2848b Mon Sep 17 00:00:00 2001 From: Danil Zvyagintsev Date: Tue, 15 May 2018 13:59:59 -0700 Subject: [PATCH] add patch method --- README.md | 1 + lib/sails.service.ts | 37 +++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f272174..46cf03f 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ The following methods are implemented in the SailsService and will always return - get(path,data):Observable - post(path,data):Observable - put(path,data):Observable +- patch(path,data):Observable - delete(path,data):Observable - request(options):Observable - on(eventEntity):Observable diff --git a/lib/sails.service.ts b/lib/sails.service.ts index fc5eb60..3e7f476 100644 --- a/lib/sails.service.ts +++ b/lib/sails.service.ts @@ -419,6 +419,43 @@ export class SailsService { return subject.asObservable(); } + /** + * + * @param url + * @param data + * @return {Observable} + */ + patch(url, data?: any): Observable { + let self = this; + let subject = new Subject(); + + this.zone.runOutsideAngular(() => { + this._io.patch(url, data, (resData, jwres: IJWRes) => { + if (io.sails.environment != "production" && self.silent !== true) { + console.log("patch::data", resData); + console.log("patch:jwr", jwres); + } + if (jwres.statusCode < 200 || jwres.statusCode >= 400) { + subject.error({ + data: resData, + statusCode: jwres.statusCode, + response: jwres, + error: jwres.error + }) + } else { + //subject.next(resData); + this.zone.run(() => subject.next({ + data: resData, + statusCode: jwres.statusCode, + response: jwres + })); + } + subject.complete(); + }) + }); + return subject.asObservable(); + } + /** * * @param url diff --git a/package.json b/package.json index 1180e8d..9916f1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular2-sails", - "version": "0.2.8", + "version": "0.2.9", "description": "An angular module for using the sails socket.io api in angular2 (@angular) with webpack and AoT compilation", "main": "index.js", "scripts": {