delete username usecase

This commit is contained in:
sbriat
2023-07-07 11:11:36 +02:00
parent a95caefaf2
commit 28c6ca0f63
12 changed files with 274 additions and 1 deletions

View File

@@ -0,0 +1,7 @@
import { DomainEvent, DomainEventProps } from '@mobicoop/ddd-library';
export class UsernameDeletedDomainEvent extends DomainEvent {
constructor(props: DomainEventProps<UsernameDeletedDomainEvent>) {
super(props);
}
}

View File

@@ -1,6 +1,7 @@
import { AggregateID, AggregateRoot } from '@mobicoop/ddd-library';
import { CreateUsernameProps, UsernameProps } from './username.types';
import { UsernameAddedDomainEvent } from './events/username-added.domain-event';
import { UsernameDeletedDomainEvent } from './events/username-deleted.domain-event';
export class UsernameEntity extends AggregateRoot<UsernameProps> {
protected readonly _id: AggregateID;
@@ -23,6 +24,14 @@ export class UsernameEntity extends AggregateRoot<UsernameProps> {
return username;
};
delete(): void {
this.addEvent(
new UsernameDeletedDomainEvent({
aggregateId: this.id,
}),
);
}
validate(): void {
// entity business rules validation to protect it's invariant before saving entity to a database
}