-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
L'admin peut télécharger tous les inventaires au format CSV
- Loading branch information
Showing
9 changed files
with
133 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { indicateurImpactEquipementModel } from '@prisma/client' | ||
import { notFound } from 'next/navigation' | ||
|
||
import { getProfilAtih } from '../../../authentification' | ||
import { recupererTousLesIndicateursImpactsEquipementsRepository } from '../../../repositories/indicateursRepository' | ||
|
||
export async function GET(): Promise<Response> { | ||
const profil = await getProfilAtih() | ||
|
||
if (!profil.isAdmin) { | ||
notFound() | ||
} | ||
|
||
const indicateurs = await recupererTousLesIndicateursImpactsEquipementsRepository() | ||
|
||
const fichierCsv = creerLeFichierAExporter(indicateurs) | ||
|
||
return new Response( | ||
fichierCsv, | ||
{ | ||
headers: { | ||
'content-disposition': `attachment; filename="${fichierCsv.name}"`, | ||
}, | ||
} | ||
) | ||
} | ||
|
||
function creerLeFichierAExporter(indicateurs: Array<indicateurImpactEquipementModel>): File { | ||
const data = ['date_calcul;date_lot;nom_lot;etapeacv;critere;source;statut_indicateur;trace;version_calcul;conso_elec_moyenne;impact_unitaire;quantite;statut_equipement_physique;type_equipement;unite;nom_entite;nom_organisation;nom_source_donnee;nom_equipement;date_lot_discriminator;nom_organisation_discriminator;nom_entite_discriminator;nom_source_donnee_discriminator'] | ||
|
||
for (const indicateur of indicateurs) { | ||
data.push(`${indicateur.date_calcul?.toLocaleString('fr-FR')};${indicateur.dateInventaire.toLocaleString('fr-FR')};${indicateur.nomInventaire};${indicateur.etapeAcv};${indicateur.critere};${indicateur.source};${indicateur.statutIndicateur};${indicateur.trace};${indicateur.version_calcul};${indicateur.conso_elec_moyenne};${indicateur.impactUnitaire};${indicateur.quantite};${indicateur.statut_equipement_physique};${indicateur.typeEquipement};${indicateur.unite};${indicateur.nom_entite};${indicateur.nomEtablissement};${indicateur.nom_source_donnee};${indicateur.nom_equipement};${indicateur.date_lot_discriminator?.toLocaleString('fr-FR')};${indicateur.nom_organisation_discriminator};${indicateur.nom_entite_discriminator};${indicateur.nom_source_donnee_discriminator}`) | ||
} | ||
|
||
return new File([data.join('\n')], `EvalCarboneSIH_Inventaires_${new Date().toLocaleDateString('fr-FR')}.csv`, { type: 'text/csv' }) | ||
} |
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
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