2023-05-02 23:43:47 +03:00
|
|
|
const MRRService = require('./MrrStatsService');
|
|
|
|
const MembersService = require('./MembersStatsService');
|
|
|
|
const SubscriptionStatsService = require('./SubscriptionStatsService');
|
|
|
|
const ReferrersStatsService = require('./ReferrersStatsService');
|
2022-04-21 15:10:33 +03:00
|
|
|
|
|
|
|
class StatsService {
|
|
|
|
/**
|
|
|
|
* @param {object} deps
|
|
|
|
* @param {MRRService} deps.mrr
|
|
|
|
* @param {MembersService} deps.members
|
2022-04-21 17:42:02 +03:00
|
|
|
* @param {SubscriptionStatsService} deps.subscriptions
|
2022-09-21 19:16:56 +03:00
|
|
|
* @param {ReferrersStatsService} deps.referrers
|
2022-04-21 15:10:33 +03:00
|
|
|
**/
|
|
|
|
constructor(deps) {
|
|
|
|
this.mrr = deps.mrr;
|
|
|
|
this.members = deps.members;
|
2022-04-21 17:42:02 +03:00
|
|
|
this.subscriptions = deps.subscriptions;
|
2022-09-21 19:16:56 +03:00
|
|
|
this.referrers = deps.referrers;
|
2022-04-21 15:10:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async getMRRHistory() {
|
|
|
|
return this.mrr.getHistory();
|
|
|
|
}
|
|
|
|
|
|
|
|
async getMemberCountHistory() {
|
|
|
|
return this.members.getCountHistory();
|
|
|
|
}
|
|
|
|
|
2022-04-21 17:42:02 +03:00
|
|
|
async getSubscriptionCountHistory() {
|
|
|
|
return this.subscriptions.getSubscriptionHistory();
|
|
|
|
}
|
|
|
|
|
2022-09-22 14:04:26 +03:00
|
|
|
async getReferrersHistory() {
|
|
|
|
return this.referrers.getReferrersHistory();
|
|
|
|
}
|
|
|
|
|
2022-09-21 19:16:56 +03:00
|
|
|
/**
|
2022-09-22 14:04:26 +03:00
|
|
|
* @param {string} postId
|
2022-09-21 19:16:56 +03:00
|
|
|
*/
|
|
|
|
async getPostReferrers(postId) {
|
|
|
|
return {
|
|
|
|
data: await this.referrers.getForPost(postId),
|
|
|
|
meta: {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:10:33 +03:00
|
|
|
/**
|
|
|
|
* @param {object} deps
|
|
|
|
* @param {import('knex').Knex} deps.knex
|
|
|
|
*
|
|
|
|
* @returns {StatsService}
|
|
|
|
**/
|
|
|
|
static create(deps) {
|
|
|
|
return new StatsService({
|
|
|
|
mrr: new MRRService(deps),
|
2022-04-21 17:42:02 +03:00
|
|
|
members: new MembersService(deps),
|
2022-09-21 19:16:56 +03:00
|
|
|
subscriptions: new SubscriptionStatsService(deps),
|
|
|
|
referrers: new ReferrersStatsService(deps)
|
2022-04-21 15:10:33 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = StatsService;
|