-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathuser.domain.ts
More file actions
27 lines (24 loc) · 787 Bytes
/
Copy pathuser.domain.ts
File metadata and controls
27 lines (24 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { randomUUID } from 'node:crypto';
import { createUserEvent } from '#src/modules/user/domain/user.events.ts';
import {
type CreateUserProps,
type UserEntity,
UserRoles,
} from '#src/modules/user/domain/user.types.ts';
import { type DomainResult, withEvents } from '#src/shared/ddd/aggregate.ts';
export default function userDomain() {
return {
createUser: (create: CreateUserProps): DomainResult<UserEntity> => {
const now = new Date();
const user: UserEntity = {
id: randomUUID(),
createdAt: now,
updatedAt: now,
...create,
role: UserRoles.guest,
};
// Record the domain event; the command handler publishes it after persistence.
return withEvents(user, [createUserEvent(user)]);
},
};
}