Add database objects

This commit is contained in:
buzz-lightsnack-2007 2025-04-06 14:12:18 +08:00
parent f966e0564e
commit 3618cbbddb
3 changed files with 79 additions and 0 deletions

View 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;

View 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;

View 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;