feat: Implement missing methods in product module and make more tests pass (#6650)
The 2 bigger remaining tasks are: 1. handling prices for variants 2. Handling options (breaking change) After that all tests should pass on both v1 and v2
This commit is contained in:
@@ -760,7 +760,7 @@ export interface FilterableProductCollectionProps
|
||||
/**
|
||||
* The title to filter product collections by.
|
||||
*/
|
||||
title?: string
|
||||
title?: string | string[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -872,16 +872,19 @@ export interface CreateProductCollectionDTO {
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface UpsertProductCollectionDTO extends UpdateProductCollectionDTO {
|
||||
/**
|
||||
* The ID of the product collection to update.
|
||||
*/
|
||||
id?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
* The data to update in a product collection. The `id` is used to identify which product collection to update.
|
||||
*/
|
||||
export interface UpdateProductCollectionDTO {
|
||||
/**
|
||||
* The ID of the product collection to update.
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* The value of the product collection.
|
||||
*/
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
UpdateProductTagDTO,
|
||||
UpdateProductTypeDTO,
|
||||
UpdateProductVariantDTO,
|
||||
UpsertProductCollectionDTO,
|
||||
UpsertProductDTO,
|
||||
} from "./common"
|
||||
|
||||
@@ -2086,7 +2087,7 @@ export interface IProductModuleService extends IModuleService {
|
||||
* initialize as initializeProductModule,
|
||||
* } from "@medusajs/product"
|
||||
*
|
||||
* async function createCollection (title: string) {
|
||||
* async function createCollections (title: string) {
|
||||
* const productModule = await initializeProductModule()
|
||||
*
|
||||
* const collections = await productModule.createCollections([
|
||||
@@ -2105,11 +2106,100 @@ export interface IProductModuleService extends IModuleService {
|
||||
): Promise<ProductCollectionDTO[]>
|
||||
|
||||
/**
|
||||
* This method is used to update existing product collections.
|
||||
* This method is used to create a product collection.
|
||||
*
|
||||
* @param {UpdateProductCollectionDTO[]} data - The product collections to be updated, each holding the attributes that should be updated in the product collection.
|
||||
* @param {CreateProductCollectionDTO} data - The product collection to be created.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ProductCollectionDTO[]>} The list of updated product collections.
|
||||
* @returns {Promise<ProductCollectionDTO>} The created product collection.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializeProductModule,
|
||||
* } from "@medusajs/product"
|
||||
*
|
||||
* async function createCollection (title: string) {
|
||||
* const productModule = await initializeProductModule()
|
||||
*
|
||||
* const collection = await productModule.createCollections(
|
||||
* {
|
||||
* title
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the product collection or return them
|
||||
* }
|
||||
*
|
||||
*/
|
||||
createCollections(
|
||||
data: CreateProductCollectionDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ProductCollectionDTO>
|
||||
|
||||
/**
|
||||
* This method updates existing collections, or creates new ones if they don't exist.
|
||||
*
|
||||
* @param {UpsertProductCollectionDTO[]} data - The attributes to update or create for each collection.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ProductCollectionDTO[]>} The updated and created collections.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializeProductModule,
|
||||
* } from "@medusajs/product"
|
||||
*
|
||||
* async function upserCollections (title: string) {
|
||||
* const productModule = await initializeProductModule()
|
||||
*
|
||||
* const createdCollections = await productModule.upsert([
|
||||
* {
|
||||
* title
|
||||
* }
|
||||
* ])
|
||||
*
|
||||
* // do something with the collections or return them
|
||||
* }
|
||||
*/
|
||||
upsertCollections(
|
||||
data: UpsertProductCollectionDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<ProductCollectionDTO[]>
|
||||
|
||||
/**
|
||||
* This method updates an existing collection, or creates a new one if it doesn't exist.
|
||||
*
|
||||
* @param {UpsertProductCollectionDTO} data - The attributes to update or create for the collection.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ProductCollectionDTO>} The updated or created collection.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializeProductModule,
|
||||
* } from "@medusajs/product"
|
||||
*
|
||||
* async function upserCollection (title: string) {
|
||||
* const productModule = await initializeProductModule()
|
||||
*
|
||||
* const createdCollection = await productModule.upsert(
|
||||
* {
|
||||
* title
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the collection or return it
|
||||
* }
|
||||
*/
|
||||
upsertCollections(
|
||||
data: UpsertProductCollectionDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ProductCollectionDTO>
|
||||
|
||||
/**
|
||||
* This method is used to update a collection.
|
||||
*
|
||||
* @param {string} id - The ID of the collection to be updated.
|
||||
* @param {UpdateProductCollectionDTO} data - The attributes of the collection to be updated
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ProductCollectionDTO>} The updated collection.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
@@ -2119,19 +2209,47 @@ export interface IProductModuleService extends IModuleService {
|
||||
* async function updateCollection (id: string, title: string) {
|
||||
* const productModule = await initializeProductModule()
|
||||
*
|
||||
* const collections = await productModule.updateCollections([
|
||||
* {
|
||||
* id,
|
||||
* const collection = await productModule.updateCollections(id, {
|
||||
* title
|
||||
* }
|
||||
* ])
|
||||
* )
|
||||
*
|
||||
* // do something with the product collections or return them
|
||||
* // do something with the collection or return it
|
||||
* }
|
||||
*
|
||||
*/
|
||||
updateCollections(
|
||||
data: UpdateProductCollectionDTO[],
|
||||
id: string,
|
||||
data: UpdateProductCollectionDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ProductCollectionDTO>
|
||||
|
||||
/**
|
||||
* This method is used to update a list of collections determined by the selector filters.
|
||||
*
|
||||
* @param {FilterableProductCollectionProps} selector - The filters that will determine which collections will be updated.
|
||||
* @param {UpdateProductCollectionDTO} data - The attributes to be updated on the selected collections
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ProductCollectionDTO[]>} The updated collections.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializeProductModule,
|
||||
* } from "@medusajs/product"
|
||||
*
|
||||
* async function updateCollections(ids: string[], title: string) {
|
||||
* const productModule = await initializeProductModule()
|
||||
*
|
||||
* const collections = await productModule.updateCollections({id: ids}, {
|
||||
* title
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the collections or return them
|
||||
* }
|
||||
*/
|
||||
updateCollections(
|
||||
selector: FilterableProductCollectionProps,
|
||||
data: UpdateProductCollectionDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ProductCollectionDTO[]>
|
||||
|
||||
@@ -2761,6 +2879,74 @@ export interface IProductModuleService extends IModuleService {
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* This method is used to delete product collections. Unlike the {@link deleteCollections} method, this method won't completely remove the collection. It can still be accessed or retrieved using methods like {@link retrieveCollections} if you pass the `withDeleted` property to the `config` object parameter.
|
||||
*
|
||||
* The soft-deleted collections can be restored using the {@link restoreCollections} method.
|
||||
*
|
||||
* @param {string[]} collectionIds - The IDs of the collections to soft-delete.
|
||||
* @param {SoftDeleteReturn<TReturnableLinkableKeys>} config -
|
||||
* Configurations determining which relations to soft delete along with the each of the collections. You can pass to its `returnLinkableKeys`
|
||||
* property any of the collection's relation attribute names.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<Record<string, string[]> | void>}
|
||||
* An object that includes the IDs of related records that were also soft deleted. The object's keys are the ID attribute names of the collection entity's relations.
|
||||
*
|
||||
* If there are no related records, the promise resolved to `void`.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializeProductModule,
|
||||
* } from "@medusajs/product"
|
||||
*
|
||||
* async function deleteCollections (ids: string[]) {
|
||||
* const productModule = await initializeProductModule()
|
||||
*
|
||||
* const cascadedEntities = await productModule.softDeleteCollections(ids)
|
||||
*
|
||||
* // do something with the returned cascaded entity IDs or return them
|
||||
* }
|
||||
*/
|
||||
softDeleteCollections<TReturnableLinkableKeys extends string = string>(
|
||||
collectionIds: string[],
|
||||
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* This method is used to restore collections which were deleted using the {@link softDelete} method.
|
||||
*
|
||||
* @param {string[]} collectionIds - The IDs of the collections to restore.
|
||||
* @param {RestoreReturn<TReturnableLinkableKeys>} config -
|
||||
* Configurations determining which relations to restore along with each of the collections. You can pass to its `returnLinkableKeys`
|
||||
* property any of the collection's relation attribute names.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<Record<string, string[]> | void>}
|
||||
* An object that includes the IDs of related records that were restored. The object's keys are the ID attribute names of the product entity's relations.
|
||||
*
|
||||
* If there are no related records that were restored, the promise resolved to `void`.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializeProductModule,
|
||||
* } from "@medusajs/product"
|
||||
*
|
||||
* async function restoreCollections (ids: string[]) {
|
||||
* const productModule = await initializeProductModule()
|
||||
*
|
||||
* const cascadedEntities = await productModule.restoreCollections(ids, {
|
||||
* returnLinkableKeys: []
|
||||
* })
|
||||
*
|
||||
* // do something with the returned cascaded entity IDs or return them
|
||||
* }
|
||||
*/
|
||||
restoreCollections<TReturnableLinkableKeys extends string = string>(
|
||||
collectionIds: string[],
|
||||
config?: RestoreReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* This method is used to restore product varaints that were soft deleted. Product variants are soft deleted when they're not
|
||||
* provided in a product's details passed to the {@link update} method.
|
||||
|
||||
Reference in New Issue
Block a user