Use ES6 syntax class

This commit is contained in:
Daniel García Aubert 2019-07-26 19:51:06 +02:00
parent fa4ec8378e
commit 298297f2c5

View File

@ -23,14 +23,15 @@ const lastModified = require('../middlewares/last-modified');
const formatter = require('../middlewares/formatter');
const content = require('../middlewares/content');
function QueryController(metadataBackend, userDatabaseService, statsdClient, userLimitsService) {
module.exports = class QueryController {
constructor (metadataBackend, userDatabaseService, statsdClient, userLimitsService) {
this.metadataBackend = metadataBackend;
this.stats = statsdClient;
this.userDatabaseService = userDatabaseService;
this.userLimitsService = userLimitsService;
}
QueryController.prototype.route = function (app) {
route (app) {
const { base_url } = global.settings;
const forceToBeMaster = false;
@ -62,6 +63,7 @@ QueryController.prototype.route = function (app) {
app.all(`${base_url}/sql`, queryMiddlewares());
app.all(`${base_url}/sql.:f`, queryMiddlewares());
}
};
function handleQuery ({ stats } = {}) {
@ -113,13 +115,15 @@ function handleQuery ({ stats } = {}) {
if (req.profiler) {
req.profiler.sendStats();
}
if (statsdClient) {
if (stats) {
if (err) {
stats.increment('sqlapi.query.error');
} else {
stats.increment('sqlapi.query.success');
}
}
});
} catch (err) {
next(err);
@ -129,6 +133,4 @@ function handleQuery ({ stats } = {}) {
}
}
};
};
module.exports = QueryController;
}