mirror of
https://gitlab.com/mobicoop/v3/service/auth.git
synced 2026-03-29 15:15:49 +00:00
wip tests update password
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
} from './authentication.types';
|
||||
import { AuthenticationCreatedDomainEvent } from './events/authentication-created.domain-event';
|
||||
import { AuthenticationDeletedDomainEvent } from './events/authentication-deleted.domain-event';
|
||||
import { PasswordUpdatedDomainEvent } from './events/password-updated.domain-event';
|
||||
|
||||
export class AuthenticationEntity extends AggregateRoot<AuthenticationProps> {
|
||||
protected readonly _id: AggregateID;
|
||||
@@ -14,7 +15,7 @@ export class AuthenticationEntity extends AggregateRoot<AuthenticationProps> {
|
||||
create: CreateAuthenticationProps,
|
||||
): Promise<AuthenticationEntity> => {
|
||||
const props: AuthenticationProps = { ...create };
|
||||
const hash = await bcrypt.hash(props.password, 10);
|
||||
const hash = await AuthenticationEntity.encryptPassword(props.password);
|
||||
const authentication = new AuthenticationEntity({
|
||||
id: props.userId,
|
||||
props: {
|
||||
@@ -29,6 +30,15 @@ export class AuthenticationEntity extends AggregateRoot<AuthenticationProps> {
|
||||
return authentication;
|
||||
};
|
||||
|
||||
updatePassword = async (password: string): Promise<void> => {
|
||||
this.props.password = await AuthenticationEntity.encryptPassword(password);
|
||||
this.addEvent(
|
||||
new PasswordUpdatedDomainEvent({
|
||||
aggregateId: this.id,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
delete(): void {
|
||||
this.addEvent(
|
||||
new AuthenticationDeletedDomainEvent({
|
||||
@@ -40,4 +50,7 @@ export class AuthenticationEntity extends AggregateRoot<AuthenticationProps> {
|
||||
validate(): void {
|
||||
// entity business rules validation to protect it's invariant before saving entity to a database
|
||||
}
|
||||
|
||||
private static encryptPassword = async (password: string): Promise<string> =>
|
||||
await bcrypt.hash(password, 10);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { DomainEvent, DomainEventProps } from '@mobicoop/ddd-library';
|
||||
|
||||
export class PasswordUpdatedDomainEvent extends DomainEvent {
|
||||
constructor(props: DomainEventProps<PasswordUpdatedDomainEvent>) {
|
||||
super(props);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user