Files
Sheep-Service/api/controllers/generator.report.territories.controller.js

32 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const getTable = require("../middleware/genReportTerritories");
class generatorReportTerritoriesController {
async getTable(req, res) {
if (req.possibilities.can_add_territory) {
let result = await getTable();
if (result) {
res.setHeader(
'Content-Disposition',
`attachment; filename*=UTF-8''${encodeURIComponent('Опрацювання_територій.xlsx')}`
);
res.setHeader(
'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
);
return res.status(200).send(result);
} else {
return res
.status(404)
.send({ message: 'Table creation error.' });
}
} else {
return res
.status(403)
.send({ message: 'The user does not have enough rights.' });
}
}
}
module.exports = new generatorReportTerritoriesController();