Ghost/ghost/stats-service/lib/stats.js
Simon Backx 7437d92d50
Added post referrers stats API (#15448)
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
2022-09-21 18:16:56 +02:00

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;