spee.ch/server/helpers/statsHelpers.js

39 lines
975 B
JavaScript
Raw Normal View History

const logger = require('winston');
2018-03-19 23:46:49 +01:00
const db = require('../models');
2018-01-23 21:08:53 +01:00
module.exports = {
2017-07-13 00:30:31 +02:00
postToStats (action, url, ipAddress, name, claimId, result) {
logger.debug('action:', action);
// make sure the result is a string
if (result && (typeof result !== 'string')) {
result = result.toString();
}
2017-07-20 00:42:56 +02:00
// make sure the ip address(es) are a string
if (ipAddress && (typeof ipAddress !== 'string')) {
ipAddress = ipAddress.toString();
}
2017-07-13 00:30:31 +02:00
db.File
.findOne({where: { name, claimId }})
.then(file => {
// create record in the db
let FileId;
if (file) {
FileId = file.dataValues.id;
} else {
FileId = null;
}
return db.Request
.create({
action,
url,
ipAddress,
result,
FileId,
});
})
.catch(error => {
2017-09-14 00:59:29 +02:00
logger.error('Sequelize error >>', error);
2017-07-13 00:30:31 +02:00
});
},
};