From 048b42f6cdc3de8d7ad33da6b70927620672632d Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sun, 6 Apr 2025 17:09:05 +0800 Subject: [PATCH] add schema gneerator for activity.js --- scripts/database/entry/activity.JS | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/database/entry/activity.JS b/scripts/database/entry/activity.JS index 477a6dd..dd48a02 100644 --- a/scripts/database/entry/activity.JS +++ b/scripts/database/entry/activity.JS @@ -9,6 +9,28 @@ class Activity extends Entry { constructor(PROPERTIES) { super(PROPERTIES); }; + + /* + Generate a schema for MongoDB. + + @return {OBJECT} the schema + */ + static generateTemplate() { + let SCHEMA = { + "username": {"type": String, "required": true}, + "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) + } } module.exports = Activity; \ No newline at end of file