Commit b58d8d119d5e03e6c7b9b01af6d02750cbbcc32d
1 parent
5e8db4bd
Exists in
master
and in
1 other branch
Accept post without subelement in restangular service
Showing
3 changed files
with
10 additions
and
6 deletions
Show diff stats
src/app/article/comment/post-comment.component.ts
@@ -20,8 +20,8 @@ export class PostCommentComponent { | @@ -20,8 +20,8 @@ export class PostCommentComponent { | ||
20 | if (this.replyOf) { | 20 | if (this.replyOf) { |
21 | this.comment.reply_of_id = this.replyOf.id; | 21 | this.comment.reply_of_id = this.replyOf.id; |
22 | } | 22 | } |
23 | - this.commentService.createInArticle(this.article, this.comment).then(() => { | ||
24 | - this.$rootScope.$emit("comment.received", this.comment); | 23 | + this.commentService.createInArticle(this.article, this.comment).then((result: noosfero.RestResult<noosfero.Comment>) => { |
24 | + this.$rootScope.$emit("comment.received", result.data); | ||
25 | this.notificationService.success({ title: "Good job!", message: "Comment saved!" }); | 25 | this.notificationService.success({ title: "Good job!", message: "Comment saved!" }); |
26 | }); | 26 | }); |
27 | } | 27 | } |
src/lib/ng-noosfero-api/http/comment.service.ts
@@ -28,6 +28,6 @@ export class CommentService extends RestangularService<noosfero.Comment> { | @@ -28,6 +28,6 @@ export class CommentService extends RestangularService<noosfero.Comment> { | ||
28 | 28 | ||
29 | createInArticle(article: noosfero.Article, comment: noosfero.Comment): ng.IPromise<noosfero.RestResult<noosfero.Comment>> { | 29 | createInArticle(article: noosfero.Article, comment: noosfero.Comment): ng.IPromise<noosfero.RestResult<noosfero.Comment>> { |
30 | let articleElement = this.articleService.getElement(<number>article.id); | 30 | let articleElement = this.articleService.getElement(<number>article.id); |
31 | - return articleElement.customPOST(comment, this.getResourcePath(), {}, { 'Content-Type': 'application/json' }); | 31 | + return this.create(comment, articleElement, null, { 'Content-Type': 'application/json' }, false); |
32 | } | 32 | } |
33 | } | 33 | } |
src/lib/ng-noosfero-api/http/restangular_service.ts
@@ -221,13 +221,17 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | @@ -221,13 +221,17 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | ||
221 | * Creates a new Resource into the resource collection | 221 | * Creates a new Resource into the resource collection |
222 | * calls POST /resourcePath | 222 | * calls POST /resourcePath |
223 | */ | 223 | */ |
224 | - public create(obj: T, rootElement?: noosfero.RestModel, queryParams?: any, headers?: any): ng.IPromise<noosfero.RestResult<T>> { | 224 | + public create(obj: T, rootElement?: noosfero.RestModel, queryParams?: any, headers?: any, isSub: boolean = true): ng.IPromise<noosfero.RestResult<T>> { |
225 | let deferred = this.$q.defer<noosfero.RestResult<T>>(); | 225 | let deferred = this.$q.defer<noosfero.RestResult<T>>(); |
226 | 226 | ||
227 | let restRequest: ng.IPromise<noosfero.RestResult<T>>; | 227 | let restRequest: ng.IPromise<noosfero.RestResult<T>>; |
228 | 228 | ||
229 | - let data = <any>{ }; | ||
230 | - data[this.getDataKeys().singular] = obj; | 229 | + let data = <any>{}; |
230 | + if (isSub) { | ||
231 | + data[this.getDataKeys().singular] = obj; | ||
232 | + } else { | ||
233 | + data = obj; | ||
234 | + } | ||
231 | 235 | ||
232 | if (rootElement) { | 236 | if (rootElement) { |
233 | restRequest = rootElement.all(this.getResourcePath()).post(data, queryParams, headers); | 237 | restRequest = rootElement.all(this.getResourcePath()).post(data, queryParams, headers); |