Add database objects
This commit is contained in:
		
							parent
							
								
									f966e0564e
								
							
						
					
					
						commit
						3618cbbddb
					
				
					 3 changed files with 79 additions and 0 deletions
				
			
		
							
								
								
									
										14
									
								
								scripts/database/entry/activity.JS
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								scripts/database/entry/activity.JS
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | ||||||
|  | const Entry = require(`./object.JS`); | ||||||
|  | 
 | ||||||
|  | class Activity extends Entry { | ||||||
|  |     username; | ||||||
|  |     description; | ||||||
|  |     duration; | ||||||
|  |     date; | ||||||
|  | 
 | ||||||
|  |     constructor(PROPERTIES) { | ||||||
|  |         super(PROPERTIES); | ||||||
|  |     }; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | module.exports = Activity; | ||||||
							
								
								
									
										10
									
								
								scripts/database/entry/object.JS
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								scripts/database/entry/object.JS
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | ||||||
|  | /* An object to represent an entry in the database. */ | ||||||
|  | class Entry { | ||||||
|  |     constructor(PROPERTIES) { | ||||||
|  |         (PROPERTIES) ? Object.entries(PROPERTIES).forEach(([property, value]) => { | ||||||
|  |             this[property] = value; | ||||||
|  |         }) : false; | ||||||
|  |     }; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | module.exports = Entry; | ||||||
							
								
								
									
										55
									
								
								scripts/database/entry/user.JS
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								scripts/database/entry/user.JS
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,55 @@ | ||||||
|  | const Entry = require(`./object`); | ||||||
|  | const Hash = require(`../../utilities/hash`); | ||||||
|  | 
 | ||||||
|  | class User extends Entry { | ||||||
|  |     // Default properties
 | ||||||
|  |     name; | ||||||
|  |     ID; | ||||||
|  |     activated = false; | ||||||
|  |     passcode; | ||||||
|  |     #login = false; | ||||||
|  | 
 | ||||||
|  |     constructor(PROPERTIES) { | ||||||
|  |         super(PROPERTIES); | ||||||
|  |         this.authenticate(); | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     /* Authenticate the user  | ||||||
|  |      | ||||||
|  |     @param {STRING} INPUT the passcode passed | ||||||
|  |     @return {BOOLEAN} the user authentication state | ||||||
|  |     */ | ||||||
|  |     authenticate(INPUT) { | ||||||
|  |         // Reset the login state. 
 | ||||||
|  |         if (this.#login) {this.#login = false;}; | ||||||
|  | 
 | ||||||
|  |         if ((this.passcode) ? (INPUT && this.passcode == INPUT) : true) { | ||||||
|  |             this.#login = true; | ||||||
|  |         } | ||||||
|  |         return (this.#login); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /*  | ||||||
|  |     Generate a schema for MongoDB.  | ||||||
|  | 
 | ||||||
|  |     @return {OBJECT} the schema | ||||||
|  |     */ | ||||||
|  |     static generateTemplate() { | ||||||
|  |         let SCHEMA = { | ||||||
|  |             "name": {"type": String, "required": true, "unique": true, "dropDups": true}, | ||||||
|  |             "ID": {"type": String, "required": true, "unique": true, "dropDups": true}, | ||||||
|  |             "activated": {"type": Boolean}, | ||||||
|  |             "passcode": {"type": String} | ||||||
|  |         } | ||||||
|  |         let TEST = new User(); | ||||||
|  | 
 | ||||||
|  |         // Verify that the schema is valid.
 | ||||||
|  |         Object.keys(SCHEMA).forEach((KEY) => { | ||||||
|  |             if (!Object.keys(TEST).includes(KEY)) {delete SCHEMA[KEY];}; | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         return (SCHEMA) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | module.exports = User; | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue