diff --git a/common/models/category.js b/common/models/category.js index 4425169a8c51afcac1f62e838ffbc72acb20c11a..86cbfd695d4efe9e92ba3f5301f16ab4e0b20679 100644 --- a/common/models/category.js +++ b/common/models/category.js @@ -21,7 +21,7 @@ along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. 'use strict'; module.exports = function(Category) { - Category.csvexport = function(type, res, callback ) { + Category.csvexport = function(res, callback ) { var datetime = new Date(); var datetimeFuture = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate()+7) res.set('Expires', datetimeFuture+''); @@ -33,10 +33,9 @@ module.exports = function(Category) { res.set('Content-Disposition','attachment;filename=category.csv'); res.set('Content-Transfer-Encoding','binary'); - Category.find(function(err, categories) { + Category.find(function(err, categories) + { // conversão JSON para CSV - var itemsFormatted = []; - // cabeçalho do csv var headers = { category_name: "category_name", @@ -44,19 +43,10 @@ module.exports = function(Category) { id: "id" }; - categories.forEach((item) => { - itemsFormatted.push({ - category_name: item.category_name, - category_description: item.category_description, - id: item.id - }); - }); - - if (headers) { - itemsFormatted.unshift(headers); - } + //Adiciona os headers no CSV + categories.unshift(headers); - var jsonObject = JSON.stringify(itemsFormatted); + var jsonObject = JSON.stringify(categories); var array = typeof jsonObject != 'object' ? JSON.parse(jsonObject) : jsonObject; var csv = ''; @@ -66,7 +56,7 @@ module.exports = function(Category) { if (line != '') line += ';' // aqui muda o separador do csv line += array[i][index]; } - csv += line + '\r\n'; + csv += line + '\n'; } res.send(csv); }); @@ -75,11 +65,9 @@ module.exports = function(Category) { Category.remoteMethod('csvexport', { accepts: [ - {arg: 'type', type: 'string', required: false}, {arg: 'res', type: 'object', 'http': {source: 'res'}} ], returns: {}, - // Para usar o 'type' -> http: {path: '/csv/:type', verb: 'get'} http: {path: '/csv', verb: 'get'}, }); }; diff --git a/common/models/geolocation.js b/common/models/geolocation.js index f2249bc51ea153ad64806a605f174f060ee4c254..cbf8f0f3c8e71538346ff289d0b3fd4784b12da7 100644 --- a/common/models/geolocation.js +++ b/common/models/geolocation.js @@ -36,7 +36,6 @@ module.exports = function(Geolocation) { Geolocation.find(function(err, geolocations) { // conversão JSON para CSV - var itemsFormatted = []; // cabeçalho do csv var headers = { category_id: "category_id",