Skip to content

Commit

Permalink
chore(medusa): Crud service accept an entity name
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Aug 11, 2022
1 parent 5df587a commit 41b190e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions packages/medusa/src/interfaces/transaction-crud-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export abstract class TransactionCrudService<
> extends TransactionBaseService<TChild> {
protected constructor(
protected readonly __repo__: ObjectType<Repository<TEntity>>,
protected readonly __entityName__: string,
container: unknown,
config?: Record<string, unknown>
) {
Expand Down Expand Up @@ -65,14 +66,9 @@ export abstract class TransactionCrudService<
const entity = await repo.findOne(query)

if (!entity) {
const entityName = repo.metadata.targetName
.replace(/([A-Z])/g, " $1")
.replace(/^./, function (str) {
return str.toUpperCase()
})
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`${entityName} with ${id} was not found`
`${this.__entityName__} with ${id} was not found`
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/services/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class CartService extends TransactionCrudService<
storeService,
}: InjectedDependencies) {
// eslint-disable-next-line prefer-rest-params
super(cartRepository, arguments[0])
super(cartRepository, "Cart", arguments[0])

this.manager_ = manager
this.shippingMethodRepository_ = shippingMethodRepository
Expand Down

0 comments on commit 41b190e

Please sign in to comment.