Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { noteStatus } from '../../common/note-status.enum';
- import { noteImportance } from '../../common/note-importance.enum';
- import { BoardItem } from './board-item.model';
- export class Note extends BoardItem {
- #description;
- #importance;
- /** @private */
- static #MAX_DESCRIPTION_LENGTH = 60;
- /** @private */
- static #MIN_DESCRIPTION_LENGTH = 6;
- constructor (name, description, importance) {
- super(name);
- this.description = description;
- this.importance = importance;
- this._status = this.reset();
- }
- set description(value) {
- if(typeof value !== 'string') {
- throw new Error('Description cannot be diffrent from string!');
- }
- if(!value) {
- throw new Error('Description cannot be null, undefined or empty string!');
- }
- if (value.length < Note.#MIN_DESCRIPTION_LENGTH || value.length > Note.#MAX_DESCRIPTION_LENGTH) {
- throw new Error(`Length should be between ${Note.#MIN_DESCRIPTION_LENGTH} and ${Note.#MAX_DESCRIPTION_LENGTH}.`);
- }
- this.#description = value;
- }
- set importance(value) {
- if (!Object.values(noteImportance).includes(value)) {
- throw new Error('Invalid importance value.');
- }
- this.#importance = value;
- }
- // set _status(value) {
- // if (!Object.values(noteStatus).includes(value)) {
- // throw new Error('Invalid status.');
- // }
- // this.#status = value;
- // }
- reset() {
- this._status = noteStatus.CREATED;
- }
- advance() {
- this._status = noteStatus.PENDING;
- }
- complete() {
- this._status = noteStatus.APPROVED;
- }
- toString() {
- return '* Note * \n' +
- `Name: ${this._name}\n` +
- `Status: ${this._status}\n` +
- `Description: ${this.#description}`;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement