forked from Sairyss/domain-driven-hexagon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.orm-mapper.ts
39 lines (36 loc) · 1.29 KB
/
user.orm-mapper.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
import { UUID } from '@libs/ddd/domain/value-objects/uuid.value-object';
import {
EntityProps,
OrmEntityProps,
OrmMapper,
} from '@libs/ddd/infrastructure/database/base-classes/orm-mapper.base';
import { UserEntity, UserProps } from '../domain/entities/user.entity';
import { Address } from '../domain/value-objects/address.value-object';
import { Email } from '../domain/value-objects/email.value-object';
import { UserOrmEntity } from './user.orm-entity';
export class UserOrmMapper extends OrmMapper<UserEntity, UserOrmEntity> {
protected toOrmProps(entity: UserEntity): OrmEntityProps<UserOrmEntity> {
const props = entity.getPropsCopy();
const ormProps: OrmEntityProps<UserOrmEntity> = {
email: props.email.value,
country: props.address.country,
postalCode: props.address.postalCode,
street: props.address.street,
role: props.role,
};
return ormProps;
}
protected toDomainProps(ormEntity: UserOrmEntity): EntityProps<UserProps> {
const id = new UUID(ormEntity.id);
const props: UserProps = {
email: new Email(ormEntity.email),
role: ormEntity.role,
address: new Address({
street: ormEntity.street,
postalCode: ormEntity.postalCode,
country: ormEntity.country,
}),
};
return { id, props };
}
}