diff --git a/README.md b/README.md index 0093243..7a12c56 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,8 @@ TODO ## Resources -https://www.sohamkamani.com/javascript/enums/ \ No newline at end of file +### JavaScript enumeration +https://www.sohamkamani.com/javascript/enums/ +https://dmitripavlutin.com/javascript-enum/#comments +https://stackoverflow.com/questions/43000451/javascript-es6-enums-inside-classes-used-outside-like-a-static-enum +https://2ality.com/2020/01/enum-pattern.html diff --git a/index.js b/index.js index 2473111..65500f7 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,16 @@ +// Node modules +const inquirer = require("inquirer"); +const path = require("path"); +const fs = require("fs"); + // Classes +const Employee = require("./lib/Employee"); const Manager = require("./lib/Manager"); const Engineer = require("./lib/Engineer"); const Intern = require("./lib/Intern"); -// Node modules -const inquirer = require("inquirer"); -const path = require("path"); -const fs = require("fs"); +// Enumerations +const EmployeeTypeEnum = require("./lib/EmployeeTypeEnum"); const OUTPUT_DIR = path.resolve(__dirname, "output"); const outputPath = path.join(OUTPUT_DIR, "team.html"); diff --git a/lib/Employee.js b/lib/Employee.js index 16eb635..fd06885 100644 --- a/lib/Employee.js +++ b/lib/Employee.js @@ -1,8 +1,11 @@ +const EmployeeTypeEnum = require("./EmployeeTypeEnum"); + class Employee { constructor(name, id, email) { this.name = name; this.id = id; this.email = email; + this.role = EmployeeTypeEnum.employee; } getName() { @@ -18,7 +21,7 @@ class Employee { } getRole() { - return "Employee"; + return this.role.toString(); } } diff --git a/lib/EmployeeTypeEnum.js b/lib/EmployeeTypeEnum.js new file mode 100644 index 0000000..f4decc1 --- /dev/null +++ b/lib/EmployeeTypeEnum.js @@ -0,0 +1,16 @@ +class EmployeeTypeEnum { + static employee = new EmployeeTypeEnum("Employee"); + static manager = new EmployeeTypeEnum("Manager"); + static engineer = new EmployeeTypeEnum("Engineer"); + static intern = new EmployeeTypeEnum("Intern"); + + constructor(name) { + this.name = name; + } + + toString() { + return `EmployeeTypeEnum.${this.name}`; + } +} + +module.exports = EmployeeTypeEnum; diff --git a/lib/Engineer.js b/lib/Engineer.js index d42480a..cb7fd23 100644 --- a/lib/Engineer.js +++ b/lib/Engineer.js @@ -1,9 +1,11 @@ +const EmployeeTypeEnum = require("./EmployeeTypeEnum"); const Employee = require("./Employee"); class Engineer extends Employee { constructor(name, id, email, github) { super(name, id, email); this.github = github; + this.role = EmployeeTypeEnum.engineer; } getGithub() { @@ -11,7 +13,7 @@ class Engineer extends Employee { } getRole() { - return "Engineer"; + return this.role.toString(); } } diff --git a/lib/Intern.js b/lib/Intern.js index 708dfd8..c51fc89 100644 --- a/lib/Intern.js +++ b/lib/Intern.js @@ -1,9 +1,11 @@ +const EmployeeTypeEnum = require("./EmployeeTypeEnum"); const Employee = require("./Employee"); class Intern extends Employee { constructor(name, id, email, school) { super(name, id, email); this.school = school; + this.role = EmployeeTypeEnum.intern; } getSchool() { @@ -11,7 +13,7 @@ class Intern extends Employee { } getRole() { - return "Intern"; + return this.role.toString(); } } diff --git a/lib/Manager.js b/lib/Manager.js index ae24921..512dc12 100644 --- a/lib/Manager.js +++ b/lib/Manager.js @@ -1,9 +1,11 @@ +const EmployeeTypeEnum = require("./EmployeeTypeEnum"); const Employee = require("./Employee"); class Manager extends Employee { constructor(name, id, email, officeNumber) { super(name, id, email); this.officeNumber = officeNumber; + this.role = EmployeeTypeEnum.manager; } getOfficeNumber() { @@ -11,7 +13,7 @@ class Manager extends Employee { } getRole() { - return "Manager"; + return this.role.toString(); } }