Skip to content

Commit

Permalink
Demo: Remove product package dimensions (#1730)
Browse files Browse the repository at this point in the history
- `packageDimensions` was nullable, although the database fields aren't
nullable (caused an DB error if null was saved)
- Admin Generator (present and future) doesn't support nested fields
(for future it is WIP, present will never get it)
- Easy solution: remove it
- #1729 will showcase nested fields and everything (as replacement for
packageDimensions)
  • Loading branch information
Ben-Ho authored Feb 22, 2024
1 parent 75865ca commit 8d508cf
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 55 deletions.
1 change: 0 additions & 1 deletion demo/admin/src/products/ProductForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ function ProductForm({ id }: FormProps): React.ReactElement {
variants: [],
articleNumbers: [],
discounts: [],
packageDimensions: { width: 0, height: 0, depth: 0 },
statistics: { views: 0 },
};
if (mode === "edit") {
Expand Down
6 changes: 0 additions & 6 deletions demo/admin/src/products/ProductsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ function ProductsGrid() {
})),
articleNumbers: input.articleNumbers,
discounts: input.discounts,
packageDimensions: input.packageDimensions,
statistics: { views: 0 },
},
},
Expand Down Expand Up @@ -245,11 +244,6 @@ const productsFragment = gql`
quantity
price
}
packageDimensions {
width
height
depth
}
}
`;

Expand Down
15 changes: 0 additions & 15 deletions demo/api/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,6 @@ type ProductDimensions {
depth: Float!
}

type ProductPackageDimensions {
width: Float!
height: Float!
depth: Float!
}

type Product implements DocumentInterface {
id: ID!
updatedAt: DateTime!
Expand All @@ -473,7 +467,6 @@ type Product implements DocumentInterface {
discounts: [ProductDiscounts!]!
articleNumbers: [String!]!
dimensions: ProductDimensions
packageDimensions: ProductPackageDimensions
statistics: ProductStatistics
createdAt: DateTime!
category: ProductCategory
Expand Down Expand Up @@ -595,12 +588,6 @@ input ProductDimensionsInput {
depth: Float!
}

input ProductPackageDimensionsInput {
width: Float!
height: Float!
depth: Float!
}

input RedirectScopeInput {
domain: String!
}
Expand Down Expand Up @@ -1148,7 +1135,6 @@ input ProductInput {
discounts: [ProductDiscountsInput!]! = []
articleNumbers: [String!]! = []
dimensions: ProductDimensionsInput
packageDimensions: ProductPackageDimensionsInput
statistics: ProductStatisticsInput
variants: [ProductVariantInput!]! = []
category: ID = null
Expand All @@ -1175,7 +1161,6 @@ input ProductUpdateInput {
discounts: [ProductDiscountsInput!]
articleNumbers: [String!]
dimensions: ProductDimensionsInput
packageDimensions: ProductPackageDimensionsInput
statistics: ProductStatisticsInput
variants: [ProductVariantInput!]
category: ID
Expand Down
10 changes: 10 additions & 0 deletions demo/api/src/db/migrations/Migration20240222081515.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240222081515 extends Migration {

async up(): Promise<void> {
this.addSql('alter table "Product" drop column "packageDimensions_width";');
this.addSql('alter table "Product" drop column "packageDimensions_height";');
this.addSql('alter table "Product" drop column "packageDimensions_depth";');
}
}
26 changes: 0 additions & 26 deletions demo/api/src/products/entities/product.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { CrudField, CrudGenerator, DamImageBlock, DocumentInterface, RootBlockDa
import {
BaseEntity,
Collection,
Embeddable,
Embedded,
Entity,
Enum,
ManyToMany,
Expand Down Expand Up @@ -55,26 +53,6 @@ export class ProductDimensions {
depth: number;
}

@Embeddable()
@ObjectType()
@InputType("ProductPackageDimensionsInput")
export class ProductPackageDimensions {
@Property({ type: types.integer })
@Field()
@IsNumber()
width: number;

@Property({ type: types.integer })
@Field()
@IsNumber()
height: number;

@Property({ type: types.integer })
@Field()
@IsNumber()
depth: number;
}

@ObjectType({
implements: () => [DocumentInterface],
})
Expand Down Expand Up @@ -147,10 +125,6 @@ export class Product extends BaseEntity<Product, "id"> implements DocumentInterf
@Field(() => ProductDimensions, { nullable: true })
dimensions?: ProductDimensions = undefined;

@Embedded(() => ProductPackageDimensions, { nullable: true })
@Field(() => ProductPackageDimensions, { nullable: true })
packageDimensions?: ProductPackageDimensions = undefined;

@OneToOne(() => ProductStatistics, { inversedBy: "product", owner: true, ref: true, nullable: true })
@Field(() => ProductStatistics, { nullable: true })
statistics?: Ref<ProductStatistics> = undefined;
Expand Down
8 changes: 1 addition & 7 deletions demo/api/src/products/generated/dto/product.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Field, ID, InputType } from "@nestjs/graphql";
import { Transform, Type } from "class-transformer";
import { IsArray, IsBoolean, IsEnum, IsNotEmpty, IsNumber, IsString, IsUUID, ValidateNested } from "class-validator";

import { ProductDimensions, ProductDiscounts, ProductPackageDimensions } from "../../entities/product.entity";
import { ProductDimensions, ProductDiscounts } from "../../entities/product.entity";
import { ProductType } from "../../entities/product-type.enum";
import { ProductStatisticsInput } from "./product-statistics.nested.input";
import { ProductVariantInput } from "./product-variant.nested.input";
Expand Down Expand Up @@ -69,12 +69,6 @@ export class ProductInput {
@Field(() => ProductDimensions, { nullable: true })
dimensions?: ProductDimensions;

@IsNullable()
@ValidateNested()
@Type(() => ProductPackageDimensions)
@Field(() => ProductPackageDimensions, { nullable: true })
packageDimensions?: ProductPackageDimensions;

@IsNullable()
@Field(() => ProductStatisticsInput, { nullable: true })
@Type(() => ProductStatisticsInput)
Expand Down

0 comments on commit 8d508cf

Please sign in to comment.