Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x | import { Injectable } from '@nestjs/common';
import {
Comment,
CommentPrincipal,
CommentRecord,
} from '../../domain/models/comment.model';
import { CommentEntity } from './entities/comment/comment.entity';
@Injectable()
class CommentDataMapper {
fromRecord(domain: CommentRecord): CommentEntity {
const entity = new CommentEntity();
entity.text = domain.text;
entity.likes = domain.likes;
entity.dislikes = domain.dislikes;
return entity;
}
fromPrincipal(domain: CommentPrincipal): CommentEntity {
const entity = this.fromRecord(domain.record);
entity.id = domain.id;
return entity;
}
toRecord(data: CommentEntity): CommentRecord {
return new CommentRecord(data.text, data.likes, data.dislikes);
}
toPrincipal(data: CommentEntity): CommentPrincipal {
return new CommentPrincipal(data.id, this.toRecord(data));
}
toDomain(data: CommentEntity): Comment {
return new Comment(this.toPrincipal(data), null!);
}
}
export { CommentDataMapper };
|