-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.entity.ts
More file actions
39 lines (33 loc) · 942 Bytes
/
book.entity.ts
File metadata and controls
39 lines (33 loc) · 942 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
28
29
30
31
32
33
34
35
36
37
38
39
import { AggregateRoot } from '@shared/domain/aggregate-root';
import { BookId } from './book-id.vo';
import { ISBN } from './isbn.vo';
import { BookTitle } from './book-title.vo';
import { Author } from './author.vo';
import { BookRegisteredEvent } from './events/book-registered.event';
export class Book extends AggregateRoot {
private constructor(
private readonly _id: BookId,
private readonly _isbn: ISBN,
private readonly _title: BookTitle,
private readonly _author: Author,
) {
super();
}
static register(id: BookId, isbn: ISBN, title: BookTitle, author: Author): Book {
const book = new Book(id, isbn, title, author);
book.raise(new BookRegisteredEvent(id.value));
return book;
}
get id(): BookId {
return this._id;
}
get isbn(): ISBN {
return this._isbn;
}
get title(): BookTitle {
return this._title;
}
get author(): Author {
return this._author;
}
}