Fix date on sqlite (#7774)

* fix date on sqlite

* remove unused imports

* rename KnexSpatial to KnexDate

Co-authored-by: Jose Varela <joselcvarela@gmail.com>
This commit is contained in:
Nitwel
2021-11-02 15:51:17 +01:00
committed by GitHub
parent d4095bc2aa
commit 6ea29d8673
2 changed files with 58 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import { applyFunctionToColumnName } from './apply-function-to-column-name';
import { getColumn } from './get-column';
import { getRelationType } from './get-relation-type';
import { getGeometryHelper } from '../database/helpers/geometry';
import { getDateHelper } from '../database/helpers/date';
const generateAlias = customAlphabet('abcdefghijklmnopqrstuvwxyz', 5);
@@ -343,6 +344,22 @@ export function applyFilter(
});
}
const dateHelper = getDateHelper();
const [collection, field] = key.split('.');
if (collection in schema.collections && field in schema.collections[collection].fields) {
const type = schema.collections[collection].fields[field].type;
if (['date', 'dateTime', 'time', 'timestamp'].includes(type)) {
if (Array.isArray(compareValue)) {
compareValue = compareValue.map((val) => dateHelper.parseDate(val));
} else {
compareValue = dateHelper.parseDate(compareValue);
}
}
}
// The following fields however, require a value to be run. If no value is passed, we
// ignore them. This allows easier use in GraphQL, where you wouldn't be able to
// conditionally build out your filter structure (#4471)