excel export (wip)
This commit is contained in:
@ -12,6 +12,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { all } from "axios";
|
||||
import { logger } from "src/helpers/common";
|
||||
import { excel } from "src/helpers/excel";
|
||||
|
||||
/**
|
||||
*
|
||||
@ -432,7 +433,13 @@ export default async function handler(req, res) {
|
||||
case "getAllPublishersWithStatistics":
|
||||
let noEndDate = common.parseBool(req.query.noEndDate);
|
||||
res.status(200).json(await dataHelper.getAllPublishersWithStatisticsMonth(day, noEndDate));
|
||||
|
||||
case "exportPublishersExcel":
|
||||
try {
|
||||
await excel.ExportPublishersToExcel(req, res);
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify(error));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
res.status(200).json({
|
||||
"message": "no action '" + action + "' found"
|
||||
|
@ -16,8 +16,6 @@ import ProtectedRoute from '../../../components/protectedRoute';
|
||||
import ConfirmationModal from '../../../components/ConfirmationModal';
|
||||
import { relative } from "path";
|
||||
import { set } from "lodash";
|
||||
import { excel } from "../../../src/helpers/excel";
|
||||
|
||||
|
||||
interface IProps {
|
||||
initialItems: Publisher[];
|
||||
@ -174,10 +172,18 @@ function PublishersPage({ publishers = [] }: IProps) {
|
||||
|
||||
const exportPublishers = async () => {
|
||||
try {
|
||||
await excel.ExportPublishersToExcel();
|
||||
const response = await axiosInstance.get('/api/?action=exportPublishersExcel');
|
||||
const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'publishers.xlsx';
|
||||
a.click();
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify(error));
|
||||
console.error(JSON.stringify(error)); // Log the error
|
||||
toast.error("Грешка при експорт на данни");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user