add schema gneerator for activity.js

This commit is contained in:
buzz-lightsnack-2007 2025-04-06 17:09:05 +08:00
parent 79146983da
commit 048b42f6cd

View file

@ -9,6 +9,28 @@ class Activity extends Entry {
constructor(PROPERTIES) { constructor(PROPERTIES) {
super(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; module.exports = Activity;