blob: d927f8c1811da47b4c7d3cc050836fa1a2168c41 [file] [log] [blame]
Matteo Scandolocb466ed2017-01-04 17:16:24 -08001import {IXosModelDefsField} from '../../core/services/helpers/config.helpers';
Matteo Scandolo828d1e82017-01-17 14:49:38 -08002import {IXosAppConfig} from '../../../index';
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08003
4export interface IModeldef {
Matteo Scandolocb466ed2017-01-04 17:16:24 -08005 fields: IXosModelDefsField[];
6 relations?: string[];
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08007 name: string;
8}
9
10export interface IModeldefsService {
11 get(): Promise<IModeldef[]>;
12}
13
14export class ModeldefsService {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080015
16 static $inject = ['$http', '$q', 'AppConfig'];
17
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080018 constructor(
19 private $http: angular.IHttpService,
20 private $q: angular.IQService,
Matteo Scandolo828d1e82017-01-17 14:49:38 -080021 private AppConfig: IXosAppConfig
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080022 ) {
23 }
24
25 public get(): Promise<any> {
26 const d = this.$q.defer();
Matteo Scandolo828d1e82017-01-17 14:49:38 -080027 this.$http.get(`${this.AppConfig.apiEndpoint}/utility/modeldefs/`)
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080028 .then((res) => {
29 d.resolve(res.data);
30 })
31 .catch(e => {
32 d.reject(e);
33 });
34 return d.promise;
35 }
36}