52 lines
No EOL
1.3 KiB
JavaScript
52 lines
No EOL
1.3 KiB
JavaScript
const Entry = require(`./object.JS`);
|
|
|
|
class Activity extends Entry {
|
|
/*
|
|
Default properties:
|
|
username
|
|
description
|
|
duration
|
|
date
|
|
*/
|
|
|
|
constructor(PROPERTIES) {
|
|
super(PROPERTIES);
|
|
|
|
// Set a default date value.
|
|
this.date = this.date ? this.date : new Date(Date.now());
|
|
this.set_date(this.date);
|
|
|
|
// Convert the duration to a number if it isn't.
|
|
(this.duration) ? this.duration = parseInt(this.duration) : null;
|
|
};
|
|
|
|
/*
|
|
Store the date with the corresponding ECMA value. If not, the existing date value is converted.
|
|
|
|
@param {Date} DATE the date
|
|
@return {Number} the date in ECMA
|
|
*/
|
|
set_date(DATE) {
|
|
if (DATE || this.date) {
|
|
this.date = parseInt((new Date(DATE || this.date)).getTime());
|
|
return (this.date);
|
|
}
|
|
}
|
|
|
|
/*
|
|
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}
|
|
};
|
|
return (SCHEMA);
|
|
}
|
|
}
|
|
|
|
module.exports = Activity; |