import { Router , Request , Response } from 'express' ; import { CategoriesRepository } from './categories.repository' ; import { InMemoryCategoriesRepository } from './in-memory-categories.repository' ; import { categoryBelongsToAccount } from './categories.middleware' ; import { User } from '../../../models/user' ; const repository = new InMemoryCategoriesRepository ( ) ; const router = Router ( ) ; router . get ( '/expense-categories/:id' , categoryBelongsToAccount ( ) , function ( req , res ) { repository . getCategory ( req . params . id ) . then ( category => res . json ( category ) ) ; } ) ; router . get ( '/expense-categories' , function ( req , res ) { const user = req . user as User ; repository . getCategories ( user . accountId as string ) . then ( categories => res . json ( categories ) ) ; } ) ; export default router ;