import { Observable } from 'rxjs/Observable' ; import { LikeSchema } from '../../schemas/Like' ; import { SDKFetch } from '../../SDKFetch' ; import { SDK } from '../../SDK' ; import { DetailObjectId , DetailObjectType } from 'teambition-types' ; export function toggleLikeFetch ( this , objectType , objectId , isLike ) { const fetchNamespace = objectType !== 'entry' ? `${ objectType }s` : 'entries' ; const uri = `${ fetchNamespace }/${ objectId }/like` ; const dist = isLike ? this . delete < LikeSchema > ( uri ) : this . post < LikeSchema > ( uri ) ; return dist . map ( r => { r . _id = `${ objectId }:like` ; return r ; } ) ; } SDKFetch . prototype . toggleLike = toggleLikeFetch ; declare module '../../SDKFetch' { interface SDKFetch { toggleLike : typeof toggleLikeFetch ; } } export function toggleLike ( this , objectType , objectId , isLike ) { return this . lift ( { request : this . fetch . toggleLike ( objectType , objectId , isLike ) , tableName : 'Like' , method : 'update' , clause : { _id : `${ objectId }:like` } } ) ; } SDK . prototype . toggleLike = toggleLike ; declare module '../../SDK' { interface SDK { toggleLike : typeof toggleLike ; } }