44 lines
2.0 KiB
TypeScript
44 lines
2.0 KiB
TypeScript
import { Controller, Get, Header, Query, UseGuards } from "@nestjs/common";
|
|
import { RolesGuard } from "src/common/guards/roles.guard";
|
|
import { Roles as RoleEnum } from '.prisma/client';
|
|
import { CsvExportService } from "../services/csv-exports.service";
|
|
// import { ExportCompany, ExportCsvOptionsDto, ExportType } from "../dtos/export-csv-options.dto";
|
|
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
|
|
|
|
|
@Controller('exports')
|
|
@UseGuards(RolesGuard)
|
|
export class CsvExportController {
|
|
constructor(private readonly csvService: CsvExportService) {}
|
|
|
|
// @Get('csv/:year/:period_no')
|
|
// @Header('Content-Type', 'text/csv; charset=utf-8')
|
|
// @Header('Content-Disposition', 'attachment; filename="export.csv"')
|
|
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.ACCOUNTING, RoleEnum.HR)
|
|
// async exportCsv(@Query() options: ExportCsvOptionsDto,
|
|
// @Query('period') periodId: string ): Promise<Buffer> {
|
|
// //modify to accept year and period_number
|
|
// //sets default values
|
|
// const companies = options.companies && options.companies.length ? options.companies :
|
|
// [ ExportCompany.TARGO, ExportCompany.SOLUCOM];
|
|
// const types = options.type && options.type.length ? options.type :
|
|
// Object.values(ExportType);
|
|
|
|
// //collects all
|
|
// const all = await this.csvService.collectTransaction(Number(periodId), companies);
|
|
|
|
// //filters by type
|
|
// const filtered = all.filter(row => {
|
|
// switch (row.bank_code.toLocaleLowerCase()) {
|
|
// case 'holiday' : return types.includes(ExportType.HOLIDAY);
|
|
// case 'vacation' : return types.includes(ExportType.VACATION);
|
|
// case 'expenses' : return types.includes(ExportType.EXPENSES);
|
|
// default : return types.includes(ExportType.SHIFTS);
|
|
// }
|
|
// });
|
|
|
|
// //generating the csv file
|
|
// return this.csvService.generateCsv(filtered);
|
|
// }
|
|
|
|
} |