From b58d8d119d5e03e6c7b9b01af6d02750cbbcc32d Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 22 Mar 2016 09:23:44 -0300 Subject: [PATCH] Accept post without subelement in restangular service --- src/app/article/comment/post-comment.component.ts | 4 ++-- src/lib/ng-noosfero-api/http/comment.service.ts | 2 +- src/lib/ng-noosfero-api/http/restangular_service.ts | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/article/comment/post-comment.component.ts b/src/app/article/comment/post-comment.component.ts index 1c36415..1fa5140 100644 --- a/src/app/article/comment/post-comment.component.ts +++ b/src/app/article/comment/post-comment.component.ts @@ -20,8 +20,8 @@ export class PostCommentComponent { if (this.replyOf) { this.comment.reply_of_id = this.replyOf.id; } - this.commentService.createInArticle(this.article, this.comment).then(() => { - this.$rootScope.$emit("comment.received", this.comment); + this.commentService.createInArticle(this.article, this.comment).then((result: noosfero.RestResult) => { + this.$rootScope.$emit("comment.received", result.data); this.notificationService.success({ title: "Good job!", message: "Comment saved!" }); }); } diff --git a/src/lib/ng-noosfero-api/http/comment.service.ts b/src/lib/ng-noosfero-api/http/comment.service.ts index ca1bbb9..514797c 100644 --- a/src/lib/ng-noosfero-api/http/comment.service.ts +++ b/src/lib/ng-noosfero-api/http/comment.service.ts @@ -28,6 +28,6 @@ export class CommentService extends RestangularService { createInArticle(article: noosfero.Article, comment: noosfero.Comment): ng.IPromise> { let articleElement = this.articleService.getElement(article.id); - return articleElement.customPOST(comment, this.getResourcePath(), {}, { 'Content-Type': 'application/json' }); + return this.create(comment, articleElement, null, { 'Content-Type': 'application/json' }, false); } } diff --git a/src/lib/ng-noosfero-api/http/restangular_service.ts b/src/lib/ng-noosfero-api/http/restangular_service.ts index b0256b6..b65c716 100644 --- a/src/lib/ng-noosfero-api/http/restangular_service.ts +++ b/src/lib/ng-noosfero-api/http/restangular_service.ts @@ -221,13 +221,17 @@ export abstract class RestangularService { * Creates a new Resource into the resource collection * calls POST /resourcePath */ - public create(obj: T, rootElement?: noosfero.RestModel, queryParams?: any, headers?: any): ng.IPromise> { + public create(obj: T, rootElement?: noosfero.RestModel, queryParams?: any, headers?: any, isSub: boolean = true): ng.IPromise> { let deferred = this.$q.defer>(); let restRequest: ng.IPromise>; - let data = { }; - data[this.getDataKeys().singular] = obj; + let data = {}; + if (isSub) { + data[this.getDataKeys().singular] = obj; + } else { + data = obj; + } if (rootElement) { restRequest = rootElement.all(this.getResourcePath()).post(data, queryParams, headers); -- libgit2 0.21.2