-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add data subvention source #1263
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
29818c3
base
rmonnier9 a489228
infos
rmonnier9 8aa9f72
feat: add data subvention source
rmonnier9 a06ccf8
feat: remove status col, add isProtected, create component, add agent…
rmonnier9 479504b
feat: add scopes and rights
XavierJp bc53fde
content: update data subvention section description
XavierJp 1d79b11
fix: useless console.log
XavierJp 75f76b0
content: typo
XavierJp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { HttpNotFound } from '#clients/exceptions'; | ||
import routes from '#clients/routes'; | ||
import constants from '#models/constants'; | ||
import { ISubvention, ISubventions } from '#models/subventions/association'; | ||
import { Siren } from '#utils/helpers'; | ||
import { httpGet } from '#utils/network'; | ||
|
||
/** | ||
* Data Subvention | ||
* https://api.datasubvention.beta.gouv.fr/ | ||
*/ | ||
export const clientDataSubvention = async ( | ||
siren: Siren | ||
): Promise<ISubventions> => { | ||
const route = routes.apiDataSubvention.grants.replace('{identifier}', siren); | ||
const data = await httpGet<any>(route, { | ||
headers: { 'x-access-token': process.env.DATA_SUBVENTION_API_KEY }, | ||
timeout: constants.timeout.XXL, | ||
}); | ||
const msgNotFound = `No subvention data found for : ${siren}`; | ||
|
||
if (!data.subventions || data.subventions.length === 0) { | ||
throw new HttpNotFound(msgNotFound); | ||
} | ||
|
||
const subventions = mapToDomainObject(data.subventions); | ||
|
||
if (subventions.length === 0) { | ||
throw new HttpNotFound(msgNotFound); | ||
} | ||
return subventions; | ||
}; | ||
|
||
const mapToDomainObject = (grantItems: IGrantItem[]): ISubvention[] => { | ||
return grantItems | ||
.filter((grantItem) => Boolean(grantItem.application)) | ||
.reduce((subventions: ISubvention[], grantItem) => { | ||
const year = grantItem.application.annee_demande?.value; | ||
const label = grantItem.application.statut_label?.value; | ||
const status = grantItem.application.status?.value; | ||
const description = grantItem.application.dispositif?.value; | ||
const amount = grantItem.application.montants?.accorde?.value; | ||
|
||
const newSubvention: ISubvention = { | ||
year, | ||
label, | ||
status, | ||
description, | ||
amount, | ||
}; | ||
|
||
return [...subventions, newSubvention]; | ||
}, []) | ||
.sort((a, b) => b.year - a.year); | ||
}; |
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,96 @@ | ||
type ApplicationField<T> = { | ||
value: T; | ||
provider: string; | ||
last_update: string; | ||
type: string; | ||
}; | ||
|
||
type SubventionStatus = 'Accordé' | 'Refusé' | 'Prise en charge' | 'Recevable'; | ||
type SubventionLabel = 'Accordé' | 'Refusé' | 'En instruction'; | ||
|
||
type Contact = { | ||
email: ApplicationField<string>; | ||
telephone: ApplicationField<string>; | ||
}; | ||
|
||
type Montants = { | ||
total: ApplicationField<number>; | ||
demande: ApplicationField<number>; | ||
propose: ApplicationField<number>; | ||
accorde: ApplicationField<number>; | ||
}; | ||
|
||
type Versement = { | ||
acompte: ApplicationField<number>; | ||
solde: ApplicationField<number>; | ||
realise: ApplicationField<number>; | ||
compensation: { | ||
'n-1': ApplicationField<number>; | ||
reversement: ApplicationField<number>; | ||
}; | ||
}; | ||
|
||
type Payment = { | ||
activitee: ApplicationField<string>; | ||
amount: ApplicationField<number>; | ||
bop: ApplicationField<string>; | ||
branche: ApplicationField<string>; | ||
centreFinancier: ApplicationField<string>; | ||
codeBranche: ApplicationField<string>; | ||
dateOperation: ApplicationField<string>; | ||
domaineFonctionnel: ApplicationField<string>; | ||
ej: ApplicationField<string>; | ||
libelleProgramme: ApplicationField<string>; | ||
numeroDemandePayment: ApplicationField<string>; | ||
numeroTier: ApplicationField<string>; | ||
programme: ApplicationField<string>; | ||
siret: ApplicationField<string>; | ||
versementKey: ApplicationField<string>; | ||
}; | ||
|
||
type ActionProposeeType = { | ||
ej: ApplicationField<string>; | ||
rang: ApplicationField<number>; | ||
intitule: ApplicationField<string>; | ||
objectifs: ApplicationField<string>; | ||
objectifs_operationnels: { | ||
provider: string; | ||
last_update: string; | ||
type: string; | ||
}; | ||
description: ApplicationField<string>; | ||
}; | ||
|
||
type TerritoireType = { | ||
status: { | ||
provider: string; | ||
last_update: string; | ||
type: string; | ||
}; | ||
commentaire: ApplicationField<string>; | ||
}; | ||
|
||
type Application = { | ||
actions_proposee: ActionProposeeType[]; | ||
annee_demande: ApplicationField<number>; | ||
contact: Contact; | ||
// This is the name of the subvention | ||
dispositif: ApplicationField<string>; | ||
ej: ApplicationField<string>; | ||
financeur_principal: ApplicationField<string>; | ||
montants: Montants; | ||
pluriannualite: ApplicationField<string>; | ||
service_instructeur: ApplicationField<string>; | ||
siret: ApplicationField<string>; | ||
sous_dispositif: ApplicationField<string>; | ||
status: ApplicationField<SubventionStatus>; | ||
statut_label: ApplicationField<SubventionLabel>; | ||
territoires: TerritoireType[]; | ||
versement: Versement; | ||
versementKey: ApplicationField<string>; | ||
}; | ||
|
||
type IGrantItem = { | ||
application: Application; | ||
payments: Payment[]; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use client'; | ||
|
||
import { Tag } from '#components-ui/tag'; | ||
import { DataSubvention } from '#components/administrations'; | ||
import { DataSectionClient } from '#components/section/data-section'; | ||
import { FullTable } from '#components/table/full'; | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { IAssociation } from '#models/core/types'; | ||
import { ISession } from '#models/user/session'; | ||
import { formatCurrency } from '#utils/helpers'; | ||
import { useAPIRouteData } from 'hooks/fetch/use-API-route-data'; | ||
|
||
export const SubventionsAssociationSection: React.FC<{ | ||
uniteLegale: IAssociation; | ||
session: ISession | null; | ||
}> = ({ uniteLegale, session }) => { | ||
const subventions = useAPIRouteData( | ||
'subventions-association', | ||
uniteLegale.siren, | ||
session | ||
); | ||
if (!subventions) return null; | ||
|
||
return ( | ||
<DataSectionClient | ||
notFoundInfo="Aucune demande de subvention n’a été trouvée pour cette association." | ||
title="Détail des subventions" | ||
sources={[EAdministration.DATA_SUBVENTION]} | ||
data={subventions} | ||
> | ||
{(subventions) => | ||
subventions.length === 0 ? ( | ||
<> | ||
Aucune demande de subvention n’a été trouvée pour cette association. | ||
</> | ||
) : ( | ||
<> | ||
<p> | ||
Voici le détail des subventions demandées par l’association. Ces | ||
données sont collectées par <DataSubvention />. | ||
</p> | ||
<FullTable | ||
head={['Année', 'Dispositif', 'Montant', 'Status', 'Label']} | ||
body={subventions.map((subvention) => [ | ||
<strong>{subvention.year}</strong>, | ||
<strong>{subvention.description}</strong>, | ||
formatCurrency(subvention.amount), | ||
// TODO Component | ||
<Tag | ||
color={ | ||
subvention.status === 'Accordé' | ||
? 'success' | ||
: subvention.status === 'Refusé' | ||
? 'error' | ||
: 'new' | ||
} | ||
> | ||
{subvention.status} | ||
</Tag>, | ||
// TODO Component | ||
<Tag | ||
color={ | ||
subvention.status === 'Accordé' | ||
? 'success' | ||
: subvention.status === 'Refusé' | ||
? 'error' | ||
: 'new' | ||
} | ||
> | ||
{subvention.label} | ||
</Tag>, | ||
])} | ||
/> | ||
</> | ||
) | ||
} | ||
</DataSectionClient> | ||
); | ||
}; |
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,14 @@ | ||
slug: data-subvention | ||
short: Data.Subvention | ||
site: https://datasubvention.beta.gouv.fr/ | ||
long: Data.Subvention | ||
logoType: portrait | ||
dataSources: | ||
- label: Data.Subvention | ||
apiSlug: data-subvention | ||
data: | ||
- label: Data.Subvention | ||
targets: | ||
- agent | ||
contact: https://datasubvention.beta.gouv.fr/contact/ | ||
description: Un outil de consultation pour les agents de l'Etat porté par la DJEPVA et la DINUM pour éclaircir vos décisions et mieux connaître les associations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering wether we create an administration or we use the existing DJEPVA one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's see with the Data.Subvention team ? |
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,49 @@ | ||
import { clientDataSubvention } from '#clients/api-data-subvention'; | ||
import { HttpNotFound } from '#clients/exceptions'; | ||
import { EAdministration } from '#models/administrations/EAdministration'; | ||
import { | ||
APINotRespondingFactory, | ||
IAPINotRespondingError, | ||
} from '#models/api-not-responding'; | ||
import { getUniteLegaleFromSlug } from '#models/core/unite-legale'; | ||
import { FetchRessourceException } from '#models/exceptions'; | ||
import logErrorInSentry from '#utils/sentry'; | ||
|
||
export type ISubventions = ISubvention[]; | ||
|
||
export interface ISubvention { | ||
year: number; | ||
label: string; | ||
status: string; | ||
description: string; | ||
amount: number; | ||
} | ||
|
||
export const getSubventionsAssociationFromSlug = async ( | ||
slug: string | ||
): Promise<ISubventions | IAPINotRespondingError | null> => { | ||
const uniteLegale = await getUniteLegaleFromSlug(slug, { | ||
isBot: false, | ||
}); | ||
|
||
const { siren } = uniteLegale; | ||
|
||
try { | ||
return await clientDataSubvention(siren); | ||
} catch (e: any) { | ||
if (e instanceof HttpNotFound) { | ||
return APINotRespondingFactory(EAdministration.DATA_SUBVENTION, 404); | ||
} | ||
logErrorInSentry( | ||
new FetchRessourceException({ | ||
ressource: 'DataSubvention', | ||
cause: e, | ||
context: { | ||
siren, | ||
}, | ||
administration: EAdministration.DATA_SUBVENTION, | ||
}) | ||
); | ||
return APINotRespondingFactory(EAdministration.DATA_SUBVENTION, 500); | ||
} | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this. Either the user has the rights to see it and he/she prefer an explanation like :
Aucune demande de subvention n’a été trouvée pour cette association.
. Or h/she is not agent connected and we could display the<AgentWall />
component