37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { Controller, Get, Header, Query} from "@nestjs/common";
|
|
import { CsvExportService } from "../services/csv-exports.service";
|
|
import { ExportCsvOptionsDto } from "../dtos/export-csv-options.dto";
|
|
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
|
import { PAY_SERVICE } from "src/common/shared/role-groupes";
|
|
|
|
|
|
@Controller('exports')
|
|
@RolesAllowed(...PAY_SERVICE)
|
|
export class CsvExportController {
|
|
constructor(private readonly csvService: CsvExportService) {}
|
|
|
|
@Get('csv')
|
|
@Header('Content-Type', 'text/csv; charset=utf-8')
|
|
@Header('Content-Disposition', 'attachment; filename="export.csv"')
|
|
async exportCsv(@Query() query: ExportCsvOptionsDto ): Promise<Buffer> {
|
|
const rows = await this.csvService.collectTransaction(
|
|
query.year,
|
|
query.period_no,
|
|
{
|
|
approved: query.approved ?? true,
|
|
types: {
|
|
shifts: query.shifts ?? true,
|
|
expenses: query.expenses ?? true,
|
|
holiday: query.holiday ?? true,
|
|
vacation: query.vacation ?? true,
|
|
},
|
|
companies: {
|
|
targo: query.targo ?? true,
|
|
solucom: query.solucom ?? true,
|
|
},
|
|
}
|
|
);
|
|
return this.csvService.generateCsv(rows);
|
|
}
|
|
|
|
} |