Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 1x | // A receipt file, after the access check in receipt-response.server.ts.
// `?download=1` sends it as an attachment.
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/api/receipts/$receiptId')({
server: {
handlers: {
// Imported on use: the modules need the Workers runtime, and the route
// tree is also loaded where there is none (unit tests, the client).
GET: async ({ request, params }) => {
const [
{ receiptResponse },
{ transactionRepository },
{ sharingRepository },
{ getRequestContext },
] = await Promise.all([
import('#/features/transactions/receipt-response.server'),
import('#/features/transactions/transaction.repository.server'),
import('#/features/sharing/sharing.repository.server'),
import('#/server/platform/context.server'),
])
const context = getRequestContext()
const session = await context.auth.getSession()
return receiptResponse(
{
userId: session?.user.id,
transactions: transactionRepository(context.db),
sharing: sharingRepository(context.db),
storage: context.storage,
},
params.receiptId,
{ download: new URL(request.url).searchParams.has('download') },
)
},
},
},
})
|