2017-06-28 00:53:53 +02:00
|
|
|
const db = require('../../models');
|
2017-06-28 01:25:35 +02:00
|
|
|
const logger = require('winston');
|
2017-06-28 00:53:53 +02:00
|
|
|
|
|
|
|
module.exports = {
|
2017-06-28 07:41:48 +02:00
|
|
|
postToAnalytics: (action, url, ipAddress, result) => {
|
|
|
|
logger.silly('creating record for analytics');
|
2017-06-29 19:51:23 +02:00
|
|
|
// make sure the result is a string
|
2017-06-28 07:41:48 +02:00
|
|
|
if (result && (typeof result !== 'string')) {
|
|
|
|
result = result.toString();
|
|
|
|
}
|
2017-06-29 19:51:23 +02:00
|
|
|
// // make sure the ip address(es) are a string
|
|
|
|
if (ipAddress && (typeof ipAddress !== 'string')) {
|
|
|
|
ipAddress = ipAddress.toString();
|
|
|
|
}
|
|
|
|
// create record in the db
|
2017-06-28 07:41:48 +02:00
|
|
|
db.Analytics.create({
|
|
|
|
action,
|
|
|
|
url,
|
|
|
|
ipAddress,
|
|
|
|
result,
|
|
|
|
})
|
|
|
|
.then()
|
|
|
|
.catch(error => {
|
|
|
|
logger.error('sequelize error', error);
|
|
|
|
});
|
2017-06-28 00:53:53 +02:00
|
|
|
},
|
|
|
|
};
|