-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Paul Gaucher <[email protected]> Co-authored-by: Nicolas KREMER <[email protected]>
- Loading branch information
1 parent
2d908a6
commit 549391c
Showing
31 changed files
with
1,634 additions
and
255 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
127 changes: 127 additions & 0 deletions
127
server/src/common/actions/indicateurs/indicateurs-with-deca.actions.ts
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,127 @@ | ||
import { ObjectId } from "mongodb"; | ||
import { TypeEffectifNominatif } from "shared/constants/indicateurs"; | ||
import { Acl } from "shared/constants/permissions"; | ||
|
||
import { effectifsDECADb, effectifsDb } from "@/common/model/collections"; | ||
import { AuthContext } from "@/common/model/internal/AuthContext"; | ||
|
||
import { DateFilters, EffectifsFiltersTerritoire, FullEffectifsFilters, TerritoireFilters } from "../helpers/filters"; | ||
|
||
import { | ||
getIndicateursEffectifsParDepartementGenerique, | ||
getIndicateursEffectifsParOrganismeGenerique, | ||
getEffectifsNominatifsGenerique, | ||
getOrganismeIndicateursEffectifsParFormationGenerique, | ||
getOrganismeIndicateursEffectifsGenerique, | ||
} from "./indicateurs.actions"; | ||
|
||
export const buildDECAFilter = (decaMode) => (decaMode ? { is_deca_compatible: true } : {}); | ||
|
||
// Attention ca marche pas, il faut ensuite merger par departement et sommer les valeurs | ||
export const getIndicateursEffectifsParDepartement = async (filters: DateFilters & TerritoireFilters, acl: Acl) => { | ||
const indicateurs = [ | ||
...(await getIndicateursEffectifsParDepartementGenerique(filters, acl, effectifsDb(), false)), | ||
...(await getIndicateursEffectifsParDepartementGenerique(filters, acl, effectifsDECADb(), true)), | ||
]; | ||
|
||
const mapDepartement = indicateurs.reduce((acc, { departement, ...rest }) => { | ||
return acc[departement] | ||
? { | ||
...acc, | ||
[departement]: { | ||
departement, | ||
apprentis: acc[departement].apprentis + rest.apprentis, | ||
abandons: acc[departement].abandons + rest.abandons, | ||
inscrits: acc[departement].inscrits + rest.inscrits, | ||
apprenants: acc[departement].apprenants + rest.apprenants, | ||
rupturants: acc[departement].rupturants + rest.rupturants, | ||
}, | ||
} | ||
: { | ||
...acc, | ||
[departement]: { | ||
departement, | ||
...rest, | ||
}, | ||
}; | ||
}, {}); | ||
return Object.values(mapDepartement); | ||
}; | ||
|
||
export const getIndicateursEffectifsParOrganisme = async ( | ||
ctx: AuthContext, | ||
filters: FullEffectifsFilters, | ||
organismeId?: ObjectId | ||
) => [ | ||
...(await getIndicateursEffectifsParOrganismeGenerique(ctx, filters, effectifsDb(), false, organismeId)), | ||
...(await getIndicateursEffectifsParOrganismeGenerique(ctx, filters, effectifsDECADb(), true, organismeId)), | ||
]; | ||
|
||
export const getEffectifsNominatifs = async ( | ||
ctx: AuthContext, | ||
filters: FullEffectifsFilters, | ||
type: TypeEffectifNominatif, | ||
organismeId?: ObjectId | ||
) => [ | ||
...(await getEffectifsNominatifsGenerique(ctx, filters, type, effectifsDb(), false, organismeId)), | ||
...(await getEffectifsNominatifsGenerique(ctx, filters, type, effectifsDECADb(), true, organismeId)), | ||
]; | ||
|
||
export const getOrganismeIndicateursEffectifs = async ( | ||
ctx: AuthContext, | ||
organismeId: ObjectId, | ||
filters: EffectifsFiltersTerritoire | ||
) => { | ||
const eff = await getOrganismeIndicateursEffectifsGenerique(ctx, organismeId, filters, effectifsDb(), false); | ||
const effDECA = await getOrganismeIndicateursEffectifsGenerique(ctx, organismeId, filters, effectifsDECADb(), true); | ||
|
||
return { | ||
apprenants: eff.apprenants + effDECA.apprenants, | ||
apprentis: eff.apprentis + effDECA.apprentis, | ||
inscrits: eff.inscrits + effDECA.inscrits, | ||
abandons: eff.abandons + effDECA.abandons, | ||
rupturants: eff.rupturants + effDECA.rupturants, | ||
}; | ||
}; | ||
|
||
export const getOrganismeIndicateursEffectifsParFormation = async ( | ||
ctx: AuthContext, | ||
organismeId: ObjectId, | ||
filters: FullEffectifsFilters | ||
) => { | ||
const indicateurs = [ | ||
...(await getOrganismeIndicateursEffectifsParFormationGenerique(ctx, organismeId, filters, effectifsDb())), | ||
...(await getOrganismeIndicateursEffectifsParFormationGenerique( | ||
ctx, | ||
organismeId, | ||
filters, | ||
effectifsDECADb(), | ||
true | ||
)), | ||
]; | ||
|
||
const mapRNCP = indicateurs.reduce((acc, { rncp_code, ...rest }) => { | ||
const rncp = rncp_code ?? "null"; | ||
return acc[rncp] | ||
? { | ||
...acc, | ||
[rncp]: { | ||
rncp_code, | ||
apprentis: acc[rncp].apprentis + rest.apprentis, | ||
abandons: acc[rncp].abandons + rest.abandons, | ||
inscrits: acc[rncp].inscrits + rest.inscrits, | ||
apprenants: acc[rncp].apprenants + rest.apprenants, | ||
rupturants: acc[rncp].rupturants + rest.rupturants, | ||
}, | ||
} | ||
: { | ||
...acc, | ||
[rncp]: { | ||
rncp_code, | ||
...rest, | ||
}, | ||
}; | ||
}, {}); | ||
|
||
return Object.values(mapRNCP); | ||
}; |
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
Oops, something went wrong.