- Transactions work against the account balance - Needs helper functions for users - Needs more testing
99 lines
3.1 KiB
JavaScript
99 lines
3.1 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; |