-
Notifications
You must be signed in to change notification settings - Fork 4
/
user.orm-mapper.ts
44 lines (41 loc) · 1.65 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
40
41
42
43
44
import {
OrmEntityProps,
OrmMapper,
} from 'src/infrastructure/database/base-classes/orm-mapper.base';
import { Roles } from 'src/interface-adapters/enum/roles.enum';
import { UserEntity, UserProps } from '../domain/entities/user.entity';
import { Email } from '../domain/value-objects/email.value-object';
import { FullName } from '../domain/value-objects/full-name.value-object';
import { Password } from '../domain/value-objects/password.value-object';
import { UniversityID } from '../domain/value-objects/university-id.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,
universityID: props.universityID.value,
firstName: props.fullName.firstName,
lastName: props.fullName.lastName,
password: props.password.value,
reservations: [],
role: props.role,
isEmailVerified: props.isEmailVerified || false,
};
return ormProps;
}
protected toDomainProps(ormEntity: UserOrmEntity): UserProps {
const props: UserProps = {
email: new Email(ormEntity.email),
universityID: new UniversityID(ormEntity.universityID),
fullName: new FullName({
firstName: ormEntity.firstName,
lastName: ormEntity.lastName,
}),
password: new Password(ormEntity.password),
role: Roles[`${ormEntity.role}` as keyof typeof Roles],
isEmailVerified: ormEntity.isEmailVerified,
};
return props;
}
}