Advertisement
mr_anastasov

Note

May 22nd, 2023
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { noteStatus } from '../../common/note-status.enum';
  2. import { noteImportance } from '../../common/note-importance.enum';
  3. import { BoardItem } from './board-item.model';
  4. export class Note extends BoardItem {
  5.  
  6.     #description;
  7.     #importance;
  8.  
  9.      /** @private */
  10.      static #MAX_DESCRIPTION_LENGTH = 60;
  11.      /** @private */
  12.      static #MIN_DESCRIPTION_LENGTH = 6;
  13.  
  14.     constructor (name, description, importance) {
  15.         super(name);
  16.  
  17.         this.description = description;
  18.         this.importance = importance;
  19.         this._status = this.reset();
  20.     }
  21.  
  22.  
  23.     set description(value) {
  24.         if(typeof value !== 'string') {
  25.             throw new Error('Description cannot be diffrent from string!');
  26.         }
  27.  
  28.         if(!value) {
  29.             throw new Error('Description cannot be null, undefined or empty string!');
  30.         }
  31.  
  32.         if (value.length < Note.#MIN_DESCRIPTION_LENGTH || value.length > Note.#MAX_DESCRIPTION_LENGTH) {
  33.             throw new Error(`Length should be between ${Note.#MIN_DESCRIPTION_LENGTH} and ${Note.#MAX_DESCRIPTION_LENGTH}.`);
  34.         }
  35.  
  36.         this.#description = value;
  37.     }
  38.  
  39.     set importance(value) {
  40.         if (!Object.values(noteImportance).includes(value)) {
  41.             throw new Error('Invalid importance value.');
  42.         }
  43.  
  44.         this.#importance = value;
  45.     }
  46.  
  47.     // set _status(value) {
  48.     //     if (!Object.values(noteStatus).includes(value)) {
  49.     //         throw new Error('Invalid status.');
  50.     //     }
  51.        
  52.     //     this.#status = value;
  53.     // }
  54.  
  55.     reset() {
  56.         this._status = noteStatus.CREATED;
  57.     }
  58.  
  59.     advance() {
  60.         this._status = noteStatus.PENDING;
  61.     }
  62.  
  63.     complete() {
  64.         this._status = noteStatus.APPROVED;
  65.     }
  66.  
  67.     toString() {
  68.  
  69.         return '* Note * \n' +
  70.         `Name: ${this._name}\n` +
  71.         `Status: ${this._status}\n` +
  72.         `Description: ${this.#description}`;
  73.     }
  74.  
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement