Skip to content

Commit

Permalink
chore(backend): remove list quotes endpoint (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonianb authored Sep 8, 2022
1 parent 5e08158 commit 668e7cb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 69 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const Config = {

openPaymentsSpec: envString(
'OPEN_PAYMENTS_SPEC',
'https://raw.githubusercontent.com/interledger/open-payments/cd3a05a08d1c5d925942f153a1532a1432a2411b/open-api-spec.yaml'
'https://raw.githubusercontent.com/interledger/open-payments/6a410518c2fe054286bb0a55b0964d80596fea5a/open-api-spec.yaml'
),
authServerSpec: envString(
'AUTH_SERVER_SPEC',
Expand Down
29 changes: 1 addition & 28 deletions packages/backend/src/open_payments/quote/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createContext } from '../../tests/context'
import { createTestApp, TestContainer } from '../../tests/app'
import { Config, IAppConfig } from '../../config/app'
import { initIocContainer } from '../..'
import { AppServices, CreateContext, ReadContext, ListContext } from '../../app'
import { AppServices, CreateContext, ReadContext } from '../../app'
import { truncateTables } from '../../tests/tableManager'
import { QuoteService } from './service'
import { Quote } from './model'
Expand All @@ -19,7 +19,6 @@ import { PaymentPointer } from '../payment_pointer/model'
import { randomAsset } from '../../tests/asset'
import { createPaymentPointer } from '../../tests/paymentPointer'
import { createQuote } from '../../tests/quote'
import { listTests } from '../../shared/routes.test'

describe('Quote Routes', (): void => {
let deps: IocContract<AppServices>
Expand Down Expand Up @@ -296,30 +295,4 @@ describe('Quote Routes', (): void => {
})
})
})

describe('list', (): void => {
listTests({
getPaymentPointer: () => paymentPointer,
getUrl: () => `/quotes`,
createItem: async (_index) => {
const quote = await createPaymentPointerQuote(paymentPointer.id)
return {
id: `${paymentPointer.url}/quotes/${quote.id}`,
paymentPointer: paymentPointer.url,
receiver: quote.receiver,
sendAmount: {
...quote.sendAmount,
value: quote.sendAmount.value.toString()
},
receiveAmount: {
...quote.receiveAmount,
value: quote.receiveAmount.value.toString()
},
expiresAt: quote.expiresAt.toISOString(),
createdAt: quote.createdAt.toISOString()
}
},
list: (ctx: ListContext) => quoteRoutes.list(ctx)
})
})
})
42 changes: 2 additions & 40 deletions packages/backend/src/open_payments/quote/routes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { Logger } from 'pino'
import { ReadContext, CreateContext, ListContext } from '../../app'
import { ReadContext, CreateContext } from '../../app'
import { IAppConfig } from '../../config/app'
import { QuoteService } from './service'
import { isQuoteError, errorToCode, errorToMessage } from './errors'
import { Quote } from './model'
import { AmountJSON, parseAmount } from '../amount'
import {
getPageInfo,
parsePaginationQueryParameters
} from '../../shared/pagination'
import { Pagination } from '../../shared/baseModel'

interface ServiceDependencies {
config: IAppConfig
Expand All @@ -20,7 +15,6 @@ interface ServiceDependencies {
export interface QuoteRoutes {
get(ctx: ReadContext): Promise<void>
create(ctx: CreateContext<CreateBody>): Promise<void>
list(ctx: ListContext): Promise<void>
}

export function createQuoteRoutes(deps_: ServiceDependencies): QuoteRoutes {
Expand All @@ -30,8 +24,7 @@ export function createQuoteRoutes(deps_: ServiceDependencies): QuoteRoutes {
const deps = { ...deps_, logger }
return {
get: (ctx: ReadContext) => getQuote(deps, ctx),
create: (ctx: CreateContext<CreateBody>) => createQuote(deps, ctx),
list: (ctx: ListContext) => listQuotes(deps, ctx)
create: (ctx: CreateContext<CreateBody>) => createQuote(deps, ctx)
}
}

Expand Down Expand Up @@ -82,37 +75,6 @@ async function createQuote(
}
}

async function listQuotes(
deps: ServiceDependencies,
ctx: ListContext
): Promise<void> {
const pagination = parsePaginationQueryParameters(ctx.request.query)
try {
const page = await deps.quoteService.getPaymentPointerPage(
ctx.paymentPointer.id,
pagination
)
const pageInfo = await getPageInfo(
(pagination: Pagination) =>
deps.quoteService.getPaymentPointerPage(
ctx.paymentPointer.id,
pagination
),
page
)
const result = {
pagination: pageInfo,
result: page.map((item: Quote) => {
item.paymentPointer = ctx.paymentPointer
return quoteToBody(deps, item)
})
}
ctx.body = result
} catch (_) {
ctx.throw(500, 'Error trying to list quotes')
}
}

function quoteToBody(deps: ServiceDependencies, quote: Quote) {
return Object.fromEntries(
Object.entries({
Expand Down

0 comments on commit 668e7cb

Please sign in to comment.