diff --git a/.changeset/long-bottles-brush.md b/.changeset/long-bottles-brush.md new file mode 100644 index 0000000000..c369b4d2dc --- /dev/null +++ b/.changeset/long-bottles-brush.md @@ -0,0 +1,18 @@ +--- +"@comet/cms-api": major +--- + +Rename `DateFilter` to `DateTimeFilter` + +This leaves room for a future DateFilter that only filters by date, not time. + +**Upgrading** + +1. Change import + +```diff +- import { DateFilter } from "@comet/cms-api"; ++ import { DateTimeFilter } from "@comet/cms-api"; +``` + +2. Re-run API Generator. diff --git a/demo/api/schema.gql b/demo/api/schema.gql index a6a05d3388..36fabde883 100644 --- a/demo/api/schema.gql +++ b/demo/api/schema.gql @@ -826,8 +826,8 @@ input RedirectFilter { generationType: StringFilter source: StringFilter active: BooleanFilter - createdAt: DateFilter - updatedAt: DateFilter + createdAt: DateTimeFilter + updatedAt: DateTimeFilter and: [RedirectFilter!] or: [RedirectFilter!] } @@ -836,7 +836,7 @@ input BooleanFilter { equal: Boolean } -input DateFilter { +input DateTimeFilter { equal: DateTime lowerThan: DateTime greaterThan: DateTime @@ -892,11 +892,11 @@ input NewsFilter { slug: StringFilter title: StringFilter status: NewsStatusEnumFilter - date: DateFilter + date: DateTimeFilter category: NewsCategoryEnumFilter comments: OneToManyFilter - createdAt: DateFilter - updatedAt: DateFilter + createdAt: DateTimeFilter + updatedAt: DateTimeFilter and: [NewsFilter!] or: [NewsFilter!] } @@ -942,14 +942,14 @@ input ProductFilter { price: NumberFilter inStock: BooleanFilter soldCount: NumberFilter - availableSince: DateFilter + availableSince: DateTimeFilter colors: OneToManyFilter variants: OneToManyFilter category: ManyToOneFilter tags: ManyToManyFilter tagsWithStatus: OneToManyFilter - createdAt: DateFilter - updatedAt: DateFilter + createdAt: DateTimeFilter + updatedAt: DateTimeFilter manufacturer: ManyToOneFilter and: [ProductFilter!] or: [ProductFilter!] @@ -1016,8 +1016,8 @@ input ProductCategoryFilter { title: StringFilter slug: StringFilter products: OneToManyFilter - createdAt: DateFilter - updatedAt: DateFilter + createdAt: DateTimeFilter + updatedAt: DateTimeFilter and: [ProductCategoryFilter!] or: [ProductCategoryFilter!] } @@ -1038,8 +1038,8 @@ input ProductTagFilter { title: StringFilter products: ManyToManyFilter productsWithStatus: OneToManyFilter - createdAt: DateFilter - updatedAt: DateFilter + createdAt: DateTimeFilter + updatedAt: DateTimeFilter and: [ProductTagFilter!] or: [ProductTagFilter!] } @@ -1057,8 +1057,8 @@ enum ProductTagSortField { input ProductVariantFilter { name: StringFilter - createdAt: DateFilter - updatedAt: DateFilter + createdAt: DateTimeFilter + updatedAt: DateTimeFilter and: [ProductVariantFilter!] or: [ProductVariantFilter!] } @@ -1085,7 +1085,7 @@ input ManufacturerFilter { addressAsEmbeddable_alternativeAddress_streetNumber: NumberFilter addressAsEmbeddable_alternativeAddress_zip: NumberFilter addressAsEmbeddable_alternativeAddress_country: StringFilter - updatedAt: DateFilter + updatedAt: DateTimeFilter and: [ManufacturerFilter!] or: [ManufacturerFilter!] } diff --git a/demo/api/src/news/generated/dto/news.filter.ts b/demo/api/src/news/generated/dto/news.filter.ts index 612afdf4fe..039ffd6120 100644 --- a/demo/api/src/news/generated/dto/news.filter.ts +++ b/demo/api/src/news/generated/dto/news.filter.ts @@ -1,6 +1,6 @@ // This file has been generated by comet api-generator. // You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment. -import { createEnumFilter, DateFilter, OneToManyFilter, StringFilter } from "@comet/cms-api"; +import { createEnumFilter, DateTimeFilter, OneToManyFilter, StringFilter } from "@comet/cms-api"; import { Field, InputType } from "@nestjs/graphql"; import { Type } from "class-transformer"; import { IsOptional, ValidateNested } from "class-validator"; @@ -32,11 +32,11 @@ export class NewsFilter { @Type(() => NewsStatusEnumFilter) status?: NewsStatusEnumFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - date?: DateFilter; + @Type(() => DateTimeFilter) + date?: DateTimeFilter; @Field(() => NewsCategoryEnumFilter, { nullable: true }) @ValidateNested() @@ -50,17 +50,17 @@ export class NewsFilter { @Type(() => OneToManyFilter) comments?: OneToManyFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - createdAt?: DateFilter; + @Type(() => DateTimeFilter) + createdAt?: DateTimeFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - updatedAt?: DateFilter; + @Type(() => DateTimeFilter) + updatedAt?: DateTimeFilter; @Field(() => [NewsFilter], { nullable: true }) @Type(() => NewsFilter) diff --git a/demo/api/src/products/generated/dto/manufacturer.filter.ts b/demo/api/src/products/generated/dto/manufacturer.filter.ts index e89341ecdb..b7f8fb732b 100644 --- a/demo/api/src/products/generated/dto/manufacturer.filter.ts +++ b/demo/api/src/products/generated/dto/manufacturer.filter.ts @@ -1,6 +1,6 @@ // This file has been generated by comet api-generator. // You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment. -import { DateFilter, NumberFilter, StringFilter } from "@comet/cms-api"; +import { DateTimeFilter, NumberFilter, StringFilter } from "@comet/cms-api"; import { Field, InputType } from "@nestjs/graphql"; import { Type } from "class-transformer"; import { IsOptional, ValidateNested } from "class-validator"; @@ -61,11 +61,11 @@ export class ManufacturerFilter { @Type(() => StringFilter) addressAsEmbeddable_alternativeAddress_country?: StringFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - updatedAt?: DateFilter; + @Type(() => DateTimeFilter) + updatedAt?: DateTimeFilter; @Field(() => [ManufacturerFilter], { nullable: true }) @Type(() => ManufacturerFilter) diff --git a/demo/api/src/products/generated/dto/product-category.filter.ts b/demo/api/src/products/generated/dto/product-category.filter.ts index 963eadce26..e3ffef25a5 100644 --- a/demo/api/src/products/generated/dto/product-category.filter.ts +++ b/demo/api/src/products/generated/dto/product-category.filter.ts @@ -1,6 +1,6 @@ // This file has been generated by comet api-generator. // You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment. -import { DateFilter, OneToManyFilter, StringFilter } from "@comet/cms-api"; +import { DateTimeFilter, OneToManyFilter, StringFilter } from "@comet/cms-api"; import { Field, InputType } from "@nestjs/graphql"; import { Type } from "class-transformer"; import { IsOptional, ValidateNested } from "class-validator"; @@ -25,17 +25,17 @@ export class ProductCategoryFilter { @Type(() => OneToManyFilter) products?: OneToManyFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - createdAt?: DateFilter; + @Type(() => DateTimeFilter) + createdAt?: DateTimeFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - updatedAt?: DateFilter; + @Type(() => DateTimeFilter) + updatedAt?: DateTimeFilter; @Field(() => [ProductCategoryFilter], { nullable: true }) @Type(() => ProductCategoryFilter) diff --git a/demo/api/src/products/generated/dto/product-tag.filter.ts b/demo/api/src/products/generated/dto/product-tag.filter.ts index 88b67696eb..3b345ace3a 100644 --- a/demo/api/src/products/generated/dto/product-tag.filter.ts +++ b/demo/api/src/products/generated/dto/product-tag.filter.ts @@ -1,6 +1,6 @@ // This file has been generated by comet api-generator. // You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment. -import { DateFilter, ManyToManyFilter, OneToManyFilter, StringFilter } from "@comet/cms-api"; +import { DateTimeFilter, ManyToManyFilter, OneToManyFilter, StringFilter } from "@comet/cms-api"; import { Field, InputType } from "@nestjs/graphql"; import { Type } from "class-transformer"; import { IsOptional, ValidateNested } from "class-validator"; @@ -25,17 +25,17 @@ export class ProductTagFilter { @Type(() => OneToManyFilter) productsWithStatus?: OneToManyFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - createdAt?: DateFilter; + @Type(() => DateTimeFilter) + createdAt?: DateTimeFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - updatedAt?: DateFilter; + @Type(() => DateTimeFilter) + updatedAt?: DateTimeFilter; @Field(() => [ProductTagFilter], { nullable: true }) @Type(() => ProductTagFilter) diff --git a/demo/api/src/products/generated/dto/product-variant.filter.ts b/demo/api/src/products/generated/dto/product-variant.filter.ts index 58a50e98d5..4cf97a98e2 100644 --- a/demo/api/src/products/generated/dto/product-variant.filter.ts +++ b/demo/api/src/products/generated/dto/product-variant.filter.ts @@ -1,6 +1,6 @@ // This file has been generated by comet api-generator. // You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment. -import { DateFilter, StringFilter } from "@comet/cms-api"; +import { DateTimeFilter, StringFilter } from "@comet/cms-api"; import { Field, InputType } from "@nestjs/graphql"; import { Type } from "class-transformer"; import { IsOptional, ValidateNested } from "class-validator"; @@ -13,17 +13,17 @@ export class ProductVariantFilter { @Type(() => StringFilter) name?: StringFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - createdAt?: DateFilter; + @Type(() => DateTimeFilter) + createdAt?: DateTimeFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - updatedAt?: DateFilter; + @Type(() => DateTimeFilter) + updatedAt?: DateTimeFilter; @Field(() => [ProductVariantFilter], { nullable: true }) @Type(() => ProductVariantFilter) diff --git a/demo/api/src/products/generated/dto/product.filter.ts b/demo/api/src/products/generated/dto/product.filter.ts index 14a99c7150..f58339b809 100644 --- a/demo/api/src/products/generated/dto/product.filter.ts +++ b/demo/api/src/products/generated/dto/product.filter.ts @@ -4,7 +4,7 @@ import { BooleanFilter, createEnumFilter, createEnumsFilter, - DateFilter, + DateTimeFilter, ManyToManyFilter, ManyToOneFilter, NumberFilter, @@ -81,11 +81,11 @@ export class ProductFilter { @Type(() => NumberFilter) soldCount?: NumberFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - availableSince?: DateFilter; + @Type(() => DateTimeFilter) + availableSince?: DateTimeFilter; @Field(() => OneToManyFilter, { nullable: true }) @ValidateNested() @@ -117,17 +117,17 @@ export class ProductFilter { @Type(() => OneToManyFilter) tagsWithStatus?: OneToManyFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - createdAt?: DateFilter; + @Type(() => DateTimeFilter) + createdAt?: DateTimeFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - updatedAt?: DateFilter; + @Type(() => DateTimeFilter) + updatedAt?: DateTimeFilter; @Field(() => ManyToOneFilter, { nullable: true }) @ValidateNested() diff --git a/packages/api/cms-api/schema.gql b/packages/api/cms-api/schema.gql index cc7199cefc..2843d39a96 100644 --- a/packages/api/cms-api/schema.gql +++ b/packages/api/cms-api/schema.gql @@ -380,8 +380,8 @@ input RedirectFilter { generationType: StringFilter source: StringFilter active: BooleanFilter - createdAt: DateFilter - updatedAt: DateFilter + createdAt: DateTimeFilter + updatedAt: DateTimeFilter and: [RedirectFilter!] or: [RedirectFilter!] } @@ -398,7 +398,7 @@ input BooleanFilter { equal: Boolean } -input DateFilter { +input DateTimeFilter { equal: DateTime lowerThan: DateTime greaterThan: DateTime diff --git a/packages/api/cms-api/src/common/filter/date.filter.ts b/packages/api/cms-api/src/common/filter/date-time.filter.ts similarity index 95% rename from packages/api/cms-api/src/common/filter/date.filter.ts rename to packages/api/cms-api/src/common/filter/date-time.filter.ts index c3a241fa9d..90c9c5aafc 100644 --- a/packages/api/cms-api/src/common/filter/date.filter.ts +++ b/packages/api/cms-api/src/common/filter/date-time.filter.ts @@ -2,7 +2,7 @@ import { Field, InputType } from "@nestjs/graphql"; import { IsDate, IsOptional } from "class-validator"; @InputType() -export class DateFilter { +export class DateTimeFilter { @Field({ nullable: true }) @IsOptional() @IsDate() diff --git a/packages/api/cms-api/src/common/filter/mikro-orm.spec.ts b/packages/api/cms-api/src/common/filter/mikro-orm.spec.ts index f36e517583..83bbdb3f31 100644 --- a/packages/api/cms-api/src/common/filter/mikro-orm.spec.ts +++ b/packages/api/cms-api/src/common/filter/mikro-orm.spec.ts @@ -1,5 +1,5 @@ import { BooleanFilter } from "./boolean.filter"; -import { DateFilter } from "./date.filter"; +import { DateTimeFilter } from "./date-time.filter"; import { filtersToMikroOrmQuery, filterToMikroOrmQuery, searchToMikroOrmQuery, splitSearchString } from "./mikro-orm"; import { NumberFilter } from "./number.filter"; import { StringFilter } from "./string.filter"; @@ -291,7 +291,7 @@ describe("filtersToMikroOrmQuery", () => { } else if ( filterValue instanceof StringFilter || filterValue instanceof NumberFilter || - filterValue instanceof DateFilter || + filterValue instanceof DateTimeFilter || filterValue instanceof BooleanFilter ) { acc[filterKey] = filterToMikroOrmQuery(filterValue, filterKey); diff --git a/packages/api/cms-api/src/common/filter/mikro-orm.ts b/packages/api/cms-api/src/common/filter/mikro-orm.ts index 7ba96e5b03..1f8745284f 100644 --- a/packages/api/cms-api/src/common/filter/mikro-orm.ts +++ b/packages/api/cms-api/src/common/filter/mikro-orm.ts @@ -1,7 +1,7 @@ import { FilterQuery, ObjectQuery } from "@mikro-orm/core"; import { BooleanFilter } from "./boolean.filter"; -import { DateFilter } from "./date.filter"; +import { DateTimeFilter } from "./date-time.filter"; import { EnumFilterInterface, isEnumFilter } from "./enum.filter.factory"; import { EnumsFilterInterface, isEnumsFilter } from "./enums.filter.factory"; import { ManyToManyFilter } from "./many-to-many.filter"; @@ -14,7 +14,7 @@ function quoteLike(string: string): string { return string.replace(/([%_\\])/g, "\\$1"); } export function filterToMikroOrmQuery( - filterProperty: StringFilter | NumberFilter | DateFilter | BooleanFilter | EnumFilterInterface | EnumsFilterInterface, + filterProperty: StringFilter | NumberFilter | DateTimeFilter | BooleanFilter | EnumFilterInterface | EnumsFilterInterface, propertyName: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any ): FilterQuery { @@ -65,7 +65,7 @@ export function filterToMikroOrmQuery( if (filterProperty.notEqual !== undefined) { ret.$ne = filterProperty.notEqual; } - } else if (filterProperty instanceof DateFilter) { + } else if (filterProperty instanceof DateTimeFilter) { if (filterProperty.equal !== undefined) { ret.$eq = filterProperty.equal; } @@ -133,8 +133,12 @@ export function filterToMikroOrmQuery( export function filtersToMikroOrmQuery( // eslint-disable-next-line @typescript-eslint/no-explicit-any filter: any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - applyFilter?: (acc: ObjectQuery, filterValue: StringFilter | NumberFilter | DateFilter | BooleanFilter | unknown, filterKey: string) => void, + applyFilter?: ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + acc: ObjectQuery, + filterValue: StringFilter | NumberFilter | DateTimeFilter | BooleanFilter | unknown, + filterKey: string, + ) => void, // eslint-disable-next-line @typescript-eslint/no-explicit-any ): ObjectQuery { // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/packages/api/cms-api/src/generator/generate-crud.ts b/packages/api/cms-api/src/generator/generate-crud.ts index 47455c6154..bf43ff78d9 100644 --- a/packages/api/cms-api/src/generator/generate-crud.ts +++ b/packages/api/cms-api/src/generator/generate-crud.ts @@ -184,7 +184,7 @@ function generateFilterDto({ generatorOptions, metadata }: { generatorOptions: C } }); - const filterOut = `import { StringFilter, NumberFilter, BooleanFilter, DateFilter, ManyToOneFilter, OneToManyFilter, ManyToManyFilter, createEnumFilter, createEnumsFilter } from "@comet/cms-api"; + const filterOut = `import { StringFilter, NumberFilter, BooleanFilter, DateTimeFilter, ManyToOneFilter, OneToManyFilter, ManyToManyFilter, createEnumFilter, createEnumsFilter } from "@comet/cms-api"; import { Field, InputType } from "@nestjs/graphql"; import { Type } from "class-transformer"; import { IsNumber, IsOptional, IsString, ValidateNested } from "class-validator"; @@ -234,11 +234,11 @@ function generateFilterDto({ generatorOptions, metadata }: { generatorOptions: C ${prop.name}?: BooleanFilter; `; } else if (prop.type === "DateType" || prop.type === "Date") { - return `@Field(() => DateFilter, { nullable: true }) + return `@Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() @IsOptional() - @Type(() => DateFilter) - ${prop.name}?: DateFilter; + @Type(() => DateTimeFilter) + ${prop.name}?: DateTimeFilter; `; } else if (prop.reference === "m:1") { return `@Field(() => ManyToOneFilter, { nullable: true }) diff --git a/packages/api/cms-api/src/index.ts b/packages/api/cms-api/src/index.ts index aed14507d1..e427b9898c 100644 --- a/packages/api/cms-api/src/index.ts +++ b/packages/api/cms-api/src/index.ts @@ -41,7 +41,7 @@ export { ExceptionInterceptor } from "./common/errors/exception.interceptor"; export { CometValidationException } from "./common/errors/validation.exception"; export { ValidationExceptionFactory } from "./common/errors/validation.exception-factory"; export { BooleanFilter } from "./common/filter/boolean.filter"; -export { DateFilter } from "./common/filter/date.filter"; +export { DateTimeFilter } from "./common/filter/date-time.filter"; export { createEnumFilter } from "./common/filter/enum.filter.factory"; export { createEnumsFilter } from "./common/filter/enums.filter.factory"; export { ManyToManyFilter } from "./common/filter/many-to-many.filter"; diff --git a/packages/api/cms-api/src/redirects/dto/redirects.filter.ts b/packages/api/cms-api/src/redirects/dto/redirects.filter.ts index 8838ac9622..868c3514ba 100644 --- a/packages/api/cms-api/src/redirects/dto/redirects.filter.ts +++ b/packages/api/cms-api/src/redirects/dto/redirects.filter.ts @@ -3,7 +3,7 @@ import { Type } from "class-transformer"; import { IsOptional, ValidateNested } from "class-validator"; import { BooleanFilter } from "../../common/filter/boolean.filter"; -import { DateFilter } from "../../common/filter/date.filter"; +import { DateTimeFilter } from "../../common/filter/date-time.filter"; import { StringFilter } from "../../common/filter/string.filter"; @InputType() @@ -23,15 +23,15 @@ export class RedirectFilter { @Type(() => BooleanFilter) active?: BooleanFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() - @Type(() => DateFilter) - createdAt?: DateFilter; + @Type(() => DateTimeFilter) + createdAt?: DateTimeFilter; - @Field(() => DateFilter, { nullable: true }) + @Field(() => DateTimeFilter, { nullable: true }) @ValidateNested() - @Type(() => DateFilter) - updatedAt?: DateFilter; + @Type(() => DateTimeFilter) + updatedAt?: DateTimeFilter; @Field(() => [RedirectFilter], { nullable: true }) @Type(() => RedirectFilter)