24 lines
783 B
JavaScript
24 lines
783 B
JavaScript
class Songs {
|
|
constructor(info) {
|
|
if (!info || !info.userid) throw "Can not construct empty profile";
|
|
this.userid = info.userid;
|
|
this.data = info.data || {};
|
|
|
|
const allowedParams = ["title", 'author', "content", "contentHistory", "bpm", "lang", "reactions", "root", 'beatsPerTempo'];
|
|
for (const key in info) {
|
|
if (info.hasOwnProperty(key) && allowedParams.includes(key)) {
|
|
this[key] = info[key];
|
|
}
|
|
}
|
|
this.createdAt = info.createdAt || new Date();
|
|
this.lastUpdated = info.lastUpdated || this.createdAt;
|
|
this.comments = info.comments || [];
|
|
this.reactions = info.reactions || {};
|
|
}
|
|
|
|
toObj() {
|
|
return { ...this };
|
|
}
|
|
}
|
|
|
|
module.exports = Songs; |