Skip to content
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: familles de métiers #15

Merged
merged 9 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: ordre des familles de métiers
  • Loading branch information
K4ST0R committed Oct 30, 2024
commit 84988ad1801000c1b0b3bd17de87368e40e6d687
24 changes: 10 additions & 14 deletions server/src/common/repositories/formationEtablissement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SqlRepository } from "./base.js";
import { kdb as defaultKdb, kyselyChainFn } from "../db/db";
import { kdb as defaultKdb } from "../db/db";
import { DB } from "../db/schema.js";
import FormationRepository from "./formation";
import EtablissementRepository from "./etablissement";
Expand Down Expand Up @@ -88,30 +88,26 @@ export class FormationEtablissementRepository extends SqlRepository<DB, "formati
.select((eb) => eb.fn("row_to_json", [sql`"feMetier"`]).as("formationEtablissement"))
.select((eb) => eb.fn("row_to_json", [sql`"eEtablissement"`]).as("etablissement"))
.select("feMetier.id as formationEtablissementId")
.select(sql.val("1").as("exist"))
.select("feMetier")
.as("feMetier"),
(join) => join.on(sql`true`)
)
.select((eb) => eb.fn("row_to_json", [sql`"fMetier"`]).as("formation"))
.select("formationEtablissement")
.select("etablissement")
.select("libelle")
.select("exist")
.whereRef("fMetier.familleMetierId", "=", "formation.familleMetierId")
.where("isAnneeCommune", "=", false)
.orderBy(["formationEtablissementId", "fMetier.libelle"])
.orderBy(["exist", "fMetier.libelle"])
.as("formationsFamilleMetier")
)
.select((eb) => {
return [
kyselyChainFn(
eb,
[
{ fn: "to_jsonb", args: [] },
{ fn: "json_agg", args: [] },
],
sql`"formationsFamilleMetier"`
).as("formationsFamilleMetier"),
];
})
.select(
sql`json_agg(to_jsonb("formationsFamilleMetier") - 'libelle' - 'exist' ORDER BY "exist", "formationsFamilleMetier".libelle)`.as(
"formationsFamilleMetier"
)
)
.as("formationsFamilleMetier"),
(join) => join.on(sql`true`)
)
Expand Down
18 changes: 6 additions & 12 deletions server/src/queries/getFormations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,25 +304,19 @@ export async function getFormationsSQL(
.select((eb) => eb.fn("row_to_json", [sql`"fMetier"`]).as("formation"))
.select((eb) => eb.fn("row_to_json", [sql`"feMetier"`]).as("formationEtablissement"))
.select((eb) => eb.fn("row_to_json", [sql`"eEtablissement"`]).as("etablissement"))
.select("fMetier.libelle")
.whereRef("feMetier.etablissementId", "=", "results.etablissementId")
.whereRef("fMetier.familleMetierId", "=", "results.familleMetierId")
.where("fMetier.isAnneeCommune", "=", false)
.where("feMetier.millesime", "&&", [millesime])
.orderBy("fMetier.libelle")
.as("formationsFamilleMetier")
)
.select((eb) => {
return [
kyselyChainFn(
eb,
[
{ fn: "to_jsonb", args: [] },
{ fn: "json_agg", args: [] },
],
sql`"formationsFamilleMetier"`
).as("formationsFamilleMetier"),
];
})
.select(
sql`json_agg(to_jsonb("formationsFamilleMetier") - 'libelle' ORDER BY "formationsFamilleMetier".libelle)`.as(
"formationsFamilleMetier"
)
)
.as("formationsFamilleMetier"),
(join) => join.on(sql`true`)
)
Expand Down
12 changes: 10 additions & 2 deletions ui/app/(accompagnateur)/recherche/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import ResearchFormationsResult from "./ResearchFormationsResult";
import { fetchAddress } from "#/app/services/address";
import { Suspense } from "react";
import { Suspense, useEffect } from "react";
import { useQuery } from "@tanstack/react-query";
import FormationsSearchProvider, { useFormationsSearch } from "../context/FormationsSearchContext";
import SearchHeader from "../components/SearchHeader";
Expand All @@ -16,11 +16,19 @@ import { FormationDomaine } from "shared";
import { FORMATION_DOMAINE } from "#/app/services/formation";
import OptionsCarousel from "#/app/components/form/OptionsCarousel";
import { myPosition } from "#/app/components/form/AddressField";
import { useRouter } from "next/navigation";

function ResearchFormationsParameter() {
const router = useRouter();
const { params, updateParams } = useFormationsSearch();
const { address, tag, domaine, formation } = params ?? {};

useEffect(() => {
if (!address) {
router.push(`/`);
}
}, [address]);

const { data, isLoading, error } = useQuery({
staleTime: Infinity,
cacheTime: Infinity,
Expand Down Expand Up @@ -49,7 +57,7 @@ function ResearchFormationsParameter() {
},
});

if (!params) {
if (!params || !params.address) {
return null;
}

Expand Down
Loading