Ghost/ghost/stats-service/lib/StatsService.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

const MRRService = require('./MrrStatsService');
const MembersService = require('./MembersStatsService');
const SubscriptionStatsService = require('./SubscriptionStatsService');
const ReferrersStatsService = require('./ReferrersStatsService');
class StatsService {
/**
* @param {object} deps
* @param {MRRService} deps.mrr
* @param {MembersService} deps.members
* @param {SubscriptionStatsService} deps.subscriptions
* @param {ReferrersStatsService} deps.referrers
**/
constructor(deps) {
this.mrr = deps.mrr;
this.members = deps.members;
this.subscriptions = deps.subscriptions;
this.referrers = deps.referrers;
}
async getMRRHistory() {
return this.mrr.getHistory();
}
async getMemberCountHistory() {
return this.members.getCountHistory();
}
async getSubscriptionCountHistory() {
return this.subscriptions.getSubscriptionHistory();
}
async getReferrersHistory() {
return this.referrers.getReferrersHistory();
}
/**
* @param {string} postId
*/
async getPostReferrers(postId) {
return {
data: await this.referrers.getForPost(postId),
meta: {}
};
}
/**
* @param {object} deps
* @param {import('knex').Knex} deps.knex
*
* @returns {StatsService}
**/
static create(deps) {
return new StatsService({
mrr: new MRRService(deps),
members: new MembersService(deps),
subscriptions: new SubscriptionStatsService(deps),
referrers: new ReferrersStatsService(deps)
});
}
}
module.exports = StatsService;