Ubuntu
9 months ago
17 changed files with 2051 additions and 1960 deletions
File diff suppressed because it is too large
@ -0,0 +1,16 @@ |
|||||
|
/*! |
||||
|
* Bootstrap v5.3.2 (https://getbootstrap.com/) |
||||
|
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) |
||||
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
* jQuery JavaScript Library v3.7.1 |
||||
|
* https://jquery.com/ |
||||
|
* |
||||
|
* Copyright OpenJS Foundation and other contributors |
||||
|
* Released under the MIT license |
||||
|
* https://jquery.org/license |
||||
|
* |
||||
|
* Date: 2023-08-28T13:37Z |
||||
|
*/ |
@ -0,0 +1,17 @@ |
|||||
|
{ |
||||
|
"sendgrid": { |
||||
|
"to": [ |
||||
|
{ |
||||
|
"email": "onja@blastream.com" |
||||
|
}, |
||||
|
{ |
||||
|
"email": "onja.asmad@gmail.com" |
||||
|
} |
||||
|
], |
||||
|
"from": "contact@blastream.com", |
||||
|
"fromName": "Blastream", |
||||
|
"uri": "https://api.sendgrid.com/v3/mail/send", |
||||
|
"application_key": "YABUthwqTla79YQbR7gToQ", |
||||
|
"application_secret": "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" |
||||
|
} |
||||
|
} |
@ -1,141 +1,148 @@ |
|||||
var express = require('express'); |
var express = require("express"); |
||||
var router = express.Router(); |
var router = express.Router(); |
||||
|
|
||||
const FileService = require('../services/file'); |
const FileService = require("../services/file"); |
||||
const TemplateService = require('../services/template'); |
const TemplateService = require("../services/template"); |
||||
|
|
||||
const templateService = new TemplateService(); |
const templateService = new TemplateService(); |
||||
const fileService = new FileService(); |
const fileService = new FileService(); |
||||
|
let initialSelectedColumns = [ |
||||
|
"region_code", |
||||
|
"region_nom_officiel", |
||||
|
"numerodepartement", |
||||
|
"departement_nom_officiel", |
||||
|
"cp", |
||||
|
"listepersonnes.personne.typePersonne", |
||||
|
"listepersonnes.personne.formeJuridique", |
||||
|
"listepersonnes.personne.denomination", |
||||
|
"listepersonnes.personne.numeroImmatriculation.codeRCS", |
||||
|
"listepersonnes.personne.numeroImmatriculation.numeroIdentification", |
||||
|
"listepersonnes.personne.nom", |
||||
|
"listepersonnes.personne.nomCommercial", |
||||
|
"listepersonnes.personne.prenom", |
||||
|
"listeetablissements.etablissement.activite", |
||||
|
"listeetablissements.etablissement.adresse.complGeographique", |
||||
|
"listeetablissements.etablissement.adresse.ville", |
||||
|
"acte.dateCommencementActivite", |
||||
|
"acte.vente.publiciteLegale.date", |
||||
|
"acte.descriptif", |
||||
|
"acte.vente.categorieVente", |
||||
|
]; |
||||
|
|
||||
/* GET home page. */ |
const data = { |
||||
router.get('/', async function(req, res, next) { |
|
||||
fileService.checkLastOperationDate(); |
|
||||
|
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8'); |
|
||||
|
|
||||
const data = { |
|
||||
form: { |
form: { |
||||
url: { |
url: { |
||||
value: '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' |
value: |
||||
|
"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", |
||||
}, |
}, |
||||
columns: { |
columns: { |
||||
options: [ |
options: [ |
||||
'id', |
"id", |
||||
'publicationavis', |
"publicationavis", |
||||
'publicationavis_facette', |
"publicationavis_facette", |
||||
'parution', |
"parution", |
||||
'dateparution', |
"dateparution", |
||||
'numeroannonce', |
"numeroannonce", |
||||
'typeavis', |
"typeavis", |
||||
'typeavis_lib', |
"typeavis_lib", |
||||
'familleavis', |
"familleavis", |
||||
'familleavis_lib', |
"familleavis_lib", |
||||
'tribunal', |
"tribunal", |
||||
'commercant', |
"commercant", |
||||
'ville', |
"ville", |
||||
'registre', |
"registre", |
||||
'pdf_parution_subfolder', |
"pdf_parution_subfolder", |
||||
'ispdf_unitaire', |
"ispdf_unitaire", |
||||
'listepersonnes.personne.administration', |
"listepersonnes.personne.administration", |
||||
'listepersonnes.personne.numeroImmatriculation.nomGreffeImmat', |
"listepersonnes.personne.numeroImmatriculation.nomGreffeImmat", |
||||
'listepersonnes.personne.capital.devise', |
"listepersonnes.personne.capital.devise", |
||||
'listepersonnes.personne.capital.montantCapital', |
"listepersonnes.personne.capital.montantCapital", |
||||
'listepersonnes.personne.adresseSiegeSocial.ville', |
"listepersonnes.personne.adresseSiegeSocial.ville", |
||||
'listepersonnes.personne.adresseSiegeSocial.codePostal', |
"listepersonnes.personne.adresseSiegeSocial.codePostal", |
||||
'listepersonnes.personne.adresseSiegeSocial.pays', |
"listepersonnes.personne.adresseSiegeSocial.pays", |
||||
'listepersonnes.personne.adresseSiegeSocial.typeVoie', |
"listepersonnes.personne.adresseSiegeSocial.typeVoie", |
||||
'listepersonnes.personne.adresseSiegeSocial.numeroVoie', |
"listepersonnes.personne.adresseSiegeSocial.numeroVoie", |
||||
'listepersonnes.personne.adresseSiegeSocial.nomVoie', |
"listepersonnes.personne.adresseSiegeSocial.nomVoie", |
||||
'listepersonnes.personne.adresseSiegeSocial.complGeographique', |
"listepersonnes.personne.adresseSiegeSocial.complGeographique", |
||||
'listeetablissements.etablissement.qualiteEtablissement', |
"listeetablissements.etablissement.qualiteEtablissement", |
||||
'listeetablissements.etablissement.adresse.codePostal', |
"listeetablissements.etablissement.adresse.codePostal", |
||||
'listeetablissements.etablissement.adresse.pays', |
"listeetablissements.etablissement.adresse.pays", |
||||
'listeetablissements.etablissement.adresse.typeVoie', |
"listeetablissements.etablissement.adresse.typeVoie", |
||||
'listeetablissements.etablissement.adresse.numeroVoie', |
"listeetablissements.etablissement.adresse.numeroVoie", |
||||
'listeetablissements.etablissement.adresse.nomVoie', |
"listeetablissements.etablissement.adresse.nomVoie", |
||||
'jugement', |
"jugement", |
||||
'acte.vente.publiciteLegale.titre', |
"acte.dateImmatriculation", |
||||
'acte.vente.opposition', |
"acte.vente.publiciteLegale.titre", |
||||
'modificationsgenerales', |
"acte.vente.opposition", |
||||
'radiationaurcs', |
"acte.vente.dateEffet", |
||||
'depot', |
"modificationsgenerales", |
||||
'listeprecedentexploitant.personne.typePersonne', |
"radiationaurcs", |
||||
'listeprecedentexploitant.personne.numeroImmatriculation.codeRCS', |
"depot", |
||||
'listeprecedentexploitant.personne.numeroImmatriculation.numeroIdentification', |
"listeprecedentexploitant.personne.typePersonne", |
||||
'listeprecedentexploitant.personne.numeroImmatriculation.nomGreffeImmat', |
"listeprecedentexploitant.personne.numeroImmatriculation.codeRCS", |
||||
'listeprecedentexploitant.personne.denomination', |
"listeprecedentexploitant.personne.numeroImmatriculation.numeroIdentification", |
||||
'listeprecedentproprietaire.personne.typePersonne', |
"listeprecedentexploitant.personne.numeroImmatriculation.nomGreffeImmat", |
||||
'listeprecedentproprietaire.personne.numeroImmatriculation.codeRCS', |
"listeprecedentexploitant.personne.denomination", |
||||
'listeprecedentproprietaire.personne.numeroImmatriculation.numeroIdentification', |
"listeprecedentproprietaire.personne.typePersonne", |
||||
'listeprecedentproprietaire.personne.numeroImmatriculation.nomGreffeImmat', |
"listeprecedentproprietaire.personne.numeroImmatriculation.codeRCS", |
||||
'listeprecedentproprietaire.personne.denomination', |
"listeprecedentproprietaire.personne.numeroImmatriculation.numeroIdentification", |
||||
'divers', |
"listeprecedentproprietaire.personne.numeroImmatriculation.nomGreffeImmat", |
||||
'parutionavisprecedent.nomPublication', |
"listeprecedentproprietaire.personne.denomination", |
||||
'parutionavisprecedent.dateParution', |
"divers", |
||||
'parutionavisprecedent.numeroParution', |
"parutionavisprecedent.nomPublication", |
||||
'parutionavisprecedent.numeroAnnonce', |
"parutionavisprecedent.dateParution", |
||||
|
"parutionavisprecedent.numeroParution", |
||||
|
"parutionavisprecedent.numeroAnnonce", |
||||
], |
], |
||||
selected: [ |
selected: initialSelectedColumns, |
||||
'region_code', |
}, |
||||
'region_nom_officiel', |
}, |
||||
'numerodepartement', |
}; |
||||
'departement_nom_officiel', |
/* GET home page. */ |
||||
'cp', |
router.get("/", async function (req, res, next) { |
||||
'listepersonnes.personne.typePersonne', |
fileService.checkLastOperationDate(); |
||||
'listepersonnes.personne.formeJuridique', |
|
||||
'listepersonnes.personne.denomination', |
res.setHeader("Content-Type", "text/html; charset=utf-8"); |
||||
'listepersonnes.personne.numeroImmatriculation.codeRCS', |
|
||||
'listepersonnes.personne.numeroImmatriculation.numeroIdentification', |
|
||||
'listepersonnes.personne.nom', |
|
||||
'listepersonnes.personne.nomCommercial', |
|
||||
'listepersonnes.personne.prenom', |
|
||||
'listeetablissements.etablissement.activite', |
|
||||
'listeetablissements.etablissement.adresse.complGeographique', |
|
||||
'listeetablissements.etablissement.adresse.ville', |
|
||||
'acte.dateCommencementActivite', |
|
||||
'acte.vente.publiciteLegale.date', |
|
||||
'acte.descriptif', |
|
||||
'acte.vente.categorieVente', |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
res.send(templateService.renderPage('index', data)); |
res.send(templateService.renderPage("index", data)); |
||||
return res; |
return res; |
||||
}); |
}); |
||||
|
|
||||
router.post('/', async function(req, res, next) { |
// Logic to handle the drag and drop update
|
||||
|
router.post("/update-columns-order", async function (req, res, next) { |
||||
|
let newColumnsOrder = req.body.columnsOrder; |
||||
|
data.form.columns.selected = newColumnsOrder; |
||||
|
// Handle saving the new column order to a database or file if necessary
|
||||
|
res.send("Columns order updated successfully"); |
||||
|
}); |
||||
|
|
||||
|
router.post("/", 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';
|
||||
|
|
||||
// get url from form
|
// get url from form
|
||||
// get columns from form
|
// get columns from form
|
||||
const url = req.body.url || ''; |
const url = req.body.url || ""; |
||||
const columns = req.body.columns || []; |
const columns = req.body.columns || []; |
||||
|
|
||||
if ( !url ) { |
if (!url) { |
||||
return res.status(500).send('Invalid url'); |
return res.status(500).send("Invalid url"); |
||||
} |
} |
||||
if ( !columns ) { |
if (!columns) { |
||||
return res.status(500).send('Invalid columns'); |
return res.status(500).send("Invalid columns"); |
||||
} |
} |
||||
|
|
||||
let stream = null; |
fileService |
||||
try { |
.parseFromUrl(url, columns) |
||||
stream = await fileService.parseFromUrl(url, columns); |
.then((filename) => { |
||||
} catch (err) { |
res.send({ |
||||
console.error('routes [/] error', err.message); |
generated: filename, |
||||
} |
message: "Fichier généré avec success", |
||||
|
}); |
||||
if ( !stream ) { |
}) |
||||
return res.status(500).send('Invalid stream'); |
.catch((err) => { |
||||
} |
console.error("routes [/] error", err.message); |
||||
|
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' });
|
|
||||
}); |
}); |
||||
|
|
||||
module.exports = router; |
module.exports = router; |
||||
|
@ -0,0 +1,129 @@ |
|||||
|
const emitter = require("../services/eventEmitter"); |
||||
|
const axios = require("axios"); |
||||
|
|
||||
|
const params = require("../config/params"); |
||||
|
const TemplateService = require("../services/template"); |
||||
|
const templateService = new TemplateService(); |
||||
|
|
||||
|
const errorResponse = (error) => { |
||||
|
if (error.response) { |
||||
|
return error.response.status + " - " + error.response.statusText; |
||||
|
} else if (error.request) { |
||||
|
// The request was made but no response was received
|
||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||
|
// http.ClientRequest in node.js
|
||||
|
return error.request; |
||||
|
} else { |
||||
|
return error.message; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
module.exports = (app) => { |
||||
|
// Get app url
|
||||
|
let host = ""; |
||||
|
app.use((req, res, next) => { |
||||
|
console.log("--- APP_URL ---", req.protocol + "://" + req.get("host")); |
||||
|
host = req.protocol + "://" + req.get("host"); |
||||
|
next(); |
||||
|
}); |
||||
|
|
||||
|
// Check if sendgrid params exists
|
||||
|
if (!params.sendgrid) { |
||||
|
console.log("--- No sendgrid params ---"); |
||||
|
return; |
||||
|
} |
||||
|
console.log("--- sendgrid params exists ---"); |
||||
|
|
||||
|
const sendgridParams = params.sendgrid; |
||||
|
const defaultParams = { |
||||
|
url: sendgridParams.uri, |
||||
|
headers: { |
||||
|
Authorization: "Bearer " + sendgridParams.application_secret, |
||||
|
"Content-Type": "application/json", |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
const sendEmail = async (to, subject, message) => { |
||||
|
const data = { |
||||
|
personalizations: [ |
||||
|
{ |
||||
|
to: to, |
||||
|
subject: subject, |
||||
|
}, |
||||
|
], |
||||
|
content: [ |
||||
|
{ |
||||
|
type: "text/html", |
||||
|
value: message, |
||||
|
}, |
||||
|
], |
||||
|
from: { |
||||
|
email: sendgridParams.from, |
||||
|
name: sendgridParams.fromName, |
||||
|
}, |
||||
|
}; |
||||
|
return null |
||||
|
// const response = await axios.post(defaultParams.url, data, {
|
||||
|
// headers: defaultParams.headers,
|
||||
|
// });
|
||||
|
// return response;
|
||||
|
}; |
||||
|
|
||||
|
// Create a new listener for the parse.end event
|
||||
|
emitter.on("parse.end", async ({ url, columns, count, generated }) => { |
||||
|
console.log("HOST", host); |
||||
|
try { |
||||
|
const message = templateService.renderEmail("parse-success", { |
||||
|
host, |
||||
|
generated, |
||||
|
count, |
||||
|
columns, |
||||
|
url, |
||||
|
}); |
||||
|
const response = await sendEmail( |
||||
|
sendgridParams.to, |
||||
|
"BODACC - Traitement terminé", |
||||
|
message |
||||
|
); |
||||
|
emitter.emit("mailer.parse.end.success", { response: response.data }); |
||||
|
} catch (error) { |
||||
|
emitter.emit("mailer.parse.end.error", { error: errorResponse(error) }); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
// Create a new listener for the parse.error event
|
||||
|
emitter.on("parse.error", async ({ filepath, columns, error }) => { |
||||
|
try { |
||||
|
const reponse = await sendEmail( |
||||
|
sendgridParams.to, |
||||
|
"BODACC - Erreur traitement", |
||||
|
"<p>Erreur traitement</p><br /><p>Voici le message d'erreur: " + |
||||
|
error + |
||||
|
"</p>" |
||||
|
); |
||||
|
emitter.emit("mailer.parse.error.success", { response: response }); |
||||
|
} catch (error) { |
||||
|
emitter.emit("mailer.parse.error.error", { error: errorResponse(error) }); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
// Create a new listener for the parseFromUrl.error event
|
||||
|
emitter.on("parseFromUrl.error", async ({ url, columns, error }) => { |
||||
|
try { |
||||
|
const response = await sendEmail( |
||||
|
sendgridParams.to, |
||||
|
"BODACC - Erreur génération fichier", |
||||
|
"<p>Erreur génération fichier</p><br /><p>Voici le message d'erreur: " + |
||||
|
error + |
||||
|
"</p>" |
||||
|
); |
||||
|
emitter.emit("mailer.parseFromUrl.error.success", { |
||||
|
response: response.data, |
||||
|
}); |
||||
|
} catch (error) { |
||||
|
emitter.emit("mailer.parseFromUrl.error.error", { |
||||
|
error: errorResponse(error), |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
|
}; |
@ -0,0 +1,8 @@ |
|||||
|
<p>Bonjour, </p> |
||||
|
<br /> |
||||
|
<p>Le traitement de votre fichier depuis l'url <strong>{{url}}</strong> est terminé</p> |
||||
|
<p><strong>{{count}} lignes</strong> ont été générés</p> |
||||
|
|
||||
|
<br /> |
||||
|
<p>Voici le lien pour télécharger le fichier généré: <strong>{{host}}/csv/{{generated}}</strong></p> |
||||
|
<p>Copier le lien ci-dessus et coller le dans votre navigateur</p> |
@ -0,0 +1,13 @@ |
|||||
|
<div class="email-layout"> |
||||
|
<div class="email-layout__inner"> |
||||
|
<div class="email-layout__header"> |
||||
|
|
||||
|
</div> |
||||
|
<div class="email-layout__body"> |
||||
|
{{{body}}} |
||||
|
</div> |
||||
|
<div class="email-layout__footer"> |
||||
|
|
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
Loading…
Reference in new issue