Use ES6 syntax class
This commit is contained in:
parent
fa4ec8378e
commit
298297f2c5
@ -23,45 +23,47 @@ const lastModified = require('../middlewares/last-modified');
|
|||||||
const formatter = require('../middlewares/formatter');
|
const formatter = require('../middlewares/formatter');
|
||||||
const content = require('../middlewares/content');
|
const content = require('../middlewares/content');
|
||||||
|
|
||||||
function QueryController(metadataBackend, userDatabaseService, statsdClient, userLimitsService) {
|
module.exports = class QueryController {
|
||||||
this.metadataBackend = metadataBackend;
|
constructor (metadataBackend, userDatabaseService, statsdClient, userLimitsService) {
|
||||||
this.stats = statsdClient;
|
this.metadataBackend = metadataBackend;
|
||||||
this.userDatabaseService = userDatabaseService;
|
this.stats = statsdClient;
|
||||||
this.userLimitsService = userLimitsService;
|
this.userDatabaseService = userDatabaseService;
|
||||||
}
|
this.userLimitsService = userLimitsService;
|
||||||
|
}
|
||||||
|
|
||||||
QueryController.prototype.route = function (app) {
|
route (app) {
|
||||||
const { base_url } = global.settings;
|
const { base_url } = global.settings;
|
||||||
const forceToBeMaster = false;
|
const forceToBeMaster = false;
|
||||||
|
|
||||||
const queryMiddlewares = () => {
|
const queryMiddlewares = () => {
|
||||||
return [
|
return [
|
||||||
bodyParserMiddleware(),
|
bodyParserMiddleware(),
|
||||||
initializeProfilerMiddleware('query'),
|
initializeProfilerMiddleware('query'),
|
||||||
userMiddleware(this.metadataBackend),
|
userMiddleware(this.metadataBackend),
|
||||||
rateLimitsMiddleware(this.userLimitsService, RATE_LIMIT_ENDPOINTS_GROUPS.QUERY),
|
rateLimitsMiddleware(this.userLimitsService, RATE_LIMIT_ENDPOINTS_GROUPS.QUERY),
|
||||||
authorizationMiddleware(this.metadataBackend, forceToBeMaster),
|
authorizationMiddleware(this.metadataBackend, forceToBeMaster),
|
||||||
connectionParamsMiddleware(this.userDatabaseService),
|
connectionParamsMiddleware(this.userDatabaseService),
|
||||||
timeoutLimitsMiddleware(this.metadataBackend),
|
timeoutLimitsMiddleware(this.metadataBackend),
|
||||||
parameters({ strategy: 'query' }),
|
parameters({ strategy: 'query' }),
|
||||||
logMiddleware(logMiddleware.TYPES.QUERY),
|
logMiddleware(logMiddleware.TYPES.QUERY),
|
||||||
cancelOnClientAbort(),
|
cancelOnClientAbort(),
|
||||||
affectedTables(),
|
affectedTables(),
|
||||||
accessValidator(),
|
accessValidator(),
|
||||||
queryMayWrite(),
|
queryMayWrite(),
|
||||||
cacheControl(),
|
cacheControl(),
|
||||||
cacheChannel(),
|
cacheChannel(),
|
||||||
surrogateKey(),
|
surrogateKey(),
|
||||||
lastModified(),
|
lastModified(),
|
||||||
formatter(),
|
formatter(),
|
||||||
content(),
|
content(),
|
||||||
handleQuery({ stats: this.stats }),
|
handleQuery({ stats: this.stats }),
|
||||||
errorMiddleware()
|
errorMiddleware()
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
app.all(`${base_url}/sql`, queryMiddlewares());
|
app.all(`${base_url}/sql`, queryMiddlewares());
|
||||||
app.all(`${base_url}/sql.:f`, queryMiddlewares());
|
app.all(`${base_url}/sql.:f`, queryMiddlewares());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleQuery ({ stats } = {}) {
|
function handleQuery ({ stats } = {}) {
|
||||||
@ -110,16 +112,18 @@ function handleQuery ({ stats } = {}) {
|
|||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( req.profiler ) {
|
if (req.profiler) {
|
||||||
req.profiler.sendStats();
|
req.profiler.sendStats();
|
||||||
}
|
}
|
||||||
if (statsdClient) {
|
|
||||||
if ( err ) {
|
if (stats) {
|
||||||
|
if (err) {
|
||||||
stats.increment('sqlapi.query.error');
|
stats.increment('sqlapi.query.error');
|
||||||
} else {
|
} else {
|
||||||
stats.increment('sqlapi.query.success');
|
stats.increment('sqlapi.query.success');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err);
|
||||||
@ -129,6 +133,4 @@ function handleQuery ({ stats } = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = QueryController;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user