165 lines
5.2 KiB
JavaScript
165 lines
5.2 KiB
JavaScript
// 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 {*} _guid The ID of this post
|
|
*/
|
|
constructor(_id, _title, _link, _category, _guid) {
|
|
super(_id, _title, _link, _category);
|
|
this.guid = _guid;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Base transaction
|
|
*/
|
|
class BaseTransaction {
|
|
constructor(_provider_transaction_id, _account_id, _discord_tokens_used, _provider_tokens_used, _provider_id) {
|
|
this.transaction_id = _provider_transaction_id;
|
|
this.account_id = _account_id;
|
|
this.discord_tokens_used = _discord_tokens_used;
|
|
this.provider_tokens_used = _provider_tokens_used;
|
|
this.provider_id = _provider_id;
|
|
}
|
|
}
|
|
|
|
exports.BaseTransaction = BaseTransaction;
|
|
|
|
/**
|
|
* Base transaction
|
|
*/
|
|
class BaseUserAccount {
|
|
constructor(_discord_account_id, _account_id) {
|
|
this.discord_account_id = _discord_account_id;
|
|
this.account_id = _account_id;
|
|
}
|
|
}
|
|
|
|
exports.BaseUserAccount = BaseUserAccount;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
class nodeObject {
|
|
/**
|
|
*
|
|
* @param {*} param0._id The ID of the node
|
|
* @param {*} param0._name The name of the node
|
|
* @param {*} param0._ip The IP that the master can contact the node at
|
|
* @param {*} param0._port The port that the client is listening on
|
|
* @param {*} param0._location The physical location of the node
|
|
* @param {*} param0._online True/False if the node is online or offline
|
|
* @param {*} param0._nearbySystems An object array of nearby systems
|
|
*/
|
|
constructor({ _id = undefined, _name = undefined, _ip = undefined, _port = undefined, _location = undefined, _nearbySystems = undefined, _online = undefined }) {
|
|
this.id = _id;
|
|
this.name = _name;
|
|
this.ip = _ip;
|
|
this.port = _port;
|
|
this.location = _location;
|
|
this.nearbySystems = _nearbySystems;
|
|
if (this.nearbySystems) this.presets = Object.keys(_nearbySystems);
|
|
this.online = _online;
|
|
}
|
|
}
|
|
|
|
exports.nodeObject = nodeObject;
|
|
|
|
/**
|
|
* This object represents a discord bot's client information
|
|
*/
|
|
class clientObject {
|
|
/**
|
|
*
|
|
* @param {*} param0._discord_id The discord id from the node, as seen when right clicking -> copy ID
|
|
* @param {*} param0._name The name of the bot associated with the IDs
|
|
* @param {*} param0._client_id The client ID of the bot needed to connect to Discord
|
|
*/
|
|
constructor({_discord_id = undefined, _name = undefined, _client_id = undefined,}) {
|
|
this.discordId = _discord_id;
|
|
this.name = _name;
|
|
this.clientId = _client_id;
|
|
}
|
|
}
|
|
|
|
exports.clientObject = clientObject;
|
|
|
|
/**
|
|
* This object represents a discord node connection
|
|
*/
|
|
class connectionObject {
|
|
/**
|
|
*
|
|
* @param {*} param0._connection_id The connection ID associated with the connection in the database
|
|
* @param {*} param0._node The node associated with the connection
|
|
* @param {*} param0._client_object The client object associated with the connection
|
|
*/
|
|
constructor({_connection_id = undefined, _node = undefined, _client_object}) {
|
|
this.connectionId = _connection_id;
|
|
this.node = _node;
|
|
this.clientObject = _client_object;
|
|
}
|
|
}
|
|
|
|
exports.connectionObject = connectionObject; |