diff --git a/www/apps/docs/content/plugins/cms/contentful.md b/www/apps/docs/content/plugins/cms/contentful.md index 6855cae066b72..6178a4ec8162b 100644 --- a/www/apps/docs/content/plugins/cms/contentful.md +++ b/www/apps/docs/content/plugins/cms/contentful.md @@ -310,28 +310,28 @@ Create the file `src/loaders/contentful-migrations/product-collection.ts` with t ```ts title=src/loaders/contentful-migrations/product-collection.ts import Migration, { - MigrationContext -} from "contentful-migration"; + MigrationContext, +} from "contentful-migration" -export function productCollectionMigration ( +export function productCollectionMigration( migration: Migration, context?: MigrationContext ) { const collection = migration .createContentType("collection") .name("Product Collection") - .displayField("title"); + .displayField("title") collection .createField("title") .name("Title") .type("Symbol") - .required(true); + .required(true) collection .createField("medusaId") .name("Medusa ID") - .type("Symbol"); -}; + .type("Symbol") +} ``` @@ -344,28 +344,28 @@ Create the file `src/loaders/contentful-migrations/product-type.ts` with the fol ```ts title=src/loaders/contentful-migrations/product-type.ts import Migration, { - MigrationContext -} from "contentful-migration"; + MigrationContext, +} from "contentful-migration" -export function productTypeMigration ( +export function productTypeMigration( migration: Migration, context?: MigrationContext ) { const collection = migration .createContentType("productType") .name("Product Type") - .displayField("title"); + .displayField("title") collection .createField("title") .name("Title") .type("Symbol") - .required(true); + .required(true) collection .createField("medusaId") .name("Medusa ID") - .type("Symbol"); -}; + .type("Symbol") +} ``` diff --git a/www/apps/docs/content/recipes/digital-products.mdx b/www/apps/docs/content/recipes/digital-products.mdx index 7ae1f221c4a82..263e30be75e9a 100644 --- a/www/apps/docs/content/recipes/digital-products.mdx +++ b/www/apps/docs/content/recipes/digital-products.mdx @@ -284,26 +284,18 @@ import { TransactionBaseService, buildQuery, } from "@medusajs/medusa" -import { - ProductMediaRepository, -} from "../repositories/product-media" import { ProductMedia } from "../models/product-media" import { MedusaError } from "@medusajs/utils" type InjectedDependencies = { - productMediaRepository: typeof ProductMediaRepository productVariantService: ProductVariantService } class ProductMediaService extends TransactionBaseService { - protected productMediaRepository_: - typeof ProductMediaRepository protected productVariantService_: ProductVariantService constructor(container: InjectedDependencies) { super(container) - this.productMediaRepository_ = - container.productMediaRepository this.productVariantService_ = container.productVariantService } @@ -328,12 +320,12 @@ class ProductMediaService extends TransactionBaseService { relations: [], } ): Promise<[ProductMedia[], number]> { - const productMediaRepo = this.activeManager_.withRepository( - this.productMediaRepository_ + const productMediaRepo = this.activeManager_.getRepository( + ProductMedia ) const [ - relations, + relations, isVariantsEnabled, ] = this.checkVariantInRelations( config.relations || [] @@ -354,8 +346,7 @@ class ProductMediaService extends TransactionBaseService { async (media, index) => { productMedias[index].variant = await this.retrieveVariantByMedia(media) - }) - ) + })) } return [productMedias, count] @@ -370,9 +361,8 @@ class ProductMediaService extends TransactionBaseService { } ): Promise { const [productMedias] = await this.listAndCount( - selector, - config - ) + selector, config + ) return productMedias } @@ -381,10 +371,9 @@ class ProductMediaService extends TransactionBaseService { id: string, config?: FindConfig ): Promise { - const productMediaRepo = - this.activeManager_.withRepository( - this.productMediaRepository_ - ) + const productMediaRepo = this.activeManager_.getRepository( + ProductMedia + ) const query = buildQuery({ id, @@ -400,8 +389,9 @@ class ProductMediaService extends TransactionBaseService { } if (config.relations.includes("variant")) { - productMedia.variant = - await this.retrieveVariantByMedia(productMedia) + productMedia.variant = await this.retrieveVariantByMedia( + productMedia + ) } return productMedia @@ -409,7 +399,8 @@ class ProductMediaService extends TransactionBaseService { async retrieveVariantByMedia(productMedia: ProductMedia) { return await this.productVariantService_.retrieve( - productMedia.variant_id, { + productMedia.variant_id, + { relations: ["product"], } ) @@ -417,13 +408,12 @@ class ProductMediaService extends TransactionBaseService { async create( data: Pick< - ProductMedia, - "name" | "file_key" | "variant_id" | "type" + ProductMedia, "name" | "file_key" | "variant_id" | "type" > ): Promise { return this.atomicPhase_(async (manager) => { - const productMediaRepo = manager.withRepository( - this.productMediaRepository_ + const productMediaRepo = manager.getRepository( + ProductMedia ) const productMedia = productMediaRepo.create(data) const result = await productMediaRepo.save(productMedia) @@ -437,8 +427,8 @@ class ProductMediaService extends TransactionBaseService { data: Omit, "id"> ): Promise { return await this.atomicPhase_(async (manager) => { - const productMediaRepo = manager.withRepository( - this.productMediaRepository_ + const productMediaRepo = manager.getRepository( + ProductMedia ) const productMedia = await this.retrieve(id) @@ -450,8 +440,8 @@ class ProductMediaService extends TransactionBaseService { async delete(id: string): Promise { return await this.atomicPhase_(async (manager) => { - const productMediaRepo = manager.withRepository( - this.productMediaRepository_ + const productMediaRepo = manager.getRepository( + ProductMedia ) const productMedia = await this.retrieve(id)