-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4da0e44
commit 3f9ec8e
Showing
21 changed files
with
331 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/domain/réseau/src/raccordement/modifier/modifierDateMiseEnService.behavior.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { DateTime, IdentifiantProjet } from '@potentiel-domain/common'; | ||
import { DomainEvent, InvalidOperationError } from '@potentiel-domain/core'; | ||
import { Option } from '@potentiel-libraries/monads'; | ||
|
||
import * as RéférenceDossierRaccordement from '../référenceDossierRaccordement.valueType'; | ||
import { RaccordementAggregate } from '../raccordement.aggregate'; | ||
import { DateDansLeFuturError } from '../dateDansLeFutur.error'; | ||
|
||
export type DateMiseEnServiceModifiéeEvent = DomainEvent< | ||
'DateMiseEnServiceModifiée-V1', | ||
{ | ||
dateMiseEnService: DateTime.RawType; | ||
référenceDossierRaccordement: RéférenceDossierRaccordement.RawType; | ||
identifiantProjet: IdentifiantProjet.RawType; | ||
} | ||
>; | ||
|
||
type ModifierDateMiseEnServiceOptions = { | ||
dateMiseEnService: DateTime.ValueType; | ||
dateDésignation: DateTime.ValueType; | ||
identifiantProjet: IdentifiantProjet.ValueType; | ||
référenceDossier: RéférenceDossierRaccordement.ValueType; | ||
}; | ||
|
||
export async function modifierDateMiseEnService( | ||
this: RaccordementAggregate, | ||
{ | ||
dateMiseEnService, | ||
dateDésignation, | ||
identifiantProjet, | ||
référenceDossier, | ||
}: ModifierDateMiseEnServiceOptions, | ||
) { | ||
if (dateMiseEnService.estDansLeFutur()) { | ||
throw new DateDansLeFuturError(); | ||
} | ||
|
||
if (dateMiseEnService.estAntérieurÀ(dateDésignation)) { | ||
throw new DateMiseEnServiceAntérieureDateDésignationProjetError(); | ||
} | ||
|
||
const dossier = this.récupérerDossier(référenceDossier.formatter()); | ||
if (Option.isNone(dossier.miseEnService.dateMiseEnService)) { | ||
throw new AucuneDateDeMiseEnServiceTransmiseError(); | ||
} | ||
|
||
if (!this.dateModifiée(référenceDossier, dateMiseEnService)) { | ||
throw new DateDeMiseEnServiceInchangéeError(); | ||
} | ||
|
||
const dateMiseEnServiceModifiée: DateMiseEnServiceModifiéeEvent = { | ||
type: 'DateMiseEnServiceModifiée-V1', | ||
payload: { | ||
dateMiseEnService: dateMiseEnService.formatter(), | ||
identifiantProjet: identifiantProjet.formatter(), | ||
référenceDossierRaccordement: référenceDossier.formatter(), | ||
}, | ||
}; | ||
|
||
await this.publish(dateMiseEnServiceModifiée); | ||
} | ||
|
||
export function applyDateMiseEnServiceModifiéeEventV1( | ||
this: RaccordementAggregate, | ||
{ payload: { dateMiseEnService, référenceDossierRaccordement } }: DateMiseEnServiceModifiéeEvent, | ||
) { | ||
const dossier = this.récupérerDossier(référenceDossierRaccordement); | ||
dossier.miseEnService.dateMiseEnService = DateTime.convertirEnValueType(dateMiseEnService); | ||
} | ||
|
||
export class DateMiseEnServiceAntérieureDateDésignationProjetError extends InvalidOperationError { | ||
constructor() { | ||
super( | ||
`La date de mise en service ne peut pas être antérieure à la date de désignation du projet`, | ||
); | ||
} | ||
} | ||
|
||
class AucuneDateDeMiseEnServiceTransmiseError extends InvalidOperationError { | ||
constructor() { | ||
super(`Aucune date de mise en service n'a encore été transmise`); | ||
} | ||
} | ||
|
||
class DateDeMiseEnServiceInchangéeError extends InvalidOperationError { | ||
constructor() { | ||
super(`La date de mise en service est inchangée`); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/domain/réseau/src/raccordement/modifier/modifierDateMiseEnService.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Message, MessageHandler, mediator } from 'mediateur'; | ||
|
||
import { DateTime, IdentifiantProjet } from '@potentiel-domain/common'; | ||
import { LoadAggregate } from '@potentiel-domain/core'; | ||
import { Lauréat } from '@potentiel-domain/laureat'; | ||
|
||
import * as RéférenceDossierRaccordement from '../référenceDossierRaccordement.valueType'; | ||
import { loadRaccordementAggregateFactory } from '../raccordement.aggregate'; | ||
|
||
export type ModifierDateMiseEnServiceCommand = Message< | ||
'Réseau.Raccordement.Command.ModifierDateMiseEnService', | ||
{ | ||
dateMiseEnService: DateTime.ValueType; | ||
référenceDossier: RéférenceDossierRaccordement.ValueType; | ||
identifiantProjet: IdentifiantProjet.ValueType; | ||
} | ||
>; | ||
|
||
export const registerModifierDateMiseEnServiceCommand = (loadAggregate: LoadAggregate) => { | ||
const loadRaccordementAggregate = loadRaccordementAggregateFactory(loadAggregate); | ||
const loadLauréatAggregate = Lauréat.loadLauréatFactory(loadAggregate); | ||
|
||
const handler: MessageHandler<ModifierDateMiseEnServiceCommand> = async ({ | ||
dateMiseEnService, | ||
référenceDossier, | ||
identifiantProjet, | ||
}) => { | ||
const raccordement = await loadRaccordementAggregate(identifiantProjet); | ||
const laureát = await loadLauréatAggregate(identifiantProjet); | ||
|
||
await raccordement.modifierDateMiseEnService({ | ||
dateDésignation: laureát.notifiéLe, | ||
dateMiseEnService, | ||
identifiantProjet, | ||
référenceDossier, | ||
}); | ||
}; | ||
|
||
mediator.register('Réseau.Raccordement.Command.ModifierDateMiseEnService', handler); | ||
}; |
40 changes: 40 additions & 0 deletions
40
packages/domain/réseau/src/raccordement/modifier/modifierDateMiseEnService.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Message, MessageHandler, mediator } from 'mediateur'; | ||
|
||
import { DateTime, IdentifiantProjet } from '@potentiel-domain/common'; | ||
|
||
import * as RéférenceDossierRaccordement from '../référenceDossierRaccordement.valueType'; | ||
|
||
import { ModifierDateMiseEnServiceCommand } from './modifierDateMiseEnService.command'; | ||
|
||
export type ModifierDateMiseEnServiceUseCase = Message< | ||
'Réseau.Raccordement.UseCase.ModifierDateMiseEnService', | ||
{ | ||
dateMiseEnServiceValue: string; | ||
référenceDossierValue: string; | ||
identifiantProjetValue: string; | ||
} | ||
>; | ||
|
||
export const registerModifierDateMiseEnServiceUseCase = () => { | ||
const runner: MessageHandler<ModifierDateMiseEnServiceUseCase> = async ({ | ||
dateMiseEnServiceValue, | ||
référenceDossierValue, | ||
identifiantProjetValue, | ||
}) => { | ||
const dateMiseEnService = DateTime.convertirEnValueType(dateMiseEnServiceValue); | ||
const identifiantProjet = IdentifiantProjet.convertirEnValueType(identifiantProjetValue); | ||
const référenceDossier = | ||
RéférenceDossierRaccordement.convertirEnValueType(référenceDossierValue); | ||
|
||
await mediator.send<ModifierDateMiseEnServiceCommand>({ | ||
type: 'Réseau.Raccordement.Command.ModifierDateMiseEnService', | ||
data: { | ||
dateMiseEnService, | ||
identifiantProjet, | ||
référenceDossier, | ||
}, | ||
}); | ||
}; | ||
|
||
mediator.register('Réseau.Raccordement.UseCase.ModifierDateMiseEnService', runner); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.