import firestore from '../../lib/firebase/firestore' ; import { Todo , Todos } from '../models' ; export function getAll ( userId ) { return firestore ( userId ) . get ( ) . then ( querySnapshot => { const todos = querySnapshot . docs . reduce ( ( result , doc ) => { result [ doc . id ] = doc . data ( ) as Todo . Model ; return result ; } , { } ) ; return todos ; } ) ; } export function add ( userId , newTodo ) { firestore ( userId ) . doc ( newTodo . id ) . set ( newTodo ) . catch ( e => { throw e ; } ) ; } export function remove ( userId , id ) { firestore ( userId ) . doc ( id ) . delete ( ) . catch ( e => { throw e ; } ) ; } export function toggle ( userId , id , newValue ) { firestore ( userId ) . doc ( id ) . update ( { completedAt : newValue , } ) . catch ( e => { throw e ; } ) ; } export function change ( userId , id , newValue ) { firestore ( userId ) . doc ( id ) . update ( newValue ) . catch ( e => { throw e ; } ) ; }