Skip to content

Commit

Permalink
🐛 Corrections notifier / corriger
Browse files Browse the repository at this point in the history
  • Loading branch information
benjlevesque committed Oct 11, 2024
1 parent a870ce3 commit 14c39a8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Message, MessageHandler, mediator } from 'mediateur';
import { Candidature } from '@potentiel-domain/candidature';
import { RebuildTriggered, Event } from '@potentiel-infrastructure/pg-event-sourcing';
import { DateTime, IdentifiantProjet } from '@potentiel-domain/common';
import { findProjection } from '@potentiel-infrastructure/pg-projections';
import { Option } from '@potentiel-libraries/monads';

import { removeProjection } from '../../infrastructure/removeProjection';
import { upsertProjection } from '../../infrastructure/upsertProjection';
Expand All @@ -25,8 +27,10 @@ export const register = () => {
const identifiantProjet = IdentifiantProjet.convertirEnValueType(
payload.identifiantProjet,
);

const candidature: Omit<Candidature.CandidatureEntity, 'type'> = {
const candidature = await findProjection<Candidature.CandidatureEntity>(
`candidature|${identifiantProjet}`,
);
const candidatureToUpsert: Omit<Candidature.CandidatureEntity, 'type'> = {
identifiantProjet: payload.identifiantProjet,
appelOffre: identifiantProjet.appelOffre,
période: identifiantProjet.période,
Expand Down Expand Up @@ -58,12 +62,13 @@ export const register = () => {
: undefined,
technologie: Candidature.TypeTechnologie.convertirEnValueType(payload.technologie).type,
misÀJourLe: type === 'CandidatureCorrigée-V1' ? payload.corrigéLe : payload.importéLe,
estNotifiée: false,
estNotifiée: Option.isSome(candidature) ? candidature.estNotifiée : false,
notification: Option.isSome(candidature) ? candidature.notification : undefined,
};

await upsertProjection<Candidature.CandidatureEntity>(
`candidature|${payload.identifiantProjet}`,
candidature,
candidatureToUpsert,
);
break;
case 'CandidatureNotifiée-V1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const CorrigerCandidaturePage: React.FC<CorrigerCandidaturePageProps> = (
nom={candidature.nomProjet}
badge={
<div className="flex gap-2">
<StatutProjetBadge statut={candidature.statut} />
{candidature.statut && <StatutProjetBadge statut={candidature.statut} />}
<NotificationBadge estNotifié={estNotifiée} />
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const mapBodyToUseCaseData = (
puissanceALaPointeValue: data.puissanceALaPointe,
evaluationCarboneSimplifiéeValue: data.evaluationCarboneSimplifiee,
actionnariatValue: data.actionnariat,
statutValue: data.statut,
statutValue: data.statut ?? previous.statut.formatter(),

// non-editable fields
typeGarantiesFinancièresValue: previous.typeGarantiesFinancières?.type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ export const candidatureSchema = z
)
.transform((val) => val.join(' / ')),
commune: requiredStringSchema,

statut: z.enum(Candidature.StatutCandidature.statuts),
// optionnel car une fois notifié, ce champs n'est plus modifiable
statut: z.enum(Candidature.StatutCandidature.statuts).optional(),
puissanceALaPointe: z
.string()
.toLowerCase()
Expand Down
2 changes: 2 additions & 0 deletions packages/domain/utilisateur/src/role.valueType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ const policies = {
référencielPermissions.lauréat.command.notifier,
référencielPermissions.éliminé.usecase.notifier,
référencielPermissions.éliminé.command.notifier,
référencielPermissions.candidature.usecase.notifier,
référencielPermissions.candidature.command.notifier,
],
},
} as const;
Expand Down

0 comments on commit 14c39a8

Please sign in to comment.