const DBManagement = require(`./management.JS`); const Activity = require(`../entry/activity.JS`); const Log = require(`../entry/log.JS`); class ActivityManagement extends DBManagement { constructor() { super(`localhost:27017`, `Activity-Tracker`); this.configure(`Activities`, Activity.generateTemplate()); }; /* Create a user. The ID will be automatically generated. @param {string} DETAILS the activity's details @param {object} OPTIONS the account options @return {object} the user data */ async create(DETAILS, OPTIONS, done) { await this.state; /* Create an activity. */ const createActivity = async () => { let CREATED = new Activity(DETAILS); let ENTRY = new this.model(CREATED); try { let RESULT = await ENTRY.save(); } catch(ERROR) { throw new CustomErrors.DBProblem(ERROR.message); } return (CREATED); } let CURRENT = await createActivity(); return (CURRENT); }; /* Search for all activities for a given user. @param {String} USERNAME the username @param {Object} CRITERIA the search criteria @param {Number} SIZE the size @return {Object} the log */ async search_User (USERNAME, CRITERIA, SIZE) { let RESULT = await this.search(Object.assign({}, CRITERIA, {"username": USERNAME}), SIZE); const convertData = () => { let LOG = new Log({"name": USERNAME, "activities": (RESULT instanceof Array ? RESULT.length : false) ? RESULT : []}); return (LOG); } return(convertData()); } } module.exports = ActivityManagement;