feat(product): Create (+ workflow), delete, restore (#4459)
* Feat: create product with product module * feat: create product wip * feat: create product wip * feat: update product relation and generate image migration * lint * conitnue implementation * continue implementation and add integration tests for produceService.create * Add integration tests for product creation at the module level for the complete flow * only use persist since write operations are always wrapped in a transaction which will be committed and flushed * simplify the transaction wrapper to make future changes easier * feat: move some utils to the utils package to simplify its usage * tests: fix unit tests * feat: create variants along side the product * Add more integration tests an update migrations * chore: Update actions workflow to include packages integration tests * small types and utils cleanup * chore: Add support for database debug option * chore: Add missing types in package.json from types and util, validate that all the models are sync with medusa * expose retrieve method * fix types issues * fix unit tests and move integration tests workflow with the plugins integration tests * chore: remove migration function export from the definition to prevent them to be ran by the medusa cli just in case * fix package.json script * chore: workflows * feat: start creating the create product workflow * feat: add empty step for prices and sales channel * tests: update scripts and action envs * fix imports * feat: Add proper soft deleted support + add product deletion service public api * chore: update migrations * chore: update migrations * chore: update todo * feat: Add product deletion to the create-product workflow as compensation * chore: cleanup product utils * feat: Add support for cascade soft-remove * feat: refactor repository to take into account withDeleted * fix integration tests * Add support for force delete -> delete, cleanup repositories and improvements * Add support for restoring a product and add integration tests * cleaup + tests * types * fix integration tests * remove unnecessary comments * move specific mikro orm usage to the DAL * Cleanup workflow functions * Make deleted_at optional at the property level and add url index for the images * address feedback + cleanup * fix export * merge migrations into one * feat(product, types): added missing product variant methods (#4475) * chore: added missing product variant methods * chore: address PR feedback * chore: catch undefined case for retrieve + specs for variant service * chore: align TEntity + add changeset * chore: revert changeset, TEntity to ProductVariant * chore: write tests for pagination, unskip the test * Create chilled-mice-deliver.md * update integration fixtuers * update pipeline node version * rename github action * fix pipeline * feat(medusa, types): added missing category tests and service methods (#4499) * chore: added missing category tests and service methods * chore: added type changes to module service * chore: address pr feedback * update repositories manager usage and serialisation from the write public API * move serializisation to the DAL * rename template args * chore: added collection methods for module and collection service (#4505) * chore: added collection methods for module and collection service * Create fresh-islands-teach.md * chore: move retrieve entity to utils package * chore: make products optional in DTO type --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * feat(product): Apply transaction decorators to the services (#4512) --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
co-authored by
Oliver Windall Juhl
Riqwan Thamir
Carlos R. L. Rodrigues
parent
5b91a3503a
commit
befc2f1c80
@@ -6,24 +6,21 @@ import {
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { MedusaError, ModulesSdkUtils } from "@medusajs/utils"
|
||||
|
||||
import { EntitySchema } from "@mikro-orm/core"
|
||||
|
||||
import * as ProductModels from "@models"
|
||||
import {
|
||||
ProductServiceInitializeCustomDataLayerOptions,
|
||||
ProductServiceInitializeOptions,
|
||||
} from "../types"
|
||||
import { createConnection, loadDatabaseConfig } from "../utils"
|
||||
import { createConnection } from "../utils"
|
||||
import { ModulesSdkTypes } from "@medusajs/types"
|
||||
|
||||
export default async (
|
||||
{
|
||||
options,
|
||||
container,
|
||||
}: LoaderOptions<
|
||||
| ProductServiceInitializeOptions
|
||||
| ProductServiceInitializeCustomDataLayerOptions
|
||||
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||
>,
|
||||
moduleDeclaration?: InternalModuleDeclaration
|
||||
): Promise<void> => {
|
||||
@@ -35,11 +32,11 @@ export default async (
|
||||
}
|
||||
|
||||
const customManager = (
|
||||
options as ProductServiceInitializeCustomDataLayerOptions
|
||||
options as ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||
)?.manager
|
||||
|
||||
if (!customManager) {
|
||||
const dbData = loadDatabaseConfig(options)
|
||||
const dbData = ModulesSdkUtils.loadDatabaseConfig("product", options)
|
||||
await loadDefault({ database: dbData, container })
|
||||
} else {
|
||||
container.register({
|
||||
|
||||
@@ -3,36 +3,39 @@ import { LoaderOptions } from "@medusajs/modules-sdk"
|
||||
import { asClass } from "awilix"
|
||||
import {
|
||||
ProductCategoryService,
|
||||
ProductCollectionService,
|
||||
ProductImageService,
|
||||
ProductModuleService,
|
||||
ProductOptionService,
|
||||
ProductService,
|
||||
ProductTagService,
|
||||
ProductTypeService,
|
||||
ProductVariantService,
|
||||
ProductCollectionService,
|
||||
} from "@services"
|
||||
import * as DefaultRepositories from "@repositories"
|
||||
import {
|
||||
BaseRepository,
|
||||
ProductCategoryRepository,
|
||||
ProductCollectionRepository,
|
||||
ProductImageRepository,
|
||||
ProductOptionRepository,
|
||||
ProductRepository,
|
||||
ProductTagRepository,
|
||||
ProductTypeRepository,
|
||||
ProductVariantRepository,
|
||||
} from "@repositories"
|
||||
import {
|
||||
ProductServiceInitializeCustomDataLayerOptions,
|
||||
ProductServiceInitializeOptions,
|
||||
} from "../types"
|
||||
import { Constructor, DAL } from "@medusajs/types"
|
||||
import { Constructor, DAL, ModulesSdkTypes } from "@medusajs/types"
|
||||
import { lowerCaseFirst } from "@medusajs/utils"
|
||||
|
||||
export default async ({
|
||||
container,
|
||||
options,
|
||||
}: LoaderOptions<
|
||||
| ProductServiceInitializeOptions
|
||||
| ProductServiceInitializeCustomDataLayerOptions
|
||||
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||
>): Promise<void> => {
|
||||
const customRepositories = (
|
||||
options as ProductServiceInitializeCustomDataLayerOptions
|
||||
options as ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||
)?.repositories
|
||||
|
||||
container.register({
|
||||
@@ -42,6 +45,9 @@ export default async ({
|
||||
productVariantService: asClass(ProductVariantService).singleton(),
|
||||
productTagService: asClass(ProductTagService).singleton(),
|
||||
productCollectionService: asClass(ProductCollectionService).singleton(),
|
||||
productImageService: asClass(ProductImageService).singleton(),
|
||||
productTypeService: asClass(ProductTypeService).singleton(),
|
||||
productOptionService: asClass(ProductOptionService).singleton(),
|
||||
})
|
||||
|
||||
if (customRepositories) {
|
||||
@@ -53,13 +59,17 @@ export default async ({
|
||||
|
||||
function loadDefaultRepositories({ container }) {
|
||||
container.register({
|
||||
productRepository: asClass(ProductRepository).singleton(),
|
||||
productVariantRepository: asClass(ProductVariantRepository).singleton(),
|
||||
productTagRepository: asClass(ProductTagRepository).singleton(),
|
||||
baseRepository: asClass(BaseRepository).singleton(),
|
||||
productImageRepository: asClass(ProductImageRepository).singleton(),
|
||||
productCategoryRepository: asClass(ProductCategoryRepository).singleton(),
|
||||
productCollectionRepository: asClass(
|
||||
ProductCollectionRepository
|
||||
).singleton(),
|
||||
productRepository: asClass(ProductRepository).singleton(),
|
||||
productTagRepository: asClass(ProductTagRepository).singleton(),
|
||||
productTypeRepository: asClass(ProductTypeRepository).singleton(),
|
||||
productOptionRepository: asClass(ProductOptionRepository).singleton(),
|
||||
productVariantRepository: asClass(ProductVariantRepository).singleton(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user