Skip to content

Commit

Permalink
feat: move network constants to shared
Browse files Browse the repository at this point in the history
wip
  • Loading branch information
sbenfares committed Oct 5, 2023
1 parent 5c0a237 commit f678f6e
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 131 deletions.
103 changes: 0 additions & 103 deletions server/src/common/constants/networks.ts

This file was deleted.

3 changes: 1 addition & 2 deletions server/src/common/model/effectifs.model/effectifs.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { CreateIndexesOptions, IndexSpecification } from "mongodb";
import { ACADEMIES, DEPARTEMENTS, REGIONS } from "shared";
import { ACADEMIES, DEPARTEMENTS, REGIONS, TETE_DE_RESEAUX } from "shared";
import { PartialDeep } from "type-fest";

import { TETE_DE_RESEAUX } from "@/common/constants/networks";
import { SIRET_REGEX_PATTERN, UAI_REGEX_PATTERN, YEAR_RANGE_PATTERN } from "@/common/constants/validations";
import { any, arrayOf, boolean, date, object, objectId, string } from "@/common/model/json-schema/jsonSchemaTypes";

Expand Down
12 changes: 10 additions & 2 deletions server/src/common/model/organisations.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { CreateIndexesOptions, IndexSpecification } from "mongodb";
import { REGIONS, DEPARTEMENTS, ACADEMIES, ACADEMIES_BY_CODE, DEPARTEMENTS_BY_CODE, REGIONS_BY_CODE } from "shared";
import {
REGIONS,
DEPARTEMENTS,
ACADEMIES,
ACADEMIES_BY_CODE,
DEPARTEMENTS_BY_CODE,
REGIONS_BY_CODE,
TETE_DE_RESEAUX,
TETE_DE_RESEAUX_BY_ID,
} from "shared";

import { TETE_DE_RESEAUX, TETE_DE_RESEAUX_BY_ID } from "@/common/constants/networks";
import { ORGANISATIONS_NATIONALES } from "@/common/constants/organisations";
import { SIRET_REGEX_PATTERN, UAI_REGEX_PATTERN } from "@/common/constants/validations";

Expand Down
2 changes: 1 addition & 1 deletion server/src/common/model/organismes.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CreateIndexesOptions, IndexSpecification } from "mongodb";
import { TETE_DE_RESEAUX } from "shared";

import { STATUT_CREATION_ORGANISME, STATUT_FIABILISATION_ORGANISME } from "@/common/constants/fiabilisation";
import { TETE_DE_RESEAUX } from "@/common/constants/networks";
import { SIRET_REGEX_PATTERN, UAI_REGEX_PATTERN } from "@/common/constants/validations";

import { NATURE_ORGANISME_DE_FORMATION, STATUT_PRESENCE_REFERENTIEL } from "../constants/organisme";
Expand Down
2 changes: 1 addition & 1 deletion server/src/common/validation/registrationSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TETE_DE_RESEAUX, TeteDeReseauKey } from "shared";
import { z } from "zod";

import { TETE_DE_RESEAUX, TeteDeReseauKey } from "@/common/constants/networks";
import { ORGANISATIONS_NATIONALES, OrganisationsNationalesKey } from "@/common/constants/organisations";

export const registrationSchema = {
Expand Down
3 changes: 1 addition & 2 deletions server/src/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import express, { Application } from "express";
import Joi from "joi";
import { ObjectId, WithId } from "mongodb";
import passport from "passport";
import { TETE_DE_RESEAUX } from "shared";
import swaggerUi from "swagger-ui-express";
import { z } from "zod";

// catch all unhandled promise rejections and call the error middleware
import "express-async-errors";

Expand Down Expand Up @@ -73,7 +73,6 @@ import { searchOrganismesFormations } from "@/common/actions/organismes/organism
import { createSession } from "@/common/actions/sessions.actions";
import { generateSifa } from "@/common/actions/sifa.actions/sifa.actions";
import { changePassword, updateUserProfile } from "@/common/actions/users.actions";
import { TETE_DE_RESEAUX } from "@/common/constants/networks";
import logger from "@/common/logger";
import { Organisme } from "@/common/model/@types";
import { jobEventsDb, organisationsDb } from "@/common/model/collections";
Expand Down
2 changes: 1 addition & 1 deletion server/tests/integration/http/referentiel.route.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { strict as assert } from "assert";

import { AxiosInstance } from "axiosist";
import { TETE_DE_RESEAUX, TETE_DE_RESEAUX_BY_ID } from "shared";

import { TETE_DE_RESEAUX, TETE_DE_RESEAUX_BY_ID } from "@/common/constants/networks";
import { initTestApp } from "@tests/utils/testUtils";

let httpClient: AxiosInstance;
Expand Down
1 change: 1 addition & 0 deletions shared/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./plausible-goals";
export * from "./sifa";
export * from "./territoires";
export * from "./networks";
24 changes: 16 additions & 8 deletions ui/common/constants/networks.ts → shared/constants/networks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// données à synchroniser avec /server/src/common/constants/networks.ts
// en attendant un import partagé

import { sortAlphabeticallyBy } from "@/common/utils/sortAlphabetically";
import { sortAlphabeticallyBy } from "../utils/sortAlphabetically";

/**
* Noms des réseaux de CFAS
Expand Down Expand Up @@ -51,6 +48,10 @@ export const TETE_DE_RESEAUX = [
nom: "COMPAGNONS DU DEVOIR",
key: "COMP_DU_DEVOIR",
},
{
nom: "COMPAGNONS DU TOUR DE FRANCE",
key: "COMP_DU_TOUR_DE_FRANCE",
},
{
nom: "GRETA",
key: "GRETA",
Expand Down Expand Up @@ -93,11 +94,18 @@ export const TETE_DE_RESEAUX = [
},
] as const;

type ITetesDeReseaux = typeof TETE_DE_RESEAUX;
type ITeteDeReseau = ITetesDeReseaux[number];
type ITeteDeReseauKey = ITeteDeReseau["key"];

export type TeteDeReseauKey = (typeof TETE_DE_RESEAUX)[number]["key"];

export const TETE_DE_RESEAUX_SORTED = sortAlphabeticallyBy("nom", TETE_DE_RESEAUX);

export const TETE_DE_RESEAUX_BY_ID = TETE_DE_RESEAUX.reduce((acc, reseau) => {
acc[reseau.key] = reseau;
return acc;
}, {});
export const TETE_DE_RESEAUX_BY_ID = TETE_DE_RESEAUX.reduce(
(acc, reseau) => {
acc[reseau.key] = reseau;
return acc;
},
{} as Record<ITeteDeReseauKey, ITeteDeReseau>
);
4 changes: 1 addition & 3 deletions ui/common/internal/Organisation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ACADEMIES_BY_CODE, DEPARTEMENTS_BY_CODE, REGIONS_BY_CODE } from "shared";

import { TETE_DE_RESEAUX_BY_ID } from "@/common/constants/networks";
import { ACADEMIES_BY_CODE, DEPARTEMENTS_BY_CODE, REGIONS_BY_CODE, TETE_DE_RESEAUX_BY_ID } from "shared";

// types en doublon avec le serveur
export const organisationTypes = [
Expand Down
3 changes: 1 addition & 2 deletions ui/modules/auth/inscription/InscriptionTeteDeReseau.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FormControl, FormLabel, Select } from "@chakra-ui/react";
import React from "react";

import { TETE_DE_RESEAUX_SORTED } from "@/common/constants/networks";
import { TETE_DE_RESEAUX_SORTED } from "shared";

import { InscriptionOrganistionChildProps } from "./common";

Expand Down
2 changes: 1 addition & 1 deletion ui/modules/dashboard/DashboardOrganisme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { PieCustomLayerProps, ResponsivePie } from "@nivo/pie";
import { useQuery } from "@tanstack/react-query";
import { useRouter } from "next/router";
import { useMemo } from "react";
import { TETE_DE_RESEAUX_BY_ID } from "shared";

import { TETE_DE_RESEAUX_BY_ID } from "@/common/constants/networks";
import { convertOrganismeToExport, organismesExportColumns } from "@/common/exports";
import { _get, _post } from "@/common/httpClient";
import { AuthContext } from "@/common/internal/AuthContext";
Expand Down
2 changes: 1 addition & 1 deletion ui/modules/dashboard/OrganismeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
VStack,
} from "@chakra-ui/react";
import { useQuery } from "@tanstack/react-query";
import { TETE_DE_RESEAUX_BY_ID } from "shared";

import { TETE_DE_RESEAUX_BY_ID } from "@/common/constants/networks";
import { _get } from "@/common/httpClient";
import { Organisme } from "@/common/internal/Organisme";
import Ribbons from "@/components/Ribbons/Ribbons";
Expand Down
3 changes: 1 addition & 2 deletions ui/modules/indicateurs/filters/FiltreOrganismeReseau.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Checkbox, CheckboxGroup, Stack } from "@chakra-ui/react";

import { TETE_DE_RESEAUX_SORTED } from "@/common/constants/networks";
import { TETE_DE_RESEAUX_SORTED } from "shared";

interface FiltreOrganismeReseauProps {
value: string[];
Expand Down
3 changes: 1 addition & 2 deletions ui/pages/auth/inscription/profil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import {
import { Field, Form, Formik } from "formik";
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { ACADEMIES_BY_CODE, DEPARTEMENTS_BY_CODE, REGIONS_BY_CODE } from "shared";
import { ACADEMIES_BY_CODE, DEPARTEMENTS_BY_CODE, REGIONS_BY_CODE, TETE_DE_RESEAUX_BY_ID } from "shared";
import * as Yup from "yup";
import YupPassword from "yup-password";

import { TETE_DE_RESEAUX_BY_ID } from "@/common/constants/networks";
import { _get, _post } from "@/common/httpClient";
import { Organisation } from "@/common/internal/Organisation";
import { getAuthServerSideProps } from "@/common/SSR/getAuthServerSideProps";
Expand Down

0 comments on commit f678f6e

Please sign in to comment.