import { Controller, Get, Res, UseGuards } from '@nestjs/common'; import type { Response } from 'express'; import { JwtAuthGuard } from '../auth/jwt-auth.guard'; import { FullAccessGuard } from '../auth/full-access.guard'; import { ExportService } from './export.service'; @Controller('export') @UseGuards(JwtAuthGuard, FullAccessGuard) export class ExportController { constructor(private readonly exportService: ExportService) {} @Get('projects.xlsx') async projectsXlsx(@Res() res: Response) { const { buffer, filename } = await this.exportService.buildWorkbook(); res.setHeader( 'Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); res.setHeader( 'Content-Disposition', `attachment; filename="${filename}"; filename*=UTF-8''${encodeURIComponent(filename)}`, ); res.send(buffer); } }