mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
216d27371a
refs https://github.com/TryGhost/Team/issues/1054 This is the initial pass at the analytics service which listens to events and then handles persisting them via the repository refs https://github.com/TryGhost/Team/issues/1055 This also adds the analytic event repository which handles persisting the events.
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
/**
|
|
* @typedef {object} DBProps
|
|
* @param {string} id
|
|
* @param {string} event_name
|
|
* @param {Date} created_at
|
|
* @param {string} member_id
|
|
* @param {string} member_status
|
|
* @param {string} entry_id
|
|
* @param {string} source_url
|
|
* @param {string} metadata
|
|
*/
|
|
|
|
class AnalyticEventRepository {
|
|
/**
|
|
* @param {any} AnalyticEventModel
|
|
*/
|
|
constructor(AnalyticEventModel) {
|
|
/** @private */
|
|
this.AnalyticEventModel = AnalyticEventModel;
|
|
}
|
|
|
|
/**
|
|
* @param {import('./AnalyticEvent')} event
|
|
*/
|
|
async save(event) {
|
|
const data = {
|
|
id: event.id,
|
|
event_name: event.name,
|
|
created_at: event.timestamp,
|
|
member_id: event.memberId,
|
|
member_status: event.memberStatus,
|
|
entry_id: event.entryId,
|
|
source_url: event.sourceUrl,
|
|
metadata: event.metadata
|
|
};
|
|
|
|
const model = this.AnalyticEventModel.forge(data);
|
|
|
|
if (event.isNew) {
|
|
await model.save(null, {method: 'insert'});
|
|
} else {
|
|
await model.save(null, {method: 'update'});
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = AnalyticEventRepository;
|