Ghost/ghost/members-analytics-ingress/lib/EventsController.js
Rishabh 317caacc0e Updated ingress event handler to use new analytics ingress package
refs https://github.com/TryGhost/Team/issues/1064

- updates handling of member events to use new analytics ingress package which is responsible to ensure storage of event
2021-09-22 16:51:03 +05:30

37 lines
1.2 KiB
JavaScript

const DomainEvents = require('@tryghost/domain-events');
const {MemberEntryViewEvent} = require('@tryghost/member-events');
/**
* @template Data
* @typedef {object} IEvent
* @prop {Date} timestamp
* @prop {Data} data
*/
class EventsController {
static createEvents(req, res) {
try {
const {events} = req.body;
for (const event of events) {
if (event.type === 'entry_view') {
const entryEvent = new MemberEntryViewEvent({
entryId: event.entry_id,
entryUrl: event.entry_url,
memberId: req.member ? req.member.id : null,
memberStatus: req.member ? req.member.status : null
}, event.created_at);
DomainEvents.dispatch(entryEvent);
}
}
res.writeHead(201);
return res.end('Created.');
} catch (err) {
const statusCode = (err && err.statusCode) || 500;
res.writeHead(statusCode);
return res.end('Internal Server Error.');
}
}
}
module.exports = EventsController;