File

apps/recallassess/recallassess-api/src/api/admin/invoice/invoice.controller.ts

Prefix

api/admin/invoice

Extends

Index

Methods

Methods

Async downloadPdf
downloadPdf(id: number, authorization: string | undefined, reply: FastifyReply)
Decorators :
@Get('download-pdf/:id')

Stream invoice PDF as attachment so the browser downloads the file instead of opening an S3 URL. Use this for UAT/production so "Download PDF" triggers a real file download.

Parameters :
Name Type Optional
id number No
authorization string | undefined No
reply FastifyReply No
Returns : unknown
Async generatePdf
generatePdf(id: number, authorization: string | undefined)
Decorators :
@Get('generate-pdf/:id')
Parameters :
Name Type Optional
id number No
authorization string | undefined No
Returns : unknown
Async refreshFromStripe
refreshFromStripe(id: number)
Decorators :
@Post(':id/refresh-from-stripe')

Admin action: refresh invoice fields from Stripe (amounts, fees, periods, ids) using its Stripe invoice id.

Parameters :
Name Type Optional
id number No
Returns : unknown
import { BaseController } from "@bish-nest/core/controller/base.controller";
import { Controller, Get, Headers, Param, ParseIntPipe, Post, Res } from "@nestjs/common";
import { FastifyReply } from "fastify";
import { InvoiceService } from "./invoice.service";

@Controller("api/admin/invoice")
export class InvoiceController extends BaseController<InvoiceService> {
  constructor(private invoiceService: InvoiceService) {
    super(invoiceService);
  }

  @Get("generate-pdf/:id")
  async generatePdf(
    @Param("id", ParseIntPipe) id: number,
    @Headers("authorization") authorization: string | undefined,
  ) {
    return this.invoiceService.generatePdf(id, authorization);
  }

  /**
   * Stream invoice PDF as attachment so the browser downloads the file instead of opening an S3 URL.
   * Use this for UAT/production so "Download PDF" triggers a real file download.
   */
  @Get("download-pdf/:id")
  async downloadPdf(
    @Param("id", ParseIntPipe) id: number,
    @Headers("authorization") authorization: string | undefined,
    @Res() reply: FastifyReply,
  ) {
    const { buffer, filename } = await this.invoiceService.getPdfBuffer(id, authorization);
    const safeName = filename.replace(/"/g, "%22");
    reply.header("Content-Type", "application/pdf");
    reply.header("Content-Disposition", `attachment; filename="${safeName}"`);
    return reply.send(buffer);
  }

  /**
   * Admin action: refresh invoice fields from Stripe (amounts, fees, periods, ids) using its Stripe invoice id.
   */
  @Post(":id/refresh-from-stripe")
  async refreshFromStripe(@Param("id", ParseIntPipe) id: number) {
    return this.invoiceService.refreshFromStripe(id);
  }
}

results matching ""

    No results matching ""