Ghost/ghost/stats-service/lib/stats.js
Fabien 'egg' O'Carroll 2575e10ec4 Added subscription stats service (#2)
refs https://github.com/TryGhost/Team/issues/1505
refs https://github.com/TryGhost/Team/issues/1466

This gives us historic data for subscriptions broken down by tier and cadence

* Cleaned up tests
Fixed up usage of knex, making sure to destroy the connection after tests

* Removed Node 12 from testing matrix
Get outta my pub!
2022-04-21 15:42:02 +01:00

46 lines
1.1 KiB
JavaScript

const MRRService = require('./mrr');
const MembersService = require('./members');
const SubscriptionStatsService = require('./subscriptions');
class StatsService {
/**
* @param {object} deps
* @param {MRRService} deps.mrr
* @param {MembersService} deps.members
* @param {SubscriptionStatsService} deps.subscriptions
**/
constructor(deps) {
this.mrr = deps.mrr;
this.members = deps.members;
this.subscriptions = deps.subscriptions;
}
async getMRRHistory() {
return this.mrr.getHistory();
}
async getMemberCountHistory() {
return this.members.getCountHistory();
}
async getSubscriptionCountHistory() {
return this.subscriptions.getSubscriptionHistory();
}
/**
* @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)
});
}
}
module.exports = StatsService;