- add excel export for history transaction
This commit is contained in:
36
src/transaction/excel.controller.ts
Normal file
36
src/transaction/excel.controller.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Res,
|
||||
Header,
|
||||
Post,
|
||||
Body,
|
||||
Request, Param, ParseUUIDPipe,
|
||||
} from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { TransactionService } from './transaction.service';
|
||||
import { ExportTransactionDto } from './dto/export-transaction.dto';
|
||||
|
||||
@Controller({
|
||||
path: 'excel',
|
||||
version: '1',
|
||||
})
|
||||
export class ExcelController {
|
||||
constructor(private transactionService: TransactionService) {}
|
||||
|
||||
@Post('history-user/export/:id')
|
||||
@Header('Content-Type', 'text/xlsx')
|
||||
async exportTransactionHistory(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
@Body() exportTransactionDto: ExportTransactionDto,
|
||||
@Request() req,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
const result = await this.transactionService.exportDataExcel(
|
||||
exportTransactionDto.dateStart,
|
||||
id,
|
||||
);
|
||||
|
||||
res.download(`${result}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user