Skip to content

Commit

Permalink
Merge pull request #542 from mission-apprentissage/fix/compteurs-inte…
Browse files Browse the repository at this point in the history
…ntion

fix: compteurs dans la boîte de réception des demandes/intentions
  • Loading branch information
LucasDetre authored Jan 22, 2025
2 parents b48b36a + db0aaec commit 3f6b61b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { cleanNull } from "@/utils/noNull";
export interface Filters extends z.infer<typeof countDemandesSchema.querystring> {
user: RequestUser;
}
export const countDemandesQuery = async ({ user, anneeCampagne, codeAcademie, codeNiveauDiplome, search }: Filters) => {
export const countDemandesQuery = async ({ user, campagne, codeAcademie, codeNiveauDiplome, search }: Filters) => {
const search_array = getNormalizedSearchArray(search);

const countDemandes = getKbdClient()
Expand All @@ -22,14 +22,7 @@ export const countDemandesQuery = async ({ user, anneeCampagne, codeAcademie, co
.leftJoin("departement", "departement.codeDepartement", "dataEtablissement.codeDepartement")
.leftJoin("academie", "academie.codeAcademie", "dataEtablissement.codeAcademie")
.leftJoin("user", "user.id", "demande.createdBy")
.innerJoin("campagne", (join) =>
join.onRef("campagne.id", "=", "demande.campagneId").$call((eb) => {
if (anneeCampagne) {
return eb.on("campagne.annee", "=", anneeCampagne);
}
return eb;
})
)
.innerJoin("campagne", "campagne.id", "demande.campagneId")
.leftJoin("suivi", (join) =>
join.onRef("suivi.intentionNumero", "=", "demande.numero").on("suivi.userId", "=", user.id)
)
Expand Down Expand Up @@ -118,6 +111,12 @@ export const countDemandesQuery = async ({ user, anneeCampagne, codeAcademie, co
if (codeNiveauDiplome) return eb.where("dataFormation.codeNiveauDiplome", "in", codeNiveauDiplome);
return eb;
})
.$call((eb) => {
if (campagne) {
return eb.where("campagne.annee", "=", campagne);
}
return eb;
})
.where(isDemandeNotDeleted)
.where(isDemandeSelectable({ user }))
.executeTakeFirstOrThrow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const countDemandesFactory =
) =>
async (activeFilters: Filters) => {
const currentCampagne = await deps.getCurrentCampagneQuery();
const anneeCampagne = activeFilters.anneeCampagne ?? currentCampagne.annee;
const anneeCampagne = activeFilters.campagne ?? currentCampagne.annee;

return await deps.countDemandesQuery({
anneeCampagne,
campagne: anneeCampagne,
...activeFilters,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Filters extends z.infer<typeof countIntentionsSchema.querystrin
}
export const countIntentionsQuery = async ({
user,
anneeCampagne,
campagne,
shouldFetchOnlyIntention,
search,
codeAcademie,
Expand All @@ -33,14 +33,7 @@ export const countIntentionsQuery = async ({
.leftJoin("departement", "departement.codeDepartement", "dataEtablissement.codeDepartement")
.leftJoin("academie", "academie.codeAcademie", "dataEtablissement.codeAcademie")
.leftJoin("user", "user.id", "intention.createdBy")
.innerJoin("campagne", (join) =>
join.onRef("campagne.id", "=", "intention.campagneId").$call((eb) => {
if (anneeCampagne) {
return eb.on("campagne.annee", "=", anneeCampagne);
}
return eb;
})
)
.innerJoin("campagne", "campagne.id", "intention.campagneId")
.leftJoin("suivi", (join) =>
join.onRef("suivi.intentionNumero", "=", "intention.numero").on("suivi.userId", "=", user.id)
)
Expand Down Expand Up @@ -181,6 +174,12 @@ export const countIntentionsQuery = async ({
}
return eb;
})
.$call((eb) => {
if (campagne) {
return eb.where("campagne.annee", "=", campagne);
}
return eb;
})
.where(isIntentionNotDeleted)
.where(isIntentionSelectable({ user }))
.where(isIntentionBrouillonVisible({ user }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const countIntentionsFactory =
) =>
async (activeFilters: Filters) => {
const currentCampagne = await deps.getCurrentCampagneQuery();
const anneeCampagne = activeFilters.anneeCampagne ?? currentCampagne.annee;
const anneeCampagne = activeFilters.campagne ?? currentCampagne.annee;

const shouldFetchOnlyIntention = anneeCampagne !== CAMPAGNE_DEMANDE;
return await deps.countIntentionsQuery({
anneeCampagne,
campagne:anneeCampagne,
...activeFilters,
shouldFetchOnlyIntention,
});
Expand Down
2 changes: 1 addition & 1 deletion shared/routes/schemas/get.demandes.count.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DemandeStatutEnum } from "../../enum/demandeStatutEnum";

export const countDemandesSchema = {
querystring: z.object({
anneeCampagne: z.string().optional(),
campagne: z.string().optional(),
search: z.string().optional(),
codeAcademie: z.array(z.string()).optional(),
codeNiveauDiplome: z.array(z.string()).optional(),
Expand Down
2 changes: 1 addition & 1 deletion shared/routes/schemas/get.intentions.count.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DemandeStatutEnum } from "../../enum/demandeStatutEnum";

export const countIntentionsSchema = {
querystring: z.object({
anneeCampagne: z.string().optional(),
campagne: z.string().optional(),
search: z.string().optional(),
codeAcademie: z.array(z.string()).optional(),
codeNiveauDiplome: z.array(z.string()).optional(),
Expand Down

0 comments on commit 3f6b61b

Please sign in to comment.