mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
7437d92d50
closes https://github.com/TryGhost/Team/issues/1942 - Added data fixtures for referrers - Added new endpoint to fetch referrer stats for a given post: `/stats/referrers/posts/:id` - Added new ReferrersStatsService, responsible for calculating referrer stats
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
const MRRService = require('./mrr');
|
|
const MembersService = require('./members');
|
|
const SubscriptionStatsService = require('./subscriptions');
|
|
const ReferrersStatsService = require('./referrers');
|
|
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* @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;
|