Skip to content

Commit

Permalink
Merge pull request #45 from SocialGouv/feat-73-permettre_saisie_DS_pe…
Browse files Browse the repository at this point in the history
…rsonne_physique

feat: 73 saisie DS personne physique
  • Loading branch information
gweill-guigops authored Mar 11, 2024
2 parents eeaa78f + 66336a1 commit 9ecea5d
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 54 deletions.
6 changes: 3 additions & 3 deletions packages/backend/src/controllers/operateur/getSiege.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const log = logger(module.filename);

module.exports = async function get(req, res) {
log.i("In");
const { siret } = req.params;
if (!siret) {
const { siren } = req.params;
if (!siren) {
log.w("missing or invalid parameter");
return res.status(400).json({ message: "paramètre manquant ou erroné." });
}
try {
const operateur = await Operateur.getSiege(siret);
const operateur = await Operateur.getSiege(siren);
log.d(operateur);
return res.status(200).json({ operateur });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/routes/operateur.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const operateurController = require("../controllers/operateur");
// Gère une connexion via mot de passe.
router.get("/", checkJWT, operateurController.getMine);
router.get("/siret/:siret", checkJWT, operateurController.getBySiret);
router.get("/siege/:siret", checkJWT, operateurController.getSiege);
router.get("/siege/:siren", checkJWT, operateurController.getSiege);
router.get("/:id", checkJWT, operateurController.getByOperateurId);
router.post("/:id", checkJWT, operateurController.update);
router.post("/", checkJWT, operateurController.post);
Expand Down
26 changes: 13 additions & 13 deletions packages/backend/src/services/Operateur.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ const query = {
o.personne_physique as "personnePhysique",
o.protocole_transport as "protocoleTransport",
o.protocole_sanitaire as "protocoleSanitaire",
o.created_at as "createdAt",
o.edited_at as "editedAt",
(
SELECT
json_build_object(
'numero', numero,
'filename', filename,
'uuid', uuid,
'regionDelivrance', region_delivrance,
'dateObtention', date_obtention,
'createdAt',a.created_at
json_build_object(
'numero', numero,
'filename', filename,
'uuid', uuid,
'regionDelivrance', region_delivrance,
'dateObtention', date_obtention,
'createdAt',a.created_at
)
FROM front.agrements a
WHERE operateur_id = o.id
AND a.supprime = false
) AS agrement
FROM front.agrements a
WHERE operateur_id = o.id
AND a.supprime = false
) AS agrement,
o.created_at as "createdAt",
o.edited_at as "editedAt"
FROM front.operateurs o
JOIN front.user_operateur uo ON o.id = ope_id
WHERE o.personne_morale->>'siren' = $1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
import { useField, useForm } from "vee-validate";
import * as yup from "yup";
import dayjs from "dayjs";
import { useOperateurStore } from "@/stores/operateur";
const nuxtApp = useNuxtApp();
const toaster = nuxtApp.vueApp.$toast;
Expand All @@ -119,6 +118,7 @@ const emit = defineEmits(["next", "update"]);
const log = logger("components/DS/informations-generales");
const operateurStore = useOperateurStore();
const userStore = useUserStore();
const duree = computed(() => {
const nbjours = dayjs(dateFin.value).diff(dateDebut.value, "day");
Expand All @@ -133,12 +133,13 @@ const saison = computed(() => {
if (moisDebut < 12) return "automne";
});
if (!operateurStore.operateurCourant) {
await operateurStore.setMyOperateur();
}
const operateurCourant = computed(() => {
return operateurStore.operateurCourant;
});
if (
operateurStore.operateurCourant.typeOperateur === "personne_morale" &&
!operateurStore.operateurCourant.personneMorale.siegeSocial
operateurCourant.value.typeOperateur === "personne_morale" &&
!operateurCourant.value.personneMorale.siegeSocial
) {
await checkSiege();
}
Expand Down Expand Up @@ -173,8 +174,16 @@ const validationSchema = yup.object({
});
const initialValues = computed(() => {
const responsableSejour =
operateurStore.operateurCourant.personneMorale?.responsableSejour ?? {};
const responsableSejour = operateurCourant.value.personneMorale.siret
? operateurCourant.value.personneMorale.responsableSejour
: {
nom: operateurCourant.value.personnePhysique.nomNaissance,
prenom: operateurCourant.value.personnePhysique.prenom,
fonction: "organisateur de séjour",
email: userStore.user.email,
telephone: operateurCourant.value.personnePhysique.telephone,
adresse: operateurCourant.value.personnePhysique.adresseSiege,
};
return {
libelle: props.initData.libelle,
dateDebut: props.initData.dateDebut
Expand Down Expand Up @@ -225,25 +234,30 @@ async function checkSiege() {
const nic =
operateurStore.operateurCourant.personneMorale.siret.substring(9);
log.d(etablissementPrincipal);
if (!etablissementPrincipal || etablissementPrincipal.length === 0) {
if (!etablissementPrincipal) {
toaster.error(
"L'établissement principal n'a pas encore déclaré son agrément sur la plateforme VAO.",
);
return navigateTo("/");
} else {
if (
!etablissementPrincipal.personneMorale.etablissements.filter(
(e) => e.nic === nic,
)[0].enabled
) {
toaster.error(
"L'établissement principal n'a pas autorisé votre établissement à saisir des déclarations.",
);
return navigateTo("/");
}
}
const e = (
etablissementPrincipal.personneMorale?.etablissements ?? []
).find((e) => e.nic === nic);
if (!e) {
toaster.error(
"Votre établissement n'est pas rattaché à l'établissement principal. Rapprochez-vous de l'établissement principal.",
);
return navigateTo("/");
}
if (!e.enabled) {
toaster.error(
"L'établissement principal n'a pas autorisé votre établissement à saisir des déclarations.",
);
return navigateTo("/");
}
} catch (error) {
log.w(error);
toaster.error("Une erreur est survenue. Veuillez réessayer ultérieurement");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import { useDemandeSejourStore } from "~/stores/demande-sejour";
import { useOperateurStore } from "~/stores/operateur";
import { logger } from "#imports";
import { navigateTo, defineNuxtRouteMiddleware } from "#app";
import { computed } from "vue";

const log = logger("middlewares/has-id-demande-sejour");
const log = logger("middlewares/check-id-demande-sejour-param");

export default defineNuxtRouteMiddleware(async (to) => {
log.i("IN", to.params.idDemande);
const hasId = !!to.params.idDemande;
const demandeStore = useDemandeSejourStore();
await demandeStore.fetchDemandes();

const isIdViewable = computed(() => {
return !!demandeStore.demandes.find(
(i) => i.demandeSejourId.toString() === to.params.idDemande,
);
});
const operateurStore = useOperateurStore();

if (isNaN(to.params.idDemande)) {
log.w(`incorrect demandeId : ${to.params.idDemande}`);
return navigateTo("/");
}
if (hasId && !isIdViewable.value) {

await operateurStore.setMyOperateur();
await demandeStore.fetchDemandes();

if (
!operateurStore.operateurCourant ||
!operateurStore.operateurCourant.complet
) {
log.w("current operateur is not defined or incomplete, back to home");
return navigateTo("/");
}

const isIdViewable = !!demandeStore.demandes.find(
(i) => i.demandeSejourId.toString() === to.params.idDemande,
);

if (hasId && !isIdViewable) {
log.w(`demande ${to.params.idDemande} is not linked with current user`);
return navigateTo("/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useHebergementStore } from "~/stores/hebergement";
import { defineNuxtRouteMiddleware, navigateTo } from "#app";
import { logger } from "#imports";

const log = logger("middlewares/has-id-hebergement");
const log = logger("middlewares/check-id-hebergement-param");

export default defineNuxtRouteMiddleware(async (to) => {
log.i("IN", { to });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { useOperateurStore } from "~/stores/operateur";
import { defineNuxtRouteMiddleware, navigateTo } from "#app";
import { logger } from "#imports";

const log = logger("middlewares/has-id-operateur");
const log = logger("middlewares/check-id-operateur-param");

export default defineNuxtRouteMiddleware(async (to) => {
log.i("IN", { to });

if (to.params.idOperateur && isNaN(to.params.idOperateur)) {
log.w("invalid param");
return navigateTo("/operateur");
Expand All @@ -19,11 +18,14 @@ export default defineNuxtRouteMiddleware(async (to) => {
log.d("Création organisme");
return;
}

if (to.params.idOperateur && !operateurStore.operateurCourant) {
log.w("opérateur non accessible");
return navigateTo("/operateur");
}

if (!to.params.idOperateur) {
log.i("redirection vers route complète");
const url = `/operateur/${operateurStore.operateurCourant.operateurId}`;
return navigateTo({ path: url, hash: to.hash });
}
Expand All @@ -33,7 +35,6 @@ export default defineNuxtRouteMiddleware(async (to) => {
to.params.idOperateur
) {
log.w(`operator ${to.params.idOperateur} is not owned by current user`);
log.d("adding correct operateurId to url");
const url = `/operateur/${operateurStore.operateurCourant.operateurId}`;
return navigateTo(url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const nuxtApp = useNuxtApp();
const toaster = nuxtApp.vueApp.$toast;
definePageMeta({
middleware: ["is-connected", "has-id-demande-sejour"],
middleware: ["is-connected", "check-id-demande-sejour-param"],
layout: "demande-sejour",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<script setup>
definePageMeta({
middleware: ["is-connected", "has-id-hebergement"],
middleware: ["is-connected", "check-id-hebergement-param"],
});
const nuxtApp = useNuxtApp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const toaster = nuxtApp.vueApp.$toast;
const log = logger("pages/operateur/[[idOperateur]]");
definePageMeta({
middleware: ["is-connected", "has-id-operateur"],
middleware: ["is-connected", "check-id-operateur-param"],
layout: "operateur",
});
Expand Down

0 comments on commit 9ecea5d

Please sign in to comment.