Skip to content

Commit

Permalink
Merge pull request #146 from franco4457/master
Browse files Browse the repository at this point in the history
fix: native crypto import
  • Loading branch information
Sairyss authored Dec 27, 2023
2 parents 82250c6 + fedad99 commit f50b71b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/libs/ddd/command.base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RequestContextService } from '@libs/application/context/AppRequestContext';
import { ArgumentNotProvidedException } from '../exceptions';
import { Guard } from '../guard';
import { randomUUID } from 'crypto';

export type CommandProps<T> = Omit<T, 'id' | 'metadata'> & Partial<Command>;

Expand Down Expand Up @@ -42,7 +43,7 @@ export class Command {
);
}
const ctx = RequestContextService.getContext();
this.id = props.id || crypto.randomUUID();
this.id = props.id || randomUUID();
this.metadata = {
correlationId: props?.metadata?.correlationId || ctx.requestId,
causationId: props?.metadata?.causationId,
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ddd/domain-event.base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { randomUUID } from 'crypto';
import { ArgumentNotProvidedException } from '../exceptions';
import { Guard } from '../guard';
import { RequestContextService } from '@libs/application/context/AppRequestContext';
Expand Down Expand Up @@ -40,7 +41,7 @@ export abstract class DomainEvent {
'DomainEvent props should not be empty',
);
}
this.id = crypto.randomUUID();
this.id = randomUUID();
this.aggregateId = props.aggregateId;
this.metadata = {
correlationId:
Expand Down
3 changes: 2 additions & 1 deletion src/modules/user/domain/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import {
import { UserDeletedDomainEvent } from './events/user-deleted.domain-event';
import { UserRoleChangedDomainEvent } from './events/user-role-changed.domain-event';
import { UserAddressUpdatedDomainEvent } from './events/user-address-updated.domain-event';
import { randomUUID } from 'crypto';

export class UserEntity extends AggregateRoot<UserProps> {
protected readonly _id: AggregateID;

static create(create: CreateUserProps): UserEntity {
const id = crypto.randomUUID();
const id = randomUUID();
/* Setting a default role since we are not accepting it during creation. */
const props: UserProps = { ...create, role: UserRoles.guest };
const user = new UserEntity({ id, props });
Expand Down
3 changes: 2 additions & 1 deletion src/modules/wallet/domain/wallet.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ArgumentOutOfRangeException } from '@libs/exceptions';
import { Err, Ok, Result } from 'oxide.ts';
import { WalletCreatedDomainEvent } from './events/wallet-created.domain-event';
import { WalletNotEnoughBalanceError } from './wallet.errors';
import { randomUUID } from 'crypto';

export interface CreateWalletProps {
userId: AggregateID;
Expand All @@ -16,7 +17,7 @@ export class WalletEntity extends AggregateRoot<WalletProps> {
protected readonly _id: AggregateID;

static create(create: CreateWalletProps): WalletEntity {
const id = crypto.randomUUID();
const id = randomUUID();
const props: WalletProps = { ...create, balance: 0 };
const wallet = new WalletEntity({ id, props });

Expand Down

0 comments on commit f50b71b

Please sign in to comment.