mr_anastasov

BoardItem

May 22nd, 2023
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export class BoardItem {
  2.  
  3.     _name;
  4.     _status;
  5.  
  6.     _MAX_NAME_LENGTH = 20;
  7.     _MIN_NAME_LENGTH = 6;
  8.    
  9.  
  10.     constructor (name) {
  11.         this._name = name;
  12.     }
  13.  
  14.    /**
  15.    * Sets the name of the note.
  16.    * @param {string} value - The name to set.
  17.    * @throws {Error} If the name is invalid or out of length bounds.
  18.    */
  19.  
  20.     get name() {
  21.         return this._name;
  22.     }
  23.  
  24.     set name(value) {
  25.         if(typeof value !== 'string') {
  26.             throw new Error('Name cannot be diffrent from string!');
  27.         }
  28.  
  29.         if(!value) {
  30.             throw new Error('Name cannot be null, undefined or empty string!');
  31.         }
  32.  
  33.         if (value.length < BoardItem._MIN_NAME_LENGTH || value.length > BoardItem._MAX_NAME_LENGTH) {
  34.             throw new Error(`Length should be between ${BoardItem._MIN_NAME_LENGTH} and ${BoardItem._MAX_NAME_LENGTH}.`);
  35.         }
  36.  
  37.         this._name = value;
  38.     }
  39.  
  40.     get status() {
  41.         return this._status;
  42.     }
  43.  
  44.     reset() {
  45.         this._status = 'new';
  46.     }
  47.  
  48.     advance() {
  49.         this._status = 'one step ahead';
  50.     }
  51.  
  52.     complete() {
  53.         this._status = 'finished';
  54.     }
  55.  
  56.  
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment