a
This commit is contained in:
parent
8ad1465c7d
commit
d66d41c02e
@ -39,7 +39,9 @@ const generateControllers = (service, extraControllers = {}, options = {}) => {
|
||||
|
||||
const params = extractParamsFromRequest(req, res, _options.params.find);
|
||||
try {
|
||||
console.log('parammmmmmmasr', params);
|
||||
const result = await service.fetchAll(params, buildContext(req, config));
|
||||
console.log('controllllerrrrrrrrrrrrrrrr', result);
|
||||
return handleResultResponse(result.rows, result.count, params, res);
|
||||
} catch (error) {
|
||||
return handleErrorResponse(_options.MODULE_NAME, 'find', error, res)
|
||||
|
||||
@ -54,7 +54,7 @@ function getTotalCount(result) {
|
||||
const toType = function (obj) {
|
||||
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
|
||||
}
|
||||
|
||||
|
||||
switch (toType(result)) {
|
||||
case 'boolean':
|
||||
return 1;
|
||||
@ -131,6 +131,7 @@ function handleErrorResponse(controllerName, methodName, error, res) {
|
||||
}
|
||||
|
||||
function handleResultResponse(result, totalCount = null, params, res, statusCode = httpStatus.OK) {
|
||||
console.log('handleResultResponse(result>>>>>>>>>>>>>>', result, getTotalCount(result));
|
||||
setPaginationInfo((totalCount) ? totalCount : getTotalCount(result), res);
|
||||
res.status(statusCode).send(typeof result == 'number' ? result.toString() : result);
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ routes.get('/events',
|
||||
(req, res, next) => {
|
||||
if (!req.body.city)
|
||||
return eventController.find({
|
||||
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeDetails'],
|
||||
// scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeDetails'],
|
||||
})(req, res, next)
|
||||
else
|
||||
return eventController.find({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user