|
|
@ -5,9 +5,10 @@ const FileService = require('../services/file'); |
|
|
|
|
|
|
|
/* GET home page. */ |
|
|
|
router.get('/', async function(req, res, next) { |
|
|
|
const url = 'https://bodacc-datadila.opendatasoft.com/api/explore/v2.1/catalog/datasets/annonces-commerciales/exports/csv?lang=fr&refine=publicationavis%3A%22A%22&refine=publicationavis_facette%3A%22Bodacc%20A%22&refine=familleavis_lib%3A%22Ventes%20et%20cessions%22&timezone=Asia%2FBaghdad&use_labels=true&delimiter=%3B'; |
|
|
|
// const url = 'https://bodacc-datadila.opendatasoft.com/api/explore/v2.1/catalog/datasets/annonces-commerciales/exports/csv?lang=fr&refine=publicationavis%3A%22A%22&refine=publicationavis_facette%3A%22Bodacc%20A%22&refine=familleavis_lib%3A%22Ventes%20et%20cessions%22&timezone=Asia%2FBaghdad&use_labels=true&delimiter=%3B';
|
|
|
|
const url = 'https://bodacc-datadila.opendatasoft.com/api/explore/v2.1/catalog/datasets/annonces-commerciales/exports/csv?lang=fr&refine=publicationavis%3A%22A%22&refine=publicationavis_facette%3A%22Bodacc%20A%22&refine=familleavis_lib%3A%22Ventes%20et%20cessions%22&refine=numerodepartement%3A%2275%22&refine=typeavis_lib%3A%22Avis%20d%E2%80%99annulation%22&timezone=Asia%2FBaghdad&use_labels=true&delimiter=%3B'; |
|
|
|
|
|
|
|
const columns = ['id', 'region_code', 'listepersonnes.personne.typePersonne', 'listepersonnes.personne.denomination', 'listeetablissements.etablissement.adresse', 'listeprecedentproprietaire.personne.nom', 'listeprecedentproprietaire.personne.prenom']; |
|
|
|
const columns = ['id', 'region_code', 'region_nom_officiel', 'listepersonnes.personne.typePersonne', 'listepersonnes.personne.denomination', 'listepersonnes.personne.numeroImmatriculation.numeroIdentification', 'parutionavisprecedent.nomPublication', 'parutionavisprecedent.dateParution', 'dateparution']; |
|
|
|
|
|
|
|
const fileService = new FileService(); |
|
|
|
|
|
|
@ -15,13 +16,15 @@ router.get('/', async function(req, res, next) { |
|
|
|
try { |
|
|
|
stream = await fileService.parseFromUrl(url, columns); |
|
|
|
} catch (err) { |
|
|
|
console.error(err.message); |
|
|
|
console.error('routes [/] error', err.message); |
|
|
|
} |
|
|
|
|
|
|
|
if ( !stream ) { |
|
|
|
return res.status(500).send('Invalid stream'); |
|
|
|
} |
|
|
|
|
|
|
|
res.setHeader('Content-Disposition', 'attachment; filename="mon_fichier.csv"'); |
|
|
|
res.setHeader('Content-Type', 'text/csv; charset=utf-8'); |
|
|
|
stream.pipe(res); |
|
|
|
|
|
|
|
// res.render('index', { title: 'Express' });
|
|
|
|