Changeset View
Changeset View
Standalone View
Standalone View
src/app/_services/post.service.ts
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | return this.httpService.POST('/areas/' + area + '/' + post.id + '/', body) | ||||
const comment = Comment.parse(response); | const comment = Comment.parse(response); | ||||
post.comments.push(comment); | post.comments.push(comment); | ||||
this.navBarService.clearInputs.next(true); | this.navBarService.clearInputs.next(true); | ||||
return comment; | return comment; | ||||
}) | }) | ||||
.catch((err) => { | .catch((err) => { | ||||
return Observable.of(new CommentError( | return Observable.of(new CommentError( | ||||
JSON.parse(err._body).non_field_errors, | err.error.non_field_errors, | ||||
JSON.parse(err._body).text | err.error.text | ||||
)); | )); | ||||
}); | }); | ||||
} | } | ||||
createPost(area: string, text: string, anonymous: boolean, image: string, | createPost(area: string, text: string, anonymous: boolean, image: string, | ||||
draft: boolean = false, postID: number = null): Observable<Post> { | draft: boolean = false, postID: number = null): Observable<Post> { | ||||
let body: any; | let body: any; | ||||
if (image === '') { | if (image === '') { | ||||
Show All 15 Lines | createPost(area: string, text: string, anonymous: boolean, image: string, | ||||
if (!draft && postID === null) { | if (!draft && postID === null) { | ||||
return this.httpService.POST('/areas/' + area + '/', body) | return this.httpService.POST('/areas/' + area + '/', body) | ||||
.map((response: Response) => { | .map((response: Response) => { | ||||
return Post.parse(response); | return Post.parse(response); | ||||
}) | }) | ||||
.catch((error) => { | .catch((error) => { | ||||
return Observable.of(new PostError( | return Observable.of(new PostError( | ||||
JSON.parse(error._body).non_field_errors, | error.error.non_field_errors, | ||||
JSON.parse(error._body)._text | error.error._text | ||||
)); | )); | ||||
}); | }); | ||||
} else if (draft && postID === null) { | } else if (draft && postID === null) { | ||||
return this.httpService.POST('/areas/' + area + '/drafts/', body) | return this.httpService.POST('/areas/' + area + '/drafts/', body) | ||||
.map((response: Response) => { | .map((response: Response) => { | ||||
return Post.parse(response); | return Post.parse(response); | ||||
}) | }) | ||||
.catch((error) => { | .catch((error) => { | ||||
return Observable.of(new PostError( | return Observable.of(new PostError( | ||||
JSON.parse(error._body).non_field_errors, | error.error.non_field_errors, | ||||
JSON.parse(error._body)._text | error.error._text | ||||
)); | )); | ||||
}); | }); | ||||
} else if (draft && postID !== null) { | } else if (draft && postID !== null) { | ||||
return this.httpService.PATCH('/areas/' + area + '/drafts/' + postID + '/', body) | return this.httpService.PATCH('/areas/' + area + '/drafts/' + postID + '/', body) | ||||
.map((response: Response) => { | .map((response: Response) => { | ||||
return Post.parse(response); | return Post.parse(response); | ||||
}) | }) | ||||
.catch((error) => { | .catch((error) => { | ||||
return Observable.of(new PostError( | return Observable.of(new PostError( | ||||
JSON.parse(error._body).non_field_errors, | error.error.non_field_errors, | ||||
JSON.parse(error._body)._text | error.error._text | ||||
)); | )); | ||||
}); | }); | ||||
} else { | } else { | ||||
throw new Error('Don\'t set postID, if not a draft'); | throw new Error('Don\'t set postID, if not a draft'); | ||||
} | } | ||||
} | } | ||||
deleteImage(image: any, postID: number, area: string, text: string) { | deleteImage(image: any, postID: number, area: string, text: string) { | ||||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |