community.service.ts
1.18 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
40
41
import { Injectable, Inject } from "ng-forward";
import {RestangularService} from "./restangular_service";
import {PersonService} from "./person.service";
@Injectable()
@Inject("Restangular", "$q", "$log", PersonService)
export class CommunityService extends RestangularService<noosfero.Community> {
constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService, protected personService: PersonService) {
super(Restangular, $q, $log);
}
getResourcePath() {
return "communities";
}
getDataKeys() {
return {
singular: 'community',
plural: 'communities'
};
}
getByOwner(owner: any, params?: any) {
// TODO see a better way to verify the owner type
if (owner.type === "Person") {
return this.getByPerson(owner, params);
} else {
return this.getByEnvironment(params);
}
}
getByEnvironment(params?: any) {
return this.list(null, params);
}
getByPerson(person: noosfero.Person, params?: any) {
let personElement = this.personService.getElement(person.id);
return this.list(personElement, params);
}
}