feat(prduct, utils, types): Create soft delete pattern for link module (#4649)

* feat(prouct, utils, types): Create soft delete pattern for link module

* add comment

* add comment

* finalise

* remove linkable keys

* cleanup and tests

* cleanup

* add some comments and renaming

* re work

* fix tests

---------

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
Adrien de PerettiandRiqwan Thamir authored and GitHub committed 2023-08-02 19:29:01 +02:00
1 parent fc6c9df035
commit ce3326c5fb
17 files changed
+448 -166

No files matched your search

+12 -1
View File
@@ -41,7 +41,18 @@ export interface RepositoryService<T = any> extends BaseRepositoryService<T> {
delete(ids: string[], context?: Context): Promise<void>
softDelete(ids: string[], context?: Context): Promise<T[]>
/**
* Soft delete entities and cascade to related entities if configured.
*
* @param ids
* @param context
*
* @returns [T[], Record<string, string[]>] the second value being the map of the entity names and ids that were soft deleted
*/
softDelete(
ids: string[],
context?: Context
): Promise<[T[], Record<string, unknown[]>]>
restore(ids: string[], context?: Context): Promise<T[]>
}
+28 -36
View File
@@ -1,30 +1,30 @@
import {
CreateProductCategoryDTO,
CreateProductCollectionDTO,
CreateProductDTO,
CreateProductOptionDTO,
CreateProductTagDTO,
CreateProductTypeDTO,
CreateProductOptionDTO,
CreateProductCategoryDTO,
UpdateProductTagDTO,
UpdateProductTypeDTO,
UpdateProductOptionDTO,
UpdateProductCategoryDTO,
UpdateProductDTO,
FilterableProductCategoryProps,
FilterableProductCollectionProps,
FilterableProductOptionProps,
FilterableProductProps,
FilterableProductTagProps,
FilterableProductTypeProps,
FilterableProductOptionProps,
FilterableProductVariantProps,
ProductCategoryDTO,
ProductCollectionDTO,
ProductDTO,
ProductOptionDTO,
ProductTagDTO,
ProductTypeDTO,
ProductOptionDTO,
ProductVariantDTO,
CreateProductCollectionDTO,
UpdateProductCategoryDTO,
UpdateProductCollectionDTO,
UpdateProductDTO,
UpdateProductOptionDTO,
UpdateProductTagDTO,
UpdateProductTypeDTO,
} from "./common"
import { Context } from "../shared-context"
@@ -72,18 +72,15 @@ export interface IProductModuleService {
createTags(
data: CreateProductTagDTO[],
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductTagDTO[]>
updateTags(
data: UpdateProductTagDTO[],
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductTagDTO[]>
deleteTags(
productTagIds: string[],
sharedContext?: Context,
): Promise<void>
deleteTags(productTagIds: string[], sharedContext?: Context): Promise<void>
retrieveType(
typeId: string,
@@ -105,18 +102,15 @@ export interface IProductModuleService {
createTypes(
data: CreateProductTypeDTO[],
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductTypeDTO[]>
updateTypes(
data: UpdateProductTypeDTO[],
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductTypeDTO[]>
deleteTypes(
productTypeIds: string[],
sharedContext?: Context,
): Promise<void>
deleteTypes(productTypeIds: string[], sharedContext?: Context): Promise<void>
retrieveOption(
optionId: string,
@@ -138,17 +132,17 @@ export interface IProductModuleService {
createOptions(
data: CreateProductOptionDTO[],
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductOptionDTO[]>
updateOptions(
data: UpdateProductOptionDTO[],
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductOptionDTO[]>
deleteOptions(
productOptionIds: string[],
sharedContext?: Context,
sharedContext?: Context
): Promise<void>
retrieveVariant(
@@ -189,17 +183,17 @@ export interface IProductModuleService {
createCollections(
data: CreateProductCollectionDTO[],
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductCollectionDTO[]>
updateCollections(
data: UpdateProductCollectionDTO[],
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductCollectionDTO[]>
deleteCollections(
productCollectionIds: string[],
sharedContext?: Context,
sharedContext?: Context
): Promise<void>
retrieveCategory(
@@ -222,19 +216,16 @@ export interface IProductModuleService {
createCategory(
data: CreateProductCategoryDTO,
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductCategoryDTO>
updateCategory(
categoryId: string,
data: UpdateProductCategoryDTO,
sharedContext?: Context,
sharedContext?: Context
): Promise<ProductCategoryDTO>
deleteCategory(
categoryId: string,
sharedContext?: Context,
): Promise<void>
deleteCategory(categoryId: string, sharedContext?: Context): Promise<void>
create(
data: CreateProductDTO[],
@@ -248,10 +239,11 @@ export interface IProductModuleService {
delete(productIds: string[], sharedContext?: Context): Promise<void>
softDelete(
softDelete<TReturnableLinkableKeys extends string = string>(
productIds: string[],
config?: { returnLinkableKeys?: TReturnableLinkableKeys[] },
sharedContext?: Context
): Promise<ProductDTO[]>
): Promise<Record<string, string[]> | void>
restore(productIds: string[], sharedContext?: Context): Promise<ProductDTO[]>
}