article_facility_service.ts
1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
export class ArticleFactilityService {
public static ARTICLES_RESOURCE_NAME = "articles";
resourceBase: restangular.IElement = null;
constructor(
protected restangularService: restangular.IService,
protected profile: noosfero.Profile) {
if (!profile) {
throw new Error("Could not instantiate ArticleOwner Service! Profile is missing!");
}
}
getArticles(params?: any, headers?: any): restangular.ICollectionPromise<noosfero.Article> {
return this.profile.getList<noosfero.Article>(ArticleFactilityService.ARTICLES_RESOURCE_NAME, params, headers);
}
getArticle(id: number, params?: any, headers?: any): restangular.IPromise<noosfero.Article> {
return this.profile.one(ArticleFactilityService.ARTICLES_RESOURCE_NAME, id).get(params, headers);
}
removeArticle(article: noosfero.Article, params?: any, headers?: any): restangular.IPromise<noosfero.Article> {
let element: restangular.IElement = this.restangularService.restangularizeElement(this.profile, article, ArticleFactilityService.ARTICLES_RESOURCE_NAME);
return element.remove(params, headers);
}
createArticle(article: noosfero.Article, params?: any, headers?: any): restangular.IPromise<noosfero.Article> {
return this.profile.post<noosfero.Article>(ArticleFactilityService.ARTICLES_RESOURCE_NAME, article, params, headers);
}
updateArticle(article: noosfero.Article, params?: any, headers?: any): restangular.IPromise<noosfero.Article> {
let element: restangular.IElement = this.restangularService.restangularizeElement(this.profile, article, ArticleFactilityService.ARTICLES_RESOURCE_NAME);
return element.put(params, headers);
}
}