From c43930fa7c29949e6729f6bc5ec1d09b53a8d1d7 Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 23 Mar 2023 14:04:53 +0800 Subject: [PATCH] fix: field path --- packages/core/database/src/fields/date-field.ts | 14 ++++++++++++++ packages/core/database/src/filter-parser.ts | 1 + packages/core/database/src/operators/date.ts | 6 ++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/core/database/src/fields/date-field.ts b/packages/core/database/src/fields/date-field.ts index 1a07d04bc..5c4145aca 100644 --- a/packages/core/database/src/fields/date-field.ts +++ b/packages/core/database/src/fields/date-field.ts @@ -5,6 +5,20 @@ export class DateField extends Field { get dataType() { return DataTypes.DATE(3); } + + getProps() { + return this.options?.uiSchema?.['x-component-props'] || {}; + } + + isDateOnly() { + const props = this.getProps(); + return !props.showTime; + } + + isGMT() { + const props = this.getProps(); + return props.gmt || !props.showTime; + } } export interface DateFieldOptions extends BaseColumnFieldOptions { diff --git a/packages/core/database/src/filter-parser.ts b/packages/core/database/src/filter-parser.ts index a1ebfa47c..766b52bc0 100644 --- a/packages/core/database/src/filter-parser.ts +++ b/packages/core/database/src/filter-parser.ts @@ -135,6 +135,7 @@ export default class FilterParser { path: skipPrefix, fullName, fieldName, + fieldPath: `${this.collection.name}.${fullName}`, model: this.model, }); break; diff --git a/packages/core/database/src/operators/date.ts b/packages/core/database/src/operators/date.ts index 2a60eafae..69fbe051d 100644 --- a/packages/core/database/src/operators/date.ts +++ b/packages/core/database/src/operators/date.ts @@ -1,5 +1,5 @@ -import { Op } from 'sequelize'; import moment, { MomentInput } from 'moment'; +import { Op } from 'sequelize'; function stringToDate(value: string): Date { return moment(value).toDate(); } @@ -9,7 +9,9 @@ function getNextDay(value: MomentInput): Date { } export default { - $dateOn(value) { + $dateOn(value, ctx) { + // const field = ctx.db.getFieldByPath(ctx.fieldPath); + // console.log(field.isDateOnly()); return { [Op.and]: [{ [Op.gte]: stringToDate(value) }, { [Op.lt]: getNextDay(value) }], };