feat(medusa): List products with Remote Query (#4969)
**What** - includes some type fixes in the DAL layer - List products including their prices and filtered by the sales channel as well as q parameter and category scope and all other filters - Assign shipping profile - ordering - Add missing columns in the product module - update product module migrations **Comment** - In regards to the fields, we can pass whatever we want the module will only return the one that exists (default behavior), but on the other hand, that is not possible for the relations. **question** - To simplify usage, should we expose the fields/relations available from the module to simplify building a query for the user and be aware of what the module provides **todo** - Add back the support for the user to ask for fields/relations
This commit is contained in:
@@ -8,15 +8,21 @@ import {
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Unique,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import Product from "./product"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "product_category" })
|
||||
class ProductCategory {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@@ -61,13 +67,18 @@ class ProductCategory {
|
||||
})
|
||||
category_children = new Collection<ProductCategory>(this)
|
||||
|
||||
@Property({ onCreate: () => new Date(), columnType: "timestamptz" })
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at?: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at?: Date
|
||||
|
||||
|
||||
@@ -13,13 +13,15 @@ import {
|
||||
|
||||
import { DALUtils, generateEntityId, kebabCase } from "@medusajs/utils"
|
||||
import Product from "./product"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalRelations = "products"
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "product_collection" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
class ProductCollection {
|
||||
[OptionalProps]?: OptionalRelations
|
||||
[OptionalProps]?: OptionalRelations | OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
@@ -40,6 +42,21 @@ class ProductCollection {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata?: Record<string, unknown> | null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_product_collection_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at?: Date
|
||||
|
||||
@@ -12,13 +12,15 @@ import {
|
||||
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
import Product from "./product"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalRelations = "products"
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "image" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
class ProductImage {
|
||||
[OptionalProps]?: OptionalRelations
|
||||
[OptionalProps]?: OptionalRelations | OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
@@ -30,6 +32,21 @@ class ProductImage {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata?: Record<string, unknown> | null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_product_image_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at?: Date
|
||||
|
||||
@@ -10,14 +10,14 @@ import {
|
||||
} from "@mikro-orm/core"
|
||||
import { ProductOption, ProductVariant } from "./index"
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalFields =
|
||||
| "created_at"
|
||||
| "updated_at"
|
||||
| "allow_backorder"
|
||||
| "manage_inventory"
|
||||
| "option_id"
|
||||
| "variant_id"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
type OptionalRelations = "product" | "option" | "variant"
|
||||
|
||||
@Entity({ tableName: "product_option_value" })
|
||||
@@ -53,6 +53,21 @@ class ProductOptionValue {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata?: Record<string, unknown> | null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_product_option_value_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at?: Date
|
||||
|
||||
@@ -14,8 +14,12 @@ import {
|
||||
} from "@mikro-orm/core"
|
||||
import { Product } from "./index"
|
||||
import ProductOptionValue from "./product-option-value"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalRelations = "values" | "product"
|
||||
type OptionalRelations =
|
||||
| "values"
|
||||
| "product"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
type OptionalFields = "product_id"
|
||||
|
||||
@Entity({ tableName: "product_option" })
|
||||
@@ -46,6 +50,21 @@ class ProductOption {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata?: Record<string, unknown> | null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_product_option_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at?: Date
|
||||
|
||||
@@ -12,13 +12,15 @@ import {
|
||||
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
import Product from "./product"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalRelations = "products"
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "product_tag" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
class ProductTag {
|
||||
[OptionalProps]?: OptionalRelations
|
||||
[OptionalProps]?: OptionalRelations | OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
@@ -29,6 +31,21 @@ class ProductTag {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata?: Record<string, unknown> | null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_product_tag_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at?: Date
|
||||
|
||||
@@ -3,15 +3,21 @@ import {
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "product_type" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
class ProductType {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@@ -21,6 +27,21 @@ class ProductType {
|
||||
@Property({ columnType: "json", nullable: true })
|
||||
metadata?: Record<string, unknown> | null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_product_type_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at?: Date
|
||||
|
||||
@@ -15,14 +15,14 @@ import {
|
||||
} from "@mikro-orm/core"
|
||||
import { Product } from "@models"
|
||||
import ProductOptionValue from "./product-option-value"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalFields =
|
||||
| "created_at"
|
||||
| "updated_at"
|
||||
| "allow_backorder"
|
||||
| "manage_inventory"
|
||||
| "product"
|
||||
| "product_id"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "product_variant" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
@@ -108,13 +108,18 @@ class ProductVariant {
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
product_id!: string
|
||||
|
||||
@Property({ onCreate: () => new Date(), columnType: "timestamptz" })
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import ProductTag from "./product-tag"
|
||||
import ProductType from "./product-type"
|
||||
import ProductVariant from "./product-variant"
|
||||
import ProductImage from "./product-image"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
type OptionalRelations = "collection" | "type"
|
||||
type OptionalFields =
|
||||
@@ -34,8 +35,7 @@ type OptionalFields =
|
||||
| "type_id"
|
||||
| "is_giftcard"
|
||||
| "discountable"
|
||||
| "created_at"
|
||||
| "updated_at"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "product" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
@@ -154,13 +154,18 @@ class Product {
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
external_id?: string | null
|
||||
|
||||
@Property({ onCreate: () => new Date(), columnType: "timestamptz" })
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
|
||||
Reference in New Issue
Block a user