import { inject , injectable } from 'inversify' ; import { ITodo } from '../interfaces/itodo' ; import { ITodoResource } from '../resources/todo.resources/itodo.resource' ; import { TYPES } from '../resources/types' ; @ injectable ( ) export class TodoService { constructor ( @ inject ( TYPES . ITodoResource ) private todoResource ) { } public addTodo ( todo ) { return this . todoResource . addTodo ( todo ) . then ( ( result ) => result ) ; } public removeTodo ( id , userId ) { return this . todoResource . removeTodo ( id , userId ) . then ( ( result ) => result ) ; } public removeAllTodos ( userId ) { return this . todoResource . removeAllTodos ( userId ) . then ( ( result ) => result ) ; } public getAllTodos ( userId , completed ) { return this . todoResource . getAllTodos ( userId ) . then ( ( todos ) => { let userTodos = todos ; if ( completed !== undefined && completed !== null ) { userTodos = completed ? todos . filter ( ( td ) => td . completed === true ) : todos . filter ( ( td ) => td . completed === false ) ; } return userTodos ; } ) ; } public changeComplete ( id , userId , completed ) { return this . todoResource . changeComplete ( id , userId , completed ) . then ( ( result ) => result ) ; } }