import express from "express" ; import { getBankAccountsByUserId , getBankAccountById , createBankAccountForUser , removeBankAccountById , } from "./database" ; import { ensureAuthenticated , validateMiddleware } from "./helpers" ; import { shortIdValidation , isBankAccountValidator } from "./validators" ; const router = express . Router ( ) ; router . get ( "/" , ensureAuthenticated , ( req , res ) => { const accounts = getBankAccountsByUserId ( req . user ?. id ! ) ; res . status ( 200 ) ; res . json ( { results : accounts } ) ; } ) ; router . get ( "/:bankAccountId" , ensureAuthenticated , validateMiddleware ( [ shortIdValidation ( "bankAccountId" ) ] ) , ( req , res ) => { const { bankAccountId } = req . params ; const account = getBankAccountById ( bankAccountId ) ; res . status ( 200 ) ; res . json ( { account } ) ; } ) ; router . post ( "/" , ensureAuthenticated , validateMiddleware ( isBankAccountValidator ) , ( req , res ) => { const account = createBankAccountForUser ( req . user ?. id ! , req . body ) ; res . status ( 200 ) ; res . json ( { account } ) ; } ) ; router . delete ( "/:bankAccountId" , ensureAuthenticated , validateMiddleware ( [ shortIdValidation ( "bankAccountId" ) ] ) , ( req , res ) => { const { bankAccountId } = req . params ; const account = removeBankAccountById ( bankAccountId ) ; res . status ( 200 ) ; res . json ( { account } ) ; } ) ; export default router ;