docs: fix usage of non-existing repository in digital products recipe (#5280)
* docs: fix usage of non-existing repository in digital products recipe * fix content linting
This commit is contained in:
@@ -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")
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
@@ -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<ProductMedia[]> {
|
||||
const [productMedias] = await this.listAndCount(
|
||||
selector,
|
||||
config
|
||||
)
|
||||
selector, config
|
||||
)
|
||||
|
||||
return productMedias
|
||||
}
|
||||
@@ -381,10 +371,9 @@ class ProductMediaService extends TransactionBaseService {
|
||||
id: string,
|
||||
config?: FindConfig<ProductMedia>
|
||||
): Promise<ProductMedia> {
|
||||
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<ProductMedia> {
|
||||
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<Partial<ProductMedia>, "id">
|
||||
): Promise<ProductMedia> {
|
||||
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<void> {
|
||||
return await this.atomicPhase_(async (manager) => {
|
||||
const productMediaRepo = manager.withRepository(
|
||||
this.productMediaRepository_
|
||||
const productMediaRepo = manager.getRepository(
|
||||
ProductMedia
|
||||
)
|
||||
const productMedia = await this.retrieve(id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user