'use strict' ; import BaseAPI from '../../bases/BaseAPI' ; import LikeModel from '../../models/LikeModel' ; import { ILikeData } from 'teambition' ; export class LikeAPI extends BaseAPI { public getLiked ( type , _id ) { let cache = LikeModel . get ( _id ) ; if ( cache ) { let deferred = this . $q . defer ( ) ; deferred . resolve ( cache ) ; return deferred . promise ; } return this . RestAPI . get ( { Type : `${ type }s` , Id : _id , Path1 : 'like' , 'all' : 1 } ) . $promise . then ( ( data ) => { return LikeModel . set ( _id , data ) ; } ) ; } public postLike < T > ( type , detail ) { let promise ; if ( detail . like && detail . like . isLike ) { promise = this . RestAPI . delete ( { Type : `${ type }s` , Id : detail . _id , Path1 : 'like' } , { _id : detail . _id } ) . $promise ; } else { promise = this . RestAPI . save ( { Type : `${ type }s` , Id : detail . _id , Path1 : 'like' } , { _id : detail . _id } ) . $promise ; } return promise . then ( ( data ) => { LikeModel . update ( detail . _id , data ) ; } ) ; } } angular . module ( 'teambition' ) . service ( 'LikeAPI' , LikeAPI ) ;