-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
118 changed files
with
3,798 additions
and
1,540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/backend/src/controllers/demandeSejour/getExtractHebergement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const DemandeSejour = require("../../services/DemandeSejour"); | ||
const logger = require("../../utils/logger"); | ||
const dayjs = require("dayjs"); | ||
|
||
const log = logger(module.filename); | ||
|
||
const escapeCsvField = (field) => { | ||
if (typeof field !== "string") { | ||
return `${field}`; | ||
} | ||
|
||
if (field.includes('"') || field.includes(";") || field.includes("\n")) { | ||
const fieldEscaped = field.replace(/"/g, '""'); | ||
return `"${fieldEscaped}"`; | ||
} | ||
return field; | ||
}; | ||
|
||
module.exports = async function get(req, res, next) { | ||
log.i("IN"); | ||
res.setHeader("Content-Type", "text/csv"); | ||
res.setHeader("Content-Disposition", 'attachment; filename="data.csv"'); | ||
const departements = req.departements.map((d) => d.value); | ||
try { | ||
const result = await DemandeSejour.getHebergementsByDepartementCodes( | ||
departements, | ||
{ | ||
limit: 20, | ||
offset: 0, | ||
order: "ASC", | ||
search: "", | ||
sort: "nom", | ||
}, | ||
); | ||
const titles = [ | ||
{ key: "nom", label: "Nom de l’hébergement" }, | ||
{ key: "dateDebut", label: "Date de début de séjour" }, | ||
{ key: "dateFin", label: "Date de fin de séjour" }, | ||
{ key: "departement", label: "Département" }, | ||
{ key: "adresse", label: "Adresse" }, | ||
{ key: "telephone", label: "Téléphone" }, | ||
{ key: "email", label: "Adresse courriel" }, | ||
{ key: "dateVisite", label: "Date de visite préalable" }, | ||
{ key: "reglementationErp", label: "Réglementation ERP" }, | ||
]; | ||
const csv = [ | ||
titles.map(({ label }) => label).join(";"), | ||
...result.data.hebergements.map((item) => { | ||
const newItem = { ...item }; | ||
newItem.reglementationErp = newItem.reglementationErp ? "Oui" : "Non"; | ||
newItem.dateDebut = dayjs(newItem.dateDebut).format("DD/MM/YYYY"); | ||
newItem.dateFin = dayjs(newItem.dateFin).format("DD/MM/YYYY"); | ||
newItem.adresse = newItem.adresse.label; | ||
newItem.dateVisite = newItem.dateVisite | ||
? dayjs(newItem.dateVisite).format("DD/MM/YYYY") | ||
: ""; | ||
return [ | ||
...titles.map(({ key }) => escapeCsvField(newItem[key] ?? "")), | ||
].join(";"); | ||
}), | ||
].join("\n"); | ||
|
||
return res.status(200).send(csv); | ||
} catch (error) { | ||
log.w("DONE with error"); | ||
return next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const FoUser = require("../../services/FoUser"); | ||
const logger = require("../../utils/logger"); | ||
const dayjs = require("dayjs"); | ||
|
||
const log = logger(module.filename); | ||
|
||
const escapeCsvField = (field) => { | ||
if (typeof field !== "string") { | ||
return `${field}`; | ||
} | ||
|
||
if (field.includes('"') || field.includes(";") || field.includes("\n")) { | ||
const fieldEscaped = field.replace(/"/g, '""'); | ||
return `"${fieldEscaped}"`; | ||
} | ||
return field; | ||
}; | ||
|
||
module.exports = async function getExtract(req, res, next) { | ||
log.i("getExtract IN", req); | ||
|
||
res.setHeader("Content-Type", "text/csv"); | ||
res.setHeader("Content-Disposition", 'attachment; filename="data.csv"'); | ||
|
||
try { | ||
const result = await FoUser.read({ | ||
search: { organisme_id: req.params.organismeId }, | ||
}); | ||
const titles = [ | ||
{ key: "nom", label: "Nom" }, | ||
{ key: "prenom", label: "Prenom" }, | ||
{ key: "email", label: "Courriel" }, | ||
{ key: "raisonSociale", label: "Raison sociale" }, | ||
{ key: "statut", label: "Statut" }, | ||
{ key: "dateCreation", label: "Date de création" }, | ||
{ key: "lastConnectionAt", label: "Date dernière connexion" }, | ||
{ key: "nombreDeclarations", label: "Nombre de déclaration" }, | ||
]; | ||
|
||
const csv = [ | ||
titles.map(({ label }) => label).join(";"), | ||
...result.users.map((item) => { | ||
const newItem = { ...item }; | ||
newItem.statut = | ||
newItem.statut === "VALIDATED" ? "Validé" : "Non validé"; | ||
newItem.dateCreation = dayjs(newItem.dateCreation).format("DD/MM/YYYY"); | ||
newItem.lastConnectionAt = newItem.lastConnectionAt | ||
? dayjs(newItem.lastConnectionAt).format("DD/MM/YYYY") | ||
: ""; | ||
return [ | ||
...titles.map(({ key }) => escapeCsvField(newItem[key] ?? "")), | ||
].join(";"); | ||
}), | ||
].join("\n"); | ||
|
||
return res.status(200).send(csv); | ||
} catch (error) { | ||
log.w("DONE with error"); | ||
return next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
module.exports.list = require("./list"); | ||
module.exports.getExtract = require("./getExtract"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/backend/src/controllers/hebergement/getExtract.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const Hebergement = require("../../services/Hebergement"); | ||
const logger = require("../../utils/logger"); | ||
const dayjs = require("dayjs"); | ||
|
||
const log = logger(module.filename); | ||
|
||
const escapeCsvField = (field) => { | ||
if (typeof field !== "string") { | ||
return `${field}`; | ||
} | ||
|
||
if (field.includes('"') || field.includes(";") || field.includes("\n")) { | ||
const fieldEscaped = field.replace(/"/g, '""'); | ||
return `"${fieldEscaped}"`; | ||
} | ||
return field; | ||
}; | ||
|
||
module.exports = async function getExtract(req, res, next) { | ||
log.i("IN"); | ||
res.setHeader("Content-Type", "text/csv"); | ||
res.setHeader("Content-Disposition", 'attachment; filename="data.csv"'); | ||
const departements = req.departements.map((d) => d.value); | ||
try { | ||
const result = await Hebergement.getByDepartementCodes(departements, { | ||
limit: 20, | ||
offset: 0, | ||
order: "ASC", | ||
search: "", | ||
sort: "nom", | ||
}); | ||
const titles = [ | ||
{ key: "nom", label: "Nom de l’hébergement" }, | ||
{ key: "departement", label: "Département" }, | ||
{ key: "adresse", label: "Adresse" }, | ||
{ key: "telephone", label: "Téléphone" }, | ||
{ key: "email", label: "Adresse courriel" }, | ||
{ key: "dateVisite", label: "Date de visite préalable" }, | ||
{ key: "reglementationErp", label: "Réglementation ERP" }, | ||
]; | ||
|
||
const csv = [ | ||
titles.map(({ label }) => label).join(";"), | ||
...result.data.hebergements.map((item) => { | ||
const newItem = { ...item }; | ||
newItem.reglementationErp = newItem.reglementationErp ? "oui" : "non"; | ||
newItem.adresse = newItem.adresse.label; | ||
newItem.dateVisite = newItem.dateVisite | ||
? dayjs(newItem.dateVisite).format("DD/MM/YYYY") | ||
: ""; | ||
return [ | ||
...titles.map(({ key }) => escapeCsvField(newItem[key] ?? "")), | ||
].join(";"); | ||
}), | ||
].join("\n"); | ||
|
||
return res.status(200).send(csv); | ||
} catch (error) { | ||
log.w("DONE with error"); | ||
return next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports.get = require("./get"); | ||
module.exports.getByDepartements = require("./getByDepartements"); | ||
module.exports.getById = require("./getById"); | ||
module.exports.getExtract = require("./getExtract"); | ||
module.exports.post = require("./post"); | ||
module.exports.update = require("./update"); |
Oops, something went wrong.