'use strict' ; import BaseAPI from '../../bases/BaseAPI' ; import ActivityModel from '../../models/ActivityModel' ; import { IActivityData , IActivitySaveData } from 'teambition' ; import { fields } from './fields' ; export class ActivityAPI extends BaseAPI { public fetch ( _boundToObjectType , _boundToObjectId ) { let activities = ActivityModel . getByObjectId ( _boundToObjectId ) ; let deferred = this . $q . defer < IActivityData [ ] > ( ) ; if ( activities ) { deferred . resolve ( activities ) ; return deferred . promise ; } return this . RestAPI . query ( { Type : `${ _boundToObjectType }s` , Id : _boundToObjectId , Path1 : 'activities' , fields : fields . activityFileds } ) . $promise . then ( ( data ) => { ActivityModel . setActivities ( _boundToObjectId , data ) ; return data ; } ) ; } public save ( data ) { return this . RestAPI . save ( { Type : 'activities' } , data ) . $promise ; } } angular . module ( 'teambition' ) . service ( 'ActivityAPI' , ActivityAPI ) ;