Fix filter for decimal

This commit is contained in:
soupette 2018-05-25 13:21:57 +02:00
parent 88d5cc2c37
commit 3847fd8c67
4 changed files with 15 additions and 50 deletions

View File

@ -8,7 +8,7 @@ import React from 'react';
import moment from 'moment'; import moment from 'moment';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { toString, upperFirst } from 'lodash'; import { get, toString, upperFirst } from 'lodash';
import Flex from './Flex'; import Flex from './Flex';
import Remove from './Remove'; import Remove from './Remove';
import Separator from './Separator'; import Separator from './Separator';
@ -17,7 +17,7 @@ import Separator from './Separator';
function Filter({ filter, index, onClick, onClickOpen, schema }) { function Filter({ filter, index, onClick, onClickOpen, schema }) {
let value = filter.value; let value = filter.value;
if (schema[filter.attr].type === 'date') { if (get(schema, [filter.attr, 'type']) === 'date') {
const format = filter.value const format = filter.value
.slice(0, -1) .slice(0, -1)
.split('T')[1] .split('T')[1]

View File

@ -1,44 +1 @@
{ {}
"fuck": {
"attributes": {
"bool": {
"appearance": ""
},
"datra": {
"appearance": ""
},
"data": {
"appearance": ""
}
}
},
"fevzilyaguk": {
"attributes": {
"razeiugeryeizla": {
"appearance": ""
}
}
},
"test": {
"attributes": {
"string": {
"appearance": ""
},
"int": {
"appearance": ""
},
"float": {
"appearance": ""
},
"decimal": {
"appearance": ""
},
"date": {
"appearance": ""
},
"json": {
"appearance": ""
}
}
}
}

View File

@ -20,8 +20,15 @@ module.exports = {
if (params.limit) { if (params.limit) {
qb.limit(params.limit); qb.limit(params.limit);
} }
if (params.sort) {
if (params.sort.key) {
qb.orderBy(params.sort.key, params.sort.order);
} else {
qb.orderBy(params.sort);
}
}
}) })
.orderBy(params.sort.key, params.sort.order)
.fetchAll({ .fetchAll({
withRelated: populate || _.keys(_.groupBy(_.reject(this.associations, { autoPopulate: false }), 'alias')) withRelated: populate || _.keys(_.groupBy(_.reject(this.associations, { autoPopulate: false }), 'alias'))
}); });

View File

@ -445,11 +445,12 @@ module.exports = {
_.forEach(params, (value, key) => { _.forEach(params, (value, key) => {
let result; let result;
const formattedValue = !_.isNaN(_.toNumber(value)) ? _.toNumber(value) : value;
if (_.includes(['_start', '_limit'], key)) { if (_.includes(['_start', '_limit'], key)) {
result = convertor(value, key); result = convertor(formattedValue, key);
} else if (key === '_sort') { } else if (key === '_sort') {
const [attr, order = 'ASC'] = value.split(':'); const [attr, order = 'ASC'] = formattedValue.split(':');
result = convertor(order, key, attr); result = convertor(order, key, attr);
} else { } else {
const suffix = key.split('_'); const suffix = key.split('_');
@ -463,7 +464,7 @@ module.exports = {
type = '='; type = '=';
} }
result = convertor(value, type, key); result = convertor(formattedValue, type, key);
} }
_.set(convertParams, result.key, result.value); _.set(convertParams, result.key, result.value);