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

♻️ Ajouter validateur dans l'event NotifierCandidature #2298

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const register = () => {
notifiéePar,
},
} = event;

switch (event.type) {
case 'CandidatureNotifiée-V1':
const candidature = await mediator.send<Candidature.ConsulterCandidatureQuery>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export const register = () => {
estNotifiée: true,
notifiéeLe: payload.notifiéeLe,
notifiéePar: payload.notifiéePar,
validateur: {
fonction: payload.validateur.fonction,
nomComplet: payload.validateur.nomComplet,
},
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,36 @@ import { Candidature } from '@potentiel-domain/candidature';
import { listProjection } from '@potentiel-infrastructure/pg-projections';
import { Lauréat } from '@potentiel-domain/laureat';
import { loadAggregate } from '@potentiel-infrastructure/pg-event-sourcing';
import { ConsulterUtilisateurQuery } from '@potentiel-domain/utilisateur';
import { Option } from '@potentiel-libraries/monads';

Candidature.registerCandidaturesUseCases({ loadAggregate });

(async () => {
console.log('✨ Migration Candidature Notifiée');

const lauréats = await listProjection<Lauréat.LauréatEntity>('lauréat');
const éliminés = await listProjection<Éliminé.ÉliminéEntity>('éliminé');
const all = [...lauréats.items, ...éliminés.items];

console.log(`ℹ️ ${all.length} éléments trouvés`);

for (const { identifiantProjet, attestation, notifiéLe, notifiéPar } of all) {
console.log(`Get détails on notifiéPar for ${identifiantProjet}`);
const utilisateur = await mediator.send<ConsulterUtilisateurQuery>({
type: 'Utilisateur.Query.ConsulterUtilisateur',
data: {
identifiantUtilisateur: notifiéPar,
},
});

if (Option.isNone(utilisateur)) {
console.warn(`Utilisateur non trouvé`, {
identifiantProjet,
identifiantUtilisateur: notifiéPar,
});
}

console.log(`Publish NotifierCandidature pour ${identifiantProjet}`);
await mediator.publish<Candidature.NotifierCandidatureUseCase>({
type: 'Candidature.UseCase.NotifierCandidature',
Expand All @@ -25,6 +43,10 @@ Candidature.registerCandidaturesUseCases({ loadAggregate });
attestationValue: { format: attestation.format },
notifiéeLeValue: notifiéLe,
notifiéeParValue: notifiéPar,
validateurValue: {
fonction: Option.isNone(utilisateur) ? 'fonction inconnue' : utilisateur.fonction,
nomComplet: Option.isNone(utilisateur) ? 'validateur inconnu' : utilisateur.nomComplet,
},
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import * as zod from 'zod';
import { mediator } from 'mediateur';
import { notFound } from 'next/navigation';

import { DateTime } from '@potentiel-domain/common';
import { Candidature } from '@potentiel-domain/candidature';
import { Période } from '@potentiel-domain/periode';
import { IdentifiantPériode } from '@potentiel-domain/periode/dist/période';
import { Routes } from '@potentiel-applications/routes';
import { ConsulterUtilisateurQuery } from '@potentiel-domain/utilisateur';
import { Option } from '@potentiel-libraries/monads';

import { FormAction, formAction, FormState } from '@/utils/formAction';
import { withUtilisateur } from '@/utils/withUtilisateur';
Expand All @@ -30,12 +33,27 @@ const action: FormAction<FormState, typeof schema> = async (_, { appelOffre, per
},
});

const utilisateurDetails = await mediator.send<ConsulterUtilisateurQuery>({
type: 'Utilisateur.Query.ConsulterUtilisateur',
data: {
identifiantUtilisateur: utilisateur.identifiantUtilisateur.formatter(),
},
});

if (Option.isNone(utilisateurDetails)) {
return notFound();
}

await mediator.send<Période.NotifierPériodeUseCase>({
type: 'Période.UseCase.NotifierPériode',
data: {
identifiantPériodeValue,
notifiéeLeValue: DateTime.now().formatter(),
notifiéeParValue: utilisateur.identifiantUtilisateur.formatter(),
validateurValue: {
fonction: utilisateurDetails.fonction,
nomComplet: utilisateurDetails.nomComplet,
},
identifiantCandidatureValues: candidatures.items.map((candidatures) =>
candidatures.identifiantProjet.formatter(),
),
Expand Down
4 changes: 4 additions & 0 deletions packages/domain/candidature/src/candidature.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export type CandidatureEntity = Entity<
estNotifiée: true;
notifiéeLe: DateTime.RawType;
notifiéePar: Email.RawType;
validateur: {
fonction: string;
nomComplet: string;
};
};
}
>;
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export type ConsulterCandidatureReadModel = {
notification?: {
notifiéeLe: DateTime.ValueType;
notifiéePar: Email.ValueType;
validateur: {
fonction: string;
nomComplet: string;
};
};
};

Expand Down Expand Up @@ -130,5 +134,9 @@ export const mapToReadModel = ({
notification: notification && {
notifiéeLe: DateTime.convertirEnValueType(notification.notifiéeLe),
notifiéePar: Email.convertirEnValueType(notification.notifiéePar),
validateur: {
fonction: notification.validateur.fonction,
nomComplet: notification.validateur.nomComplet,
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export type NotifierOptions = {
identifiantProjet: IdentifiantProjet.ValueType;
notifiéeLe: DateTime.ValueType;
notifiéePar: Email.ValueType;
validateur: {
fonction: string;
nomComplet: string;
};
attestation: {
format: string;
};
Expand All @@ -18,7 +22,10 @@ export type CandidatureNotifiéeEvent = DomainEvent<
identifiantProjet: IdentifiantProjet.RawType;
notifiéeLe: DateTime.RawType;
notifiéePar: Email.RawType;

validateur: {
fonction: string;
nomComplet: string;
};
attestation: {
format: string;
};
Expand All @@ -27,17 +34,25 @@ export type CandidatureNotifiéeEvent = DomainEvent<

export async function notifier(
this: CandidatureAggregate,
{ identifiantProjet, notifiéeLe, notifiéePar, attestation: { format } }: NotifierOptions,
{
identifiantProjet,
notifiéeLe,
notifiéePar,
validateur,
attestation: { format },
}: NotifierOptions,
) {
if (this.estNotifiée) {
throw new CandidatureDéjàNotifiéeError(identifiantProjet);
}

const event: CandidatureNotifiéeEvent = {
type: 'CandidatureNotifiée-V1',
payload: {
identifiantProjet: identifiantProjet.formatter(),
notifiéeLe: notifiéeLe.formatter(),
notifiéePar: notifiéePar.formatter(),
validateur,
VioMrqs marked this conversation as resolved.
Show resolved Hide resolved
attestation: {
format,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export type NotifierCandidatureCommand = Message<
identifiantProjet: IdentifiantProjet.ValueType;
notifiéeLe: DateTime.ValueType;
notifiéePar: Email.ValueType;
validateur: {
fonction: string;
nomComplet: string;
};
attestation: { format: string };
}
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export type NotifierCandidatureUseCase = Message<
identifiantProjetValue: string;
notifiéeLeValue: string;
notifiéeParValue: string;
validateurValue: {
fonction: string;
nomComplet: string;
};
attestationValue: {
format: string;
};
Expand All @@ -21,6 +25,7 @@ export const registerNotifierCandidatureUseCase = () => {
identifiantProjetValue,
notifiéeParValue,
notifiéeLeValue,
validateurValue,
attestationValue: { format },
}) => {
await mediator.send<NotifierCandidatureCommand>({
Expand All @@ -29,6 +34,7 @@ export const registerNotifierCandidatureUseCase = () => {
identifiantProjet: IdentifiantProjet.convertirEnValueType(identifiantProjetValue),
notifiéeLe: DateTime.convertirEnValueType(notifiéeLeValue),
notifiéePar: Email.convertirEnValueType(notifiéeParValue),
validateur: validateurValue,
attestation: { format },
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export type NotifierLauréatUseCase = Message<
identifiantProjetValue: string;
notifiéLeValue: string;
notifiéParValue: string;
validateurValue: {
fonction: string;
nomComplet: string;
};
attestationValue: {
format: string;
};
Expand All @@ -22,6 +26,7 @@ export const registerNotifierLauréatUseCase = () => {
identifiantProjetValue,
notifiéParValue,
notifiéLeValue,
validateurValue,
attestationValue: { format },
}) => {
await mediator.send<Candidature.NotifierCandidatureUseCase>({
Expand All @@ -30,6 +35,7 @@ export const registerNotifierLauréatUseCase = () => {
identifiantProjetValue,
notifiéeLeValue: notifiéLeValue,
notifiéeParValue: notifiéParValue,
validateurValue,
attestationValue: {
format: 'application/pdf',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export type NotifierPériodeCommand = Message<
identifiantPériode: IdentifiantPériode.ValueType;
notifiéeLe: DateTime.ValueType;
notifiéePar: Email.ValueType;
validateur: {
fonction: string;
nomComplet: string;
};
identifiantCandidatures: ReadonlyArray<IdentifiantProjet.ValueType>;
}
>;
Expand All @@ -28,6 +32,7 @@ export const registerNotifierPériodeCommand = (loadAggregate: LoadAggregate) =>
identifiantPériode,
notifiéeLe,
notifiéePar,
validateur,
identifiantCandidatures,
}) => {
const identifiantLauréats: Array<IdentifiantProjet.ValueType> = [];
Expand All @@ -38,12 +43,14 @@ export const registerNotifierPériodeCommand = (loadAggregate: LoadAggregate) =>

try {
if (candidature.statut?.estClassé()) {
// TODO: devrait être appelé dans le usecase NotifierPériode
await mediator.send<Lauréat.NotifierLauréatUseCase>({
type: 'Lauréat.UseCase.NotifierLauréat',
data: {
identifiantProjetValue: identifiantCandidature.formatter(),
notifiéLeValue: notifiéeLe.formatter(),
notifiéParValue: notifiéePar.formatter(),
validateurValue: validateur,
attestationValue: {
format: 'application/pdf',
},
Expand All @@ -54,12 +61,14 @@ export const registerNotifierPériodeCommand = (loadAggregate: LoadAggregate) =>
}

if (candidature.statut?.estÉliminé()) {
// TODO: devrait être appelé dans le usecase NotifierPériode
await mediator.send<Éliminé.NotifierÉliminéUseCase>({
type: 'Éliminé.UseCase.NotifierÉliminé',
data: {
identifiantProjetValue: identifiantCandidature.formatter(),
notifiéLeValue: notifiéeLe.formatter(),
notifiéParValue: notifiéePar.formatter(),
validateurValue: validateur,
attestationValue: {
format: 'application/pdf',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export type NotifierPériodeUseCase = Message<
identifiantPériodeValue: IdentifiantPériode.RawType;
notifiéeLeValue: DateTime.RawType;
notifiéeParValue: Email.RawType;
validateurValue: {
fonction: string;
nomComplet: string;
};
identifiantCandidatureValues: ReadonlyArray<IdentifiantProjet.RawType>;
}
>;
Expand All @@ -21,6 +25,7 @@ export const registerNotifierPériodeUseCase = () => {
identifiantPériodeValue,
notifiéeLeValue,
notifiéeParValue,
validateurValue,
identifiantCandidatureValues,
}) => {
const identifiantPériode = IdentifiantPériode.convertirEnValueType(identifiantPériodeValue);
Expand All @@ -31,6 +36,7 @@ export const registerNotifierPériodeUseCase = () => {
identifiantPériode,
notifiéeLe: DateTime.convertirEnValueType(notifiéeLeValue),
notifiéePar: Email.convertirEnValueType(notifiéeParValue),
validateur: validateurValue,
identifiantCandidatures: identifiantCandidatureValues.map((identifiantCandidatureValue) =>
IdentifiantProjet.convertirEnValueType(identifiantCandidatureValue),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export type NotifierÉliminéUseCase = Message<
identifiantProjetValue: string;
notifiéLeValue: string;
notifiéParValue: string;
validateurValue: {
fonction: string;
nomComplet: string;
};
attestationValue: {
format: string;
};
Expand All @@ -22,6 +26,7 @@ export const registerNotifierÉliminéUseCase = () => {
identifiantProjetValue,
notifiéLeValue,
notifiéParValue,
validateurValue,
attestationValue: { format },
}) => {
await mediator.send<Candidature.NotifierCandidatureUseCase>({
Expand All @@ -30,6 +35,7 @@ export const registerNotifierÉliminéUseCase = () => {
identifiantProjetValue,
notifiéeLeValue: notifiéLeValue,
notifiéeParValue: notifiéParValue,
validateurValue,
attestationValue: {
format: 'application/pdf',
},
Expand Down

This file was deleted.

Loading