Updated storage for feeds and posts
This commit is contained in:
72
utilities/recordHelper.js
Normal file
72
utilities/recordHelper.js
Normal file
@@ -0,0 +1,72 @@
|
||||
// This is for record builders
|
||||
|
||||
const { DebugBuilder } = require("./debugBuilder");
|
||||
const log = new DebugBuilder("server", "recordHelper");
|
||||
|
||||
class baseRSSRecord {
|
||||
/**
|
||||
*
|
||||
* @param {*} _id The ID of the post from the DB
|
||||
* @param {*} _title The title of the post
|
||||
* @param {*} _link The link to the post
|
||||
* @param {*} _category The category of the post
|
||||
*/
|
||||
constructor(_id, _title, _link, _category) {
|
||||
this.id = _id;
|
||||
this.title = _title;
|
||||
this.link= _link;
|
||||
this.category = _category;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
get(key) {
|
||||
log.DEBUG(`Getting key '${key}' from: `, Object(this));
|
||||
if (!Object.keys(this).includes(key)) throw new Error(`Key is invalid ${key}`);
|
||||
return this[key]
|
||||
}
|
||||
}
|
||||
|
||||
exports.baseRSSRecord = baseRSSRecord;
|
||||
|
||||
/**
|
||||
* Build a Source record.
|
||||
*
|
||||
* A source record is the record of an RSS feed itself. Something like "https://www.leafly.com/feed".
|
||||
*/
|
||||
exports.RSSSourceRecord = class RSSSourceRecord extends baseRSSRecord{
|
||||
/**
|
||||
* @param {*} _id The ID of the post from the DB
|
||||
* @param {*} _title The title of the post
|
||||
* @param {*} _link The link to the post
|
||||
* @param {*} _category The category of the post
|
||||
* @param {*} _guild_id The guild id to receive updates on this source
|
||||
* @param {*} _channel_id The channel to send updates from this source
|
||||
*/
|
||||
constructor(_id, _title, _link, _category, _guild_id, _channel_id) {
|
||||
super(_id, _title, _link, _category);
|
||||
this.guild_id = _guild_id;
|
||||
this.channel_id = _channel_id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a Post record.
|
||||
*
|
||||
* A post is an individual article/post/link from an RSS feed. Each individual post will be added to the database to be recalled and sent later.
|
||||
*/
|
||||
exports.RSSPostRecord = class RSSPostRecord extends baseRSSRecord{
|
||||
/**
|
||||
* @param {*} _id The ID of the post from the DB
|
||||
* @param {*} _title The title of the post
|
||||
* @param {*} _link The link to the post
|
||||
* @param {*} _category The category of the post
|
||||
* @param {*} _rssSourceID The ID of the RSS source that created this post
|
||||
*/
|
||||
constructor(_id, _title, _link, _category, _rssSourceID) {
|
||||
super(_id, _title, _link, _category);
|
||||
this.source_id = _rssSourceID;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user