Skip to content

Instantly share code, notes, and snippets.

@frknbasaran
Created September 18, 2017 00:26
Show Gist options
  • Save frknbasaran/94fe30c67149c0db6c9b66bb9591ae8a to your computer and use it in GitHub Desktop.
Save frknbasaran/94fe30c67149c0db6c9b66bb9591ae8a to your computer and use it in GitHub Desktop.
plugin/api/api.js
var plugin = {},
common = require('../../../api/utils/common.js'),
countlyCommon = require('../../../api/lib/countly.common.js'),
plugins = require('../../pluginManager.js');
(function (plugin) {
function getPeriodObj(params) {
params.qstring.period = params.qstring.period || "month";
if (params.qstring.period && params.qstring.period.indexOf(",") !== -1) {
try {
params.qstring.period = JSON.parse(params.qstring.period);
} catch (SyntaxError) {
console.log('Parse period JSON failed');
return false;
}
}
countlyCommon.setTimezone(params.appTimezone);
countlyCommon.setPeriod(params.qstring.period);
return countlyCommon.periodObj;
}
//It's work correctly
plugins.register("/o", function (ob) {
var params = ob.params
if (params.qstring.method == 'todlogs') {
/*
Query Build and Prepare Result
*/
var resultJSON = {};
common.returnOutput(params, {
"data": resultJSON
});
return true;
}
});
//But I cant manipulate this request
plugins.register("/i", function (ob) {
var params = ob.params
/*
Make some control and save
log properties into todlog collection
*/
var log = {};
log.hour = params.qstring.hour;
log.dow = params.qstring.dow;
log.app_id = params.qstring.app_id;
log.ts = Math.round(new Date().getTime()/1000);
common.db.collection('todlog').insert(log, function() {});
return true;
});
}(plugin));
module.exports = plugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment