forked from Sairyss/domain-driven-hexagon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.orm-mapper.ts
34 lines (31 loc) · 1.09 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
import {
OrmEntityProps,
OrmMapper,
} from 'src/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,
};
return ormProps;
}
protected toDomainProps(ormEntity: UserOrmEntity): UserProps {
const props: UserProps = {
email: new Email(ormEntity.email),
address: new Address({
street: ormEntity.street,
postalCode: ormEntity.postalCode,
country: ormEntity.country,
}),
};
return props;
}
}