update username

This commit is contained in:
sbriat
2023-07-07 17:50:49 +02:00
parent 28c6ca0f63
commit 805a7fe24d
14 changed files with 372 additions and 3 deletions

View File

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

View File

@@ -1,7 +1,12 @@
import { AggregateID, AggregateRoot } from '@mobicoop/ddd-library';
import { CreateUsernameProps, UsernameProps } from './username.types';
import {
CreateUsernameProps,
UpdateUsernameProps,
UsernameProps,
} from './username.types';
import { UsernameAddedDomainEvent } from './events/username-added.domain-event';
import { UsernameDeletedDomainEvent } from './events/username-deleted.domain-event';
import { UsernameUpdatedDomainEvent } from './events/username-updated.domain-event';
export class UsernameEntity extends AggregateRoot<UsernameProps> {
protected readonly _id: AggregateID;
@@ -24,6 +29,15 @@ export class UsernameEntity extends AggregateRoot<UsernameProps> {
return username;
};
update(props: UpdateUsernameProps): void {
this.props.name = props.name;
this.addEvent(
new UsernameUpdatedDomainEvent({
aggregateId: props.name,
}),
);
}
delete(): void {
this.addEvent(
new UsernameDeletedDomainEvent({

View File

@@ -10,6 +10,10 @@ export interface CreateUsernameProps {
type: Type;
}
export interface UpdateUsernameProps {
name: string;
}
export enum Type {
EMAIL = 'EMAIL',
PHONE = 'PHONE',