feat: Add support for search to all endpoints (#7149)

* feat: Add search capability to api keys

* feat: Add support for searching to currency and customer endpoints

* fix: Clean up product search filters

* feat: Add search support to regions

* feat: Add search support to sales channels

* feat: Add search support to store module

* feat: Add search support to user module

* fix: Clean up inventory search

* feat: Add search support for payments

* fix: Add searchable attributes to stock location models

* feat: Add search support to tax

* feat: Add search support to promotions

* feat: Add search support for pricing, filtering cleanup

* fix: Further cleanups around search
This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-04-25 17:36:59 +02:00
1 parent d02905cefa
commit f03a822253
52 files changed
+640 -64

No files matched your search

+3
View File
@@ -1,4 +1,5 @@
import {
Searchable,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
@@ -35,9 +36,11 @@ export default class ApiKey {
@Property({ columnType: "text" })
salt: string
@Searchable()
@Property({ columnType: "text" })
redacted: string
@Searchable()
@Property({ columnType: "text" })
title: string
@@ -443,6 +443,10 @@ export default class ApiKeyModuleService<TEntity extends ApiKey = ApiKey>
// There can only be 2 secret keys at most, and one has to be with a revoked_at date set, so only 1 can be newly created.
const secretKeysToCreate = data.filter((k) => k.type === ApiKeyType.SECRET)
if (!secretKeysToCreate.length) {
return
}
if (secretKeysToCreate.length > 1) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
+10 -1
View File
@@ -1,5 +1,5 @@
import { DAL } from "@medusajs/types"
import { generateEntityId } from "@medusajs/utils"
import { Searchable, generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
@@ -37,6 +37,7 @@ export default class Address {
@PrimaryKey({ columnType: "text" })
id!: string
@Searchable()
@Property({ columnType: "text", nullable: true })
address_name: string | null = null
@@ -56,30 +57,38 @@ export default class Address {
})
customer: Customer
@Searchable()
@Property({ columnType: "text", nullable: true })
company: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
first_name: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
last_name: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
address_1: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
address_2: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
city: string | null = null
@Property({ columnType: "text", nullable: true })
country_code: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
province: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
postal_code: string | null = null
@@ -1,5 +1,5 @@
import { DAL } from "@medusajs/types"
import { DALUtils, generateEntityId } from "@medusajs/utils"
import { DALUtils, Searchable, generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Entity,
@@ -24,6 +24,7 @@ export default class CustomerGroup {
@PrimaryKey({ columnType: "text" })
id!: string
@Searchable()
@Property({ columnType: "text", nullable: true })
name: string | null = null
@@ -70,9 +70,11 @@ export class InventoryItem {
@Property({ columnType: "text", nullable: true })
origin_country: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
hs_code: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
mid_code: string | null = null
@@ -14,6 +14,7 @@ export const AdminGetApiKeysParams = createFindParams({
limit: 50,
}).merge(
z.object({
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
title: z.union([z.string(), z.array(z.string())]).optional(),
token: z.union([z.string(), z.array(z.string())]).optional(),
@@ -12,6 +12,7 @@ export const AdminGetCampaignsParams = createFindParams({
limit: 50,
}).merge(
z.object({
q: z.string().optional(),
campaign_identifier: z.string().optional(),
currency: z.string().optional(),
$and: z.lazy(() => AdminGetCampaignsParams.array()).optional(),
@@ -82,6 +82,7 @@ export const AdminCustomerAdressesParams = createFindParams({
limit: 50,
}).merge(
z.object({
q: z.string().optional(),
address_name: z.union([z.string(), z.array(z.string())]).optional(),
is_default_shipping: z.boolean().optional(),
is_default_billing: z.boolean().optional(),
@@ -14,6 +14,7 @@ export const AdminGetPaymentsParams = createFindParams({
offset: 0,
}).merge(
z.object({
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
created_at: createOperatorMap().optional(),
updated_at: createOperatorMap().optional(),
@@ -1,17 +1,29 @@
import { PriceListStatus, PriceListType } from "@medusajs/types"
import { z } from "zod"
import { createFindParams, createSelectParams } from "../../utils/validators"
import {
createFindParams,
createOperatorMap,
createSelectParams,
} from "../../utils/validators"
export const AdminGetPriceListPricesParams = createSelectParams()
export const AdminGetPriceListsParams = createFindParams({
offset: 0,
limit: 50,
})
}).merge(
z.object({
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
starts_at: createOperatorMap().optional(),
ends_at: createOperatorMap().optional(),
status: z.array(z.nativeEnum(PriceListStatus)).optional(),
rules_count: z.array(z.number()).optional(),
$and: z.lazy(() => AdminGetPriceListsParams.array()).optional(),
$or: z.lazy(() => AdminGetPriceListsParams.array()).optional(),
})
)
export const AdminGetPriceListParams = createFindParams({
offset: 0,
limit: 50,
})
export const AdminGetPriceListParams = createSelectParams()
export const AdminCreatePriceListPrice = z.object({
currency_code: z.string(),
@@ -14,6 +14,7 @@ export const AdminGetRegionsParams = createFindParams({
offset: 0,
}).merge(
z.object({
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
code: z.union([z.string(), z.array(z.string())]).optional(),
name: z.union([z.string(), z.array(z.string())]).optional(),
@@ -18,6 +18,7 @@ export const AdminGetSalesChannelsParams = createFindParams({
offset: 0,
}).merge(
z.object({
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
name: z.union([z.string(), z.array(z.string())]).optional(),
description: z.string().optional(),
@@ -10,6 +10,7 @@ export const AdminGetStoresParams = createFindParams({
offset: 0,
}).merge(
z.object({
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
name: z.union([z.string(), z.array(z.string())]).optional(),
$and: z.lazy(() => AdminGetStoresParams.array()).optional(),
@@ -18,8 +18,8 @@ export const AdminGetTaxRegionsParams = createFindParams({
offset: 0,
}).merge(
z.object({
id: z.union([z.string(), z.array(z.string())]).optional(),
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
country_code: z
.union([z.string(), z.array(z.string()), createOperatorMap()])
.optional(),
@@ -13,6 +13,7 @@ export const AdminGetUsersParams = createFindParams({
limit: 50,
}).merge(
z.object({
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
created_at: createOperatorMap().optional(),
updated_at: createOperatorMap().optional(),
@@ -20,7 +21,6 @@ export const AdminGetUsersParams = createFindParams({
email: z.string().optional(),
first_name: z.string().optional(),
last_name: z.string().optional(),
q: z.string().optional(),
})
)
+4
View File
@@ -3,6 +3,7 @@ import {
BigNumber,
DALUtils,
MikroOrmBigNumberProperty,
Searchable,
generateEntityId,
} from "@medusajs/utils"
import {
@@ -46,12 +47,15 @@ export default class Payment {
@Property({ columnType: "text" })
provider_id: string
@Searchable()
@Property({ columnType: "text", nullable: true })
cart_id: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
order_id: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
customer_id: string | null = null
@@ -5,6 +5,7 @@ import {
generateEntityId,
PriceListStatus,
PriceListType,
Searchable,
} from "@medusajs/utils"
import {
BeforeCreate,
@@ -46,9 +47,11 @@ export default class PriceList {
@PrimaryKey({ columnType: "text" })
id!: string
@Searchable()
@Property({ columnType: "text" })
title: string
@Searchable()
@Property({ columnType: "text" })
description: string
+3 -1
View File
@@ -1,5 +1,5 @@
import { DAL } from "@medusajs/types"
import { DALUtils, generateEntityId } from "@medusajs/utils"
import { DALUtils, Searchable, generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Collection,
@@ -32,9 +32,11 @@ export default class Campaign {
@PrimaryKey({ columnType: "text" })
id!: string
@Searchable()
@Property({ columnType: "text" })
name: string
@Searchable()
@Property({ columnType: "text", nullable: true })
description: string | null = null
+8 -1
View File
@@ -1,5 +1,10 @@
import { DAL, PromotionTypeValues } from "@medusajs/types"
import { DALUtils, PromotionUtils, generateEntityId } from "@medusajs/utils"
import {
DALUtils,
PromotionUtils,
Searchable,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Collection,
@@ -31,6 +36,7 @@ export default class Promotion {
@PrimaryKey({ columnType: "text" })
id!: string
@Searchable()
@Property({ columnType: "text" })
@Index({ name: "IDX_promotion_code" })
@Unique({
@@ -39,6 +45,7 @@ export default class Promotion {
})
code: string
@Searchable()
@ManyToOne(() => Campaign, {
fieldName: "campaign_id",
nullable: true,
+3 -1
View File
@@ -1,5 +1,5 @@
import { DAL } from "@medusajs/types"
import { DALUtils, generateEntityId } from "@medusajs/utils"
import { DALUtils, Searchable, generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Collection,
@@ -24,9 +24,11 @@ export default class Region {
@PrimaryKey({ columnType: "text" })
id: string
@Searchable()
@Property({ columnType: "text" })
name: string
@Searchable()
@Property({ columnType: "text" })
currency_code: string
@@ -1,4 +1,4 @@
import { DALUtils, generateEntityId } from "@medusajs/utils"
import { DALUtils, Searchable, generateEntityId } from "@medusajs/utils"
import { DAL } from "@medusajs/types"
import {
@@ -22,9 +22,11 @@ export default class SalesChannel {
@PrimaryKey({ columnType: "text" })
id!: string
@Searchable()
@Property({ columnType: "text" })
name!: string
@Searchable()
@Property({ columnType: "text", nullable: true })
description: string | null = null
@@ -1,4 +1,4 @@
import { generateEntityId } from "@medusajs/utils"
import { Searchable, generateEntityId } from "@medusajs/utils"
import {
BeforeInsert,
Column,
@@ -24,15 +24,19 @@ export class StockLocationAddress {
@DeleteDateColumn({ type: "timestamptz" })
deleted_at: Date | null
@Searchable()
@Column({ type: "text" })
address_1: string
@Searchable()
@Column({ type: "text", nullable: true })
address_2: string | null
@Searchable()
@Column({ type: "text", nullable: true })
company: string | null
@Searchable()
@Column({ type: "text", nullable: true })
city: string | null
@@ -43,9 +47,11 @@ export class StockLocationAddress {
@Column({ type: "text", nullable: true })
phone: string | null
@Searchable()
@Column({ type: "text", nullable: true })
province: string | null
@Searchable()
@Column({ type: "text", nullable: true })
postal_code: string | null
@@ -1,4 +1,4 @@
import { generateEntityId } from "@medusajs/utils"
import { Searchable, generateEntityId } from "@medusajs/utils"
import {
BeforeInsert,
Column,
@@ -27,6 +27,7 @@ export class StockLocation {
@DeleteDateColumn({ type: "timestamptz" })
deleted_at: Date | null
@Searchable()
@Column({ type: "text" })
name: string
@@ -34,6 +35,7 @@ export class StockLocation {
@Column({ type: "text", nullable: true })
address_id: string | null
@Searchable()
@ManyToOne(() => StockLocationAddress)
@JoinColumn({ name: "address_id" })
address: StockLocationAddress | null
+2
View File
@@ -1,5 +1,6 @@
import {
DALUtils,
Searchable,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
@@ -32,6 +33,7 @@ export default class Store {
@PrimaryKey({ columnType: "text" })
id: string
@Searchable()
@Property({ columnType: "text", default: "Medusa Store" })
name: string
@@ -67,6 +67,10 @@ export interface ApiKeyDTO {
*/
export interface FilterableApiKeyProps
extends BaseFilterable<FilterableApiKeyProps> {
/**
* Search through the api key names and redacted keys using this search term.
*/
q?: string
/**
* The IDs to filter the API keys by.
*/
@@ -43,6 +43,10 @@ export interface CurrencyDTO {
*/
export interface FilterableCurrencyProps
extends BaseFilterable<FilterableCurrencyProps> {
/**
* Search through currencies using this search term.
*/
q?: string
/**
* The codes to filter the currencies by.
*/
+15
View File
@@ -102,6 +102,11 @@ export interface CustomerAddressDTO {
*/
export interface FilterableCustomerAddressProps
extends BaseFilterable<FilterableCustomerAddressProps> {
/**
* Searches for addreses by properties such as name and street using this search term.
*/
q?: string
/**
* The IDs to filter the customer address by.
*/
@@ -203,6 +208,11 @@ export interface FilterableCustomerAddressProps
*/
export interface FilterableCustomerGroupProps
extends BaseFilterable<FilterableCustomerGroupProps> {
/**
* Searches for customer groups by name using this search term.
*/
q?: string
/**
* The IDs to filter the customer group by.
*/
@@ -285,6 +295,11 @@ export interface FilterableCustomerGroupCustomerProps
*/
export interface FilterableCustomerProps
extends BaseFilterable<FilterableCustomerProps> {
/**
* Searches for customers by properties such as name and email using this search term.
*/
q?: string
/**
* The IDs to filter the customer by.
*/
@@ -101,6 +101,11 @@ export interface InventoryItemDTO {
* The filters to apply on retrieved inventory items.
*/
export interface FilterableInventoryItemProps {
/**
* Search term to search inventory items' attributes.
*/
q?: string
/**
* The IDs to filter inventory items by.
*/
@@ -111,11 +116,6 @@ export interface FilterableInventoryItemProps {
*/
location_id?: string | string[]
/**
* Search term to search inventory items' attributes.
*/
q?: string
/**
* The SKUs to filter inventory items by.
*/
+5
View File
@@ -419,6 +419,11 @@ export interface PaymentDTO {
*/
export interface FilterablePaymentProps
extends BaseFilterable<FilterablePaymentProps> {
/**
* Find payments based on cart, order, or customer IDs through this search term.
*/
q?: string
/**
* The IDs to filter the payments by.
*/
@@ -1,4 +1,4 @@
import { BaseFilterable } from "../../dal"
import { BaseFilterable, OperatorMap } from "../../dal"
import {
CreateMoneyAmountDTO,
MoneyAmountDTO,
@@ -240,18 +240,22 @@ export interface UpdatePriceListDTO {
*/
export interface FilterablePriceListProps
extends BaseFilterable<FilterablePriceListProps> {
/**
* Find price lists by title or description through this search term.
*/
q?: string
/**
* The IDs to filter price lists by
*/
id?: string[]
id?: string | string[]
/**
* The start dates to filter price lists by.
*/
starts_at?: string[]
starts_at?: OperatorMap<string>
/**
* The end dates to filter price lists by.
*/
ends_at?: string[]
ends_at?: OperatorMap<string>
/**
* The statuses to filter price lists by.
*/
+4 -4
View File
@@ -888,6 +888,10 @@ export interface FilterableProductVariantProps
*/
export interface FilterableProductCategoryProps
extends BaseFilterable<FilterableProductCategoryProps> {
/**
* Filter product categories based on searchable fields
*/
q?: string
/**
* The IDs to filter product categories by.
*/
@@ -920,10 +924,6 @@ export interface FilterableProductCategoryProps
* Whether to include parents of retrieved product categories.
*/
include_ancestors_tree?: boolean
/**
* Filter product categories based on searchable fields
*/
q?: string
}
/**
@@ -51,6 +51,10 @@ export interface CampaignDTO {
*/
export interface FilterableCampaignProps
extends BaseFilterable<FilterableCampaignProps> {
/**
* Find campaigns by their name or description through this search term.
*/
q?: string
/**
* The IDs to filter the campaigns by.
*/
@@ -141,6 +141,11 @@ export interface UpdatePromotionDTO {
*/
export interface FilterablePromotionProps
extends BaseFilterable<FilterablePromotionProps> {
/**
* The IDs to filter the promotions by.
*/
q?: string
/**
* The IDs to filter the promotions by.
*/
+4
View File
@@ -90,6 +90,10 @@ export interface RegionCountryDTO {
*/
export interface FilterableRegionProps
extends BaseFilterable<FilterableRegionProps> {
/**
* Find regions by name through this search term
*/
q?: string
/**
* The IDs to filter the regions by.
*/
@@ -60,6 +60,11 @@ export interface SalesChannelDTO {
*/
export interface FilterableSalesChannelProps
extends BaseFilterable<FilterableSalesChannelProps> {
/**
* Find sales channels by their name or description through this search term.
*/
q?: string
/**
* The IDs to filter the sales channel by.
*/
+4
View File
@@ -60,6 +60,10 @@ export interface StoreDTO {
*/
export interface FilterableStoreProps
extends BaseFilterable<FilterableStoreProps> {
/**
* Find stores by name through this search term.
*/
q?: string
/**
* The IDs to filter the stores by.
*/
+10
View File
@@ -93,6 +93,11 @@ export interface TaxProviderDTO {
*/
export interface FilterableTaxRateProps
extends BaseFilterable<FilterableTaxRateProps> {
/**
* Find tax rates based on name and code properties through this search term.
*/
q?: string
/**
* The IDs to filter the tax rates by.
*/
@@ -190,6 +195,11 @@ export interface TaxRegionDTO {
*/
export interface FilterableTaxRegionProps
extends BaseFilterable<FilterableTaxRegionProps> {
/**
* Find tax regions based on currency and province codes through this search term.
*/
q?: string
/**
* The IDs to filter the tax regions by.
*/
+4
View File
@@ -52,6 +52,10 @@ export interface UserDTO {
*/
export interface FilterableUserProps
extends BaseFilterable<FilterableUserProps> {
/**
* Find users by name or email through this search term
*/
q?: string
/**
* The IDs to filter users by.
*/