User search and creation
This commit is contained in:
		
							parent
							
								
									5fa9e6efd6
								
							
						
					
					
						commit
						0458e11267
					
				
					 7 changed files with 109 additions and 42 deletions
				
			
		|  | @ -1,10 +1,13 @@ | |||
| const Entry = require(`./object.JS`); | ||||
| 
 | ||||
| class Activity extends Entry { | ||||
|     username; | ||||
|     description; | ||||
|     duration; | ||||
|     date; | ||||
|     /* | ||||
|     Default properties:  | ||||
|         username | ||||
|         description | ||||
|         duration | ||||
|         date | ||||
|     */ | ||||
| 
 | ||||
|     constructor(PROPERTIES) { | ||||
|         super(PROPERTIES); | ||||
|  | @ -21,15 +24,8 @@ class Activity extends Entry { | |||
|             "description": {"type": String}, | ||||
|             "date": {"type": Number}, | ||||
|             "duration": {"type": Number} | ||||
|         } | ||||
|         let TEST = new Activity(); | ||||
| 
 | ||||
|         // Verify that the schema is valid.
 | ||||
|         Object.keys(SCHEMA).forEach((KEY) => { | ||||
|             if (!Object.keys(TEST).includes(KEY)) {delete SCHEMA[KEY];}; | ||||
|         }); | ||||
| 
 | ||||
|         return (SCHEMA) | ||||
|         }; | ||||
|         return (SCHEMA); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| /* An object to represent an entry in the database. */ | ||||
| class Entry { | ||||
|     constructor(PROPERTIES) { | ||||
|         (PROPERTIES) ? Object.entries(PROPERTIES).forEach(([property, value]) => { | ||||
|         (PROPERTIES && (Object.keys(PROPERTIES).length)) ? Object.entries(PROPERTIES).forEach(([property, value]) => { | ||||
|             this[property] = value; | ||||
|         }) : false; | ||||
|     }; | ||||
|  |  | |||
|  | @ -2,11 +2,13 @@ const Entry = require(`./object.JS`); | |||
| const Hash = require(`../../utilities/hash.JS`); | ||||
| 
 | ||||
| class User extends Entry { | ||||
|     // Default properties
 | ||||
|     name; | ||||
|     ID; | ||||
|     activated = false; | ||||
|     passcode; | ||||
|     /* | ||||
|     Default properties: | ||||
|         name | ||||
|         ID | ||||
|         activated = false | ||||
|         passcode | ||||
|     */ | ||||
|     #login = false; | ||||
| 
 | ||||
|     constructor(PROPERTIES) { | ||||
|  | @ -40,15 +42,8 @@ class User extends Entry { | |||
|             "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) | ||||
|         }; | ||||
|         return (SCHEMA); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -43,6 +43,7 @@ class DBManagement { | |||
| 		let RESULT = []; | ||||
| 
 | ||||
| 		if ((CRITERIA && CRITERIA instanceof Object) ? !(Object.keys(CRITERIA).length) : true) { | ||||
| 			console.log(`Searching all...`); | ||||
| 			RESULT = await this.model.find(); | ||||
| 		} else if (CRITERIA instanceof Object) { | ||||
| 			RESULT = await this.model.find(CRITERIA); | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ class UsersManagement extends DBManagement { | |||
| 		@param {object} OPTIONS the account options | ||||
| 		@return {object} the user data | ||||
| 	*/ | ||||
| 	async create(USERNAME, OPTIONS, done) { | ||||
| 	async create(USERNAME, OPTIONS) { | ||||
| 		await this.state; | ||||
| 
 | ||||
| 		/*  | ||||
|  | @ -47,7 +47,7 @@ class UsersManagement extends DBManagement { | |||
| 		} | ||||
| 
 | ||||
| 		if ((USERNAME) ? USERNAME.trim() : false) { | ||||
| 			let CURRENT = !(await checkMatch()) | ||||
| 			let CURRENT = (await checkMatch()) | ||||
| 			CURRENT = (!CURRENT) ? await createUser() : CURRENT; | ||||
| 			 | ||||
| 			return (CURRENT); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue