import { Service } from "typedi" ; import { Category } from "../model/Category" ; @ Service ( ) export class CategoryRepository { private categories = [ new Category ( 1 , "Society" ) , new Category ( 2 , "Technology" ) , new Category ( 3 , "Politics" ) , new Category ( 4 , "Economy" ) , new Category ( 5 , "Sports" ) , ] ; findAll ( ) { return Promise . resolve ( this . categories ) ; } findOne ( id ) { let foundCategory = undefined ; this . categories . forEach ( category => { if ( category . id === id ) foundCategory = category ; } ) ; return foundCategory ; } save ( category ) { this . categories . push ( category ) ; return category ; } remove ( id ) { const category = this . findOne ( id ) ; if ( category ) this . categories . splice ( this . categories . indexOf ( category ) , 1 ) ; return category ; } }