mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 04:43:12 +03:00
317caacc0e
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
37 lines
1.2 KiB
JavaScript
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;
|