-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ajout bilan en tonnes dans le redirection post reception situation NGC
- Loading branch information
Wojciech WOJCIK
committed
Oct 7, 2024
1 parent
b6bd003
commit dd75d66
Showing
3 changed files
with
53 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { SituationNGCRepository } from '../infrastructure/repository/bilan.repository'; | ||
import { NGCCalculator } from '../infrastructure/ngc/NGCCalculator'; | ||
|
||
@Injectable() | ||
export class BilanUsecase { | ||
constructor(private bilanRepository: SituationNGCRepository) {} | ||
constructor( | ||
private bilanRepository: SituationNGCRepository, | ||
private ngcCaclulator: NGCCalculator, | ||
) {} | ||
|
||
async importSituationNGC(situation: object): Promise<string> { | ||
return await this.bilanRepository.createSituation(situation); | ||
async importSituationNGC( | ||
situation: object, | ||
): Promise<{ id_situtation: string; bilan_tonnes: number }> { | ||
const id_situtation = await this.bilanRepository.createSituation(situation); | ||
let bilan = { bilan_carbone_annuel: 8000 }; | ||
try { | ||
bilan = this.ngcCaclulator.computeBilanFromSituation(situation); | ||
} catch (error) { | ||
console.error( | ||
`Erreur calcul bilan carbone utilisateur NGC, id_situation : ${id_situtation}`, | ||
); | ||
} | ||
return { | ||
id_situtation: id_situtation, | ||
bilan_tonnes: Math.round(bilan.bilan_carbone_annuel / 1000), | ||
}; | ||
} | ||
} |
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