feat(medusa): Validate required id before retrieving (#2738)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore(medusa): Validate required id in `[someService].retrieve`
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from "../types/batch-job"
|
} from "../types/batch-job"
|
||||||
import { FindConfig } from "../types/common"
|
import { FindConfig } from "../types/common"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery, isDefined } from "../utils"
|
||||||
import { MedusaError } from "medusa-core-utils"
|
import { MedusaError } from "medusa-core-utils"
|
||||||
import { EventBusService, StrategyResolverService } from "./index"
|
import { EventBusService, StrategyResolverService } from "./index"
|
||||||
import { Request } from "express"
|
import { Request } from "express"
|
||||||
@@ -109,6 +109,13 @@ class BatchJobService extends TransactionBaseService {
|
|||||||
batchJobId: string,
|
batchJobId: string,
|
||||||
config: FindConfig<BatchJob> = {}
|
config: FindConfig<BatchJob> = {}
|
||||||
): Promise<BatchJob | never> {
|
): Promise<BatchJob | never> {
|
||||||
|
if (!isDefined(batchJobId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"batchJobId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const batchJobRepo = manager.getCustomRepository(this.batchJobRepository_)
|
const batchJobRepo = manager.getCustomRepository(this.batchJobRepository_)
|
||||||
|
|
||||||
|
|||||||
@@ -214,6 +214,13 @@ class CartService extends TransactionBaseService {
|
|||||||
options: FindConfig<Cart> = {},
|
options: FindConfig<Cart> = {},
|
||||||
totalsConfig: TotalsConfig = {}
|
totalsConfig: TotalsConfig = {}
|
||||||
): Promise<Cart> {
|
): Promise<Cart> {
|
||||||
|
if (!isDefined(cartId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"cartId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const { totalsToSelect } = this.transformQueryForTotals_(options)
|
const { totalsToSelect } = this.transformQueryForTotals_(options)
|
||||||
|
|
||||||
if (totalsToSelect.length) {
|
if (totalsToSelect.length) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { ClaimItemRepository } from "../repositories/claim-item"
|
|||||||
import { ClaimTagRepository } from "../repositories/claim-tag"
|
import { ClaimTagRepository } from "../repositories/claim-tag"
|
||||||
import { CreateClaimItemInput } from "../types/claim"
|
import { CreateClaimItemInput } from "../types/claim"
|
||||||
import { FindConfig, Selector } from "../types/common"
|
import { FindConfig, Selector } from "../types/common"
|
||||||
import { buildQuery, setMetadata } from "../utils"
|
import { buildQuery, isDefined, setMetadata } from "../utils"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
import LineItemService from "./line-item"
|
import LineItemService from "./line-item"
|
||||||
|
|
||||||
@@ -226,24 +226,31 @@ class ClaimItemService extends TransactionBaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a claim item by id.
|
* Gets a claim item by id.
|
||||||
* @param {string} id - id of ClaimItem to retrieve
|
* @param {string} claimItemId - id of ClaimItem to retrieve
|
||||||
* @param {Object} config - configuration for the find operation
|
* @param {Object} config - configuration for the find operation
|
||||||
* @return {Promise<Order>} the ClaimItem
|
* @return {Promise<Order>} the ClaimItem
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
claimItemId: string,
|
||||||
config: FindConfig<ClaimItem> = {}
|
config: FindConfig<ClaimItem> = {}
|
||||||
): Promise<ClaimItem> {
|
): Promise<ClaimItem> {
|
||||||
|
if (!isDefined(claimItemId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"claimItemId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const claimItemRepo = this.manager_.getCustomRepository(
|
const claimItemRepo = this.manager_.getCustomRepository(
|
||||||
this.claimItemRepository_
|
this.claimItemRepository_
|
||||||
)
|
)
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: claimItemId }, config)
|
||||||
const item = await claimItemRepo.findOne(query)
|
const item = await claimItemRepo.findOne(query)
|
||||||
|
|
||||||
if (!item) {
|
if (!item) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Claim item with id: ${id} was not found.`
|
`Claim item with id: ${claimItemId} was not found.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -830,24 +830,31 @@ export default class ClaimService extends TransactionBaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an order by id.
|
* Gets an order by id.
|
||||||
* @param id - id of the claim order to retrieve
|
* @param claimId - id of the claim order to retrieve
|
||||||
* @param config - the config object containing query settings
|
* @param config - the config object containing query settings
|
||||||
* @return the order document
|
* @return the order document
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
claimId: string,
|
||||||
config: FindConfig<ClaimOrder> = {}
|
config: FindConfig<ClaimOrder> = {}
|
||||||
): Promise<ClaimOrder> {
|
): Promise<ClaimOrder> {
|
||||||
|
if (!isDefined(claimId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"claimId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const claimRepo = manager.getCustomRepository(this.claimRepository_)
|
const claimRepo = manager.getCustomRepository(this.claimRepository_)
|
||||||
|
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: claimId }, config)
|
||||||
const claim = await claimRepo.findOne(query)
|
const claim = await claimRepo.findOne(query)
|
||||||
|
|
||||||
if (!claim) {
|
if (!claim) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Claim with ${id} was not found`
|
`Claim with ${claimId} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,18 +42,25 @@ class CustomerGroupService extends TransactionBaseService {
|
|||||||
this.customerService_ = customerService
|
this.customerService_ = customerService
|
||||||
}
|
}
|
||||||
|
|
||||||
async retrieve(id: string, config = {}): Promise<CustomerGroup> {
|
async retrieve(customerGroupId: string, config = {}): Promise<CustomerGroup> {
|
||||||
|
if (!isDefined(customerGroupId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"customerGroupId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const cgRepo = this.manager_.getCustomRepository(
|
const cgRepo = this.manager_.getCustomRepository(
|
||||||
this.customerGroupRepository_
|
this.customerGroupRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: customerGroupId }, config)
|
||||||
|
|
||||||
const customerGroup = await cgRepo.findOne(query)
|
const customerGroup = await cgRepo.findOne(query)
|
||||||
if (!customerGroup) {
|
if (!customerGroup) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`CustomerGroup with id ${id} was not found`
|
`CustomerGroup with id ${customerGroupId} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -196,6 +196,13 @@ class CustomerService extends TransactionBaseService {
|
|||||||
email: string,
|
email: string,
|
||||||
config: FindConfig<Customer> = {}
|
config: FindConfig<Customer> = {}
|
||||||
): Promise<Customer | never> {
|
): Promise<Customer | never> {
|
||||||
|
if (!isDefined(email)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"email" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ email: email.toLowerCase() }, config)
|
return await this.retrieve_({ email: email.toLowerCase() }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,6 +254,13 @@ class CustomerService extends TransactionBaseService {
|
|||||||
customerId: string,
|
customerId: string,
|
||||||
config: FindConfig<Customer> = {}
|
config: FindConfig<Customer> = {}
|
||||||
): Promise<Customer> {
|
): Promise<Customer> {
|
||||||
|
if (!isDefined(customerId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"customerId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return this.retrieve_({ id: customerId }, config)
|
return this.retrieve_({ id: customerId }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { DiscountConditionRepository } from "../repositories/discount-condition"
|
|||||||
import { FindConfig } from "../types/common"
|
import { FindConfig } from "../types/common"
|
||||||
import { DiscountConditionInput } from "../types/discount"
|
import { DiscountConditionInput } from "../types/discount"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import { buildQuery, PostgresError } from "../utils"
|
import { buildQuery, isDefined, PostgresError } from "../utils"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
@@ -50,6 +50,13 @@ class DiscountConditionService extends TransactionBaseService {
|
|||||||
conditionId: string,
|
conditionId: string,
|
||||||
config?: FindConfig<DiscountCondition>
|
config?: FindConfig<DiscountCondition>
|
||||||
): Promise<DiscountCondition | never> {
|
): Promise<DiscountCondition | never> {
|
||||||
|
if (!isDefined(conditionId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"conditionId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const conditionRepo = manager.getCustomRepository(
|
const conditionRepo = manager.getCustomRepository(
|
||||||
this.discountConditionRepository_
|
this.discountConditionRepository_
|
||||||
@@ -108,7 +115,7 @@ class DiscountConditionService extends TransactionBaseService {
|
|||||||
|
|
||||||
async upsertCondition(
|
async upsertCondition(
|
||||||
data: DiscountConditionInput,
|
data: DiscountConditionInput,
|
||||||
overrideExisting: boolean = true
|
overrideExisting = true
|
||||||
): Promise<
|
): Promise<
|
||||||
(
|
(
|
||||||
| DiscountConditionProduct
|
| DiscountConditionProduct
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import {
|
|||||||
UpdateDiscountInput,
|
UpdateDiscountInput,
|
||||||
UpdateDiscountRuleInput,
|
UpdateDiscountRuleInput,
|
||||||
} from "../types/discount"
|
} from "../types/discount"
|
||||||
import { buildQuery, setMetadata } from "../utils"
|
import { buildQuery, isDefined, setMetadata } from "../utils"
|
||||||
import { isFuture, isPast } from "../utils/date-helpers"
|
import { isFuture, isPast } from "../utils/date-helpers"
|
||||||
import { FlagRouter } from "../utils/flag-router"
|
import { FlagRouter } from "../utils/flag-router"
|
||||||
import CustomerService from "./customer"
|
import CustomerService from "./customer"
|
||||||
@@ -253,6 +253,13 @@ class DiscountService extends TransactionBaseService {
|
|||||||
discountId: string,
|
discountId: string,
|
||||||
config: FindConfig<Discount> = {}
|
config: FindConfig<Discount> = {}
|
||||||
): Promise<Discount> {
|
): Promise<Discount> {
|
||||||
|
if (!isDefined(discountId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"discountId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const discountRepo = manager.getCustomRepository(this.discountRepository_)
|
const discountRepo = manager.getCustomRepository(this.discountRepository_)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { OrderRepository } from "../repositories/order"
|
|||||||
import { PaymentRepository } from "../repositories/payment"
|
import { PaymentRepository } from "../repositories/payment"
|
||||||
import { ExtendedFindConfig, FindConfig } from "../types/common"
|
import { ExtendedFindConfig, FindConfig } from "../types/common"
|
||||||
import { DraftOrderCreateProps } from "../types/draft-orders"
|
import { DraftOrderCreateProps } from "../types/draft-orders"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery, isDefined } from "../utils"
|
||||||
import CartService from "./cart"
|
import CartService from "./cart"
|
||||||
import CustomShippingOptionService from "./custom-shipping-option"
|
import CustomShippingOptionService from "./custom-shipping-option"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
@@ -80,25 +80,32 @@ class DraftOrderService extends TransactionBaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a draft order with the given id.
|
* Retrieves a draft order with the given id.
|
||||||
* @param id - id of the draft order to retrieve
|
* @param draftOrderId - id of the draft order to retrieve
|
||||||
* @param config - query object for findOne
|
* @param config - query object for findOne
|
||||||
* @return the draft order
|
* @return the draft order
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
draftOrderId: string,
|
||||||
config: FindConfig<DraftOrder> = {}
|
config: FindConfig<DraftOrder> = {}
|
||||||
): Promise<DraftOrder | never> {
|
): Promise<DraftOrder | never> {
|
||||||
|
if (!isDefined(draftOrderId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"draftOrderId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const draftOrderRepo = manager.getCustomRepository(
|
const draftOrderRepo = manager.getCustomRepository(
|
||||||
this.draftOrderRepository_
|
this.draftOrderRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: draftOrderId }, config)
|
||||||
const draftOrder = await draftOrderRepo.findOne(query)
|
const draftOrder = await draftOrderRepo.findOne(query)
|
||||||
if (!draftOrder) {
|
if (!draftOrder) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Draft order with ${id} was not found`
|
`Draft order with ${draftOrderId} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -159,27 +159,34 @@ class FulfillmentService extends TransactionBaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a fulfillment by its id.
|
* Retrieves a fulfillment by its id.
|
||||||
* @param id - the id of the fulfillment to retrieve
|
* @param fulfillmentId - the id of the fulfillment to retrieve
|
||||||
* @param config - optional values to include with fulfillmentRepository query
|
* @param config - optional values to include with fulfillmentRepository query
|
||||||
* @return the fulfillment
|
* @return the fulfillment
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
fulfillmentId: string,
|
||||||
config: FindConfig<Fulfillment> = {}
|
config: FindConfig<Fulfillment> = {}
|
||||||
): Promise<Fulfillment> {
|
): Promise<Fulfillment> {
|
||||||
|
if (!isDefined(fulfillmentId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"fulfillmentId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const fulfillmentRepository = manager.getCustomRepository(
|
const fulfillmentRepository = manager.getCustomRepository(
|
||||||
this.fulfillmentRepository_
|
this.fulfillmentRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: fulfillmentId }, config)
|
||||||
|
|
||||||
const fulfillment = await fulfillmentRepository.findOne(query)
|
const fulfillment = await fulfillmentRepository.findOne(query)
|
||||||
|
|
||||||
if (!fulfillment) {
|
if (!fulfillment) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Fulfillment with id: ${id} was not found`
|
`Fulfillment with id: ${fulfillmentId} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return fulfillment
|
return fulfillment
|
||||||
|
|||||||
@@ -218,6 +218,13 @@ class GiftCardService extends TransactionBaseService {
|
|||||||
giftCardId: string,
|
giftCardId: string,
|
||||||
config: FindConfig<GiftCard> = {}
|
config: FindConfig<GiftCard> = {}
|
||||||
): Promise<GiftCard> {
|
): Promise<GiftCard> {
|
||||||
|
if (!isDefined(giftCardId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"giftCardId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ id: giftCardId }, config)
|
return await this.retrieve_({ id: giftCardId }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +232,13 @@ class GiftCardService extends TransactionBaseService {
|
|||||||
code: string,
|
code: string,
|
||||||
config: FindConfig<GiftCard> = {}
|
config: FindConfig<GiftCard> = {}
|
||||||
): Promise<GiftCard> {
|
): Promise<GiftCard> {
|
||||||
|
if (!isDefined(code)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"code" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ code }, config)
|
return await this.retrieve_({ code }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
CreateIdempotencyKeyInput,
|
CreateIdempotencyKeyInput,
|
||||||
IdempotencyCallbackResult,
|
IdempotencyCallbackResult,
|
||||||
} from "../types/idempotency-key"
|
} from "../types/idempotency-key"
|
||||||
|
import { isDefined } from "../utils"
|
||||||
|
|
||||||
const KEY_LOCKED_TIMEOUT = 1000
|
const KEY_LOCKED_TIMEOUT = 1000
|
||||||
|
|
||||||
@@ -83,6 +84,13 @@ class IdempotencyKeyService extends TransactionBaseService {
|
|||||||
* @return idempotency key
|
* @return idempotency key
|
||||||
*/
|
*/
|
||||||
async retrieve(idempotencyKey: string): Promise<IdempotencyKey | never> {
|
async retrieve(idempotencyKey: string): Promise<IdempotencyKey | never> {
|
||||||
|
if (!isDefined(idempotencyKey)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"idempotencyKey" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const idempotencyKeyRepo = this.manager_.getCustomRepository(
|
const idempotencyKeyRepo = this.manager_.getCustomRepository(
|
||||||
this.idempotencyKeyRepository_
|
this.idempotencyKeyRepository_
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { FindConfig } from "../types/common"
|
|||||||
import { FilterableLineItemAdjustmentProps } from "../types/line-item-adjustment"
|
import { FilterableLineItemAdjustmentProps } from "../types/line-item-adjustment"
|
||||||
import DiscountService from "./discount"
|
import DiscountService from "./discount"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import { buildQuery, setMetadata } from "../utils"
|
import { buildQuery, isDefined, setMetadata } from "../utils"
|
||||||
import { CalculationContextData } from "../types/totals"
|
import { CalculationContextData } from "../types/totals"
|
||||||
|
|
||||||
type LineItemAdjustmentServiceProps = {
|
type LineItemAdjustmentServiceProps = {
|
||||||
@@ -51,24 +51,31 @@ class LineItemAdjustmentService extends TransactionBaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a line item adjustment by id.
|
* Retrieves a line item adjustment by id.
|
||||||
* @param id - the id of the line item adjustment to retrieve
|
* @param lineItemAdjustmentId - the id of the line item adjustment to retrieve
|
||||||
* @param config - the config to retrieve the line item adjustment by
|
* @param config - the config to retrieve the line item adjustment by
|
||||||
* @return the line item adjustment.
|
* @return the line item adjustment.
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
lineItemAdjustmentId: string,
|
||||||
config: FindConfig<LineItemAdjustment> = {}
|
config: FindConfig<LineItemAdjustment> = {}
|
||||||
): Promise<LineItemAdjustment> {
|
): Promise<LineItemAdjustment> {
|
||||||
|
if (!isDefined(lineItemAdjustmentId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"lineItemAdjustmentId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const lineItemAdjustmentRepo: LineItemAdjustmentRepository =
|
const lineItemAdjustmentRepo: LineItemAdjustmentRepository =
|
||||||
this.manager_.getCustomRepository(this.lineItemAdjustmentRepo_)
|
this.manager_.getCustomRepository(this.lineItemAdjustmentRepo_)
|
||||||
|
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: lineItemAdjustmentId }, config)
|
||||||
const lineItemAdjustment = await lineItemAdjustmentRepo.findOne(query)
|
const lineItemAdjustment = await lineItemAdjustmentRepo.findOne(query)
|
||||||
|
|
||||||
if (!lineItemAdjustment) {
|
if (!lineItemAdjustment) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Line item adjustment with id: ${id} was not found`
|
`Line item adjustment with id: ${lineItemAdjustmentId} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { NoteRepository } from "../repositories/note"
|
|||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
import { FindConfig, Selector } from "../types/common"
|
import { FindConfig, Selector } from "../types/common"
|
||||||
import { Note } from "../models"
|
import { Note } from "../models"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery, isDefined } from "../utils"
|
||||||
import { CreateNoteInput } from "../types/note"
|
import { CreateNoteInput } from "../types/note"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -40,24 +40,31 @@ class NoteService extends TransactionBaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a specific note.
|
* Retrieves a specific note.
|
||||||
* @param id - the id of the note to retrieve.
|
* @param noteId - the id of the note to retrieve.
|
||||||
* @param config - any options needed to query for the result.
|
* @param config - any options needed to query for the result.
|
||||||
* @return which resolves to the requested note.
|
* @return which resolves to the requested note.
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
noteId: string,
|
||||||
config: FindConfig<Note> = {}
|
config: FindConfig<Note> = {}
|
||||||
): Promise<Note | never> {
|
): Promise<Note | never> {
|
||||||
|
if (!isDefined(noteId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"noteId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const noteRepo = this.manager_.getCustomRepository(this.noteRepository_)
|
const noteRepo = this.manager_.getCustomRepository(this.noteRepository_)
|
||||||
|
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: noteId }, config)
|
||||||
|
|
||||||
const note = await noteRepo.findOne(query)
|
const note = await noteRepo.findOne(query)
|
||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Note with id: ${id} was not found.`
|
`Note with id: ${noteId} was not found.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { OauthRepository } from "../repositories/oauth"
|
|||||||
import { Selector } from "../types/common"
|
import { Selector } from "../types/common"
|
||||||
import { MedusaContainer } from "../types/global"
|
import { MedusaContainer } from "../types/global"
|
||||||
import { CreateOauthInput, UpdateOauthInput } from "../types/oauth"
|
import { CreateOauthInput, UpdateOauthInput } from "../types/oauth"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery, isDefined } from "../utils"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
|
|
||||||
type InjectedDependencies = MedusaContainer & {
|
type InjectedDependencies = MedusaContainer & {
|
||||||
@@ -55,6 +55,13 @@ class Oauth extends TransactionBaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async retrieve(oauthId: string): Promise<OAuthModel> {
|
async retrieve(oauthId: string): Promise<OAuthModel> {
|
||||||
|
if (!isDefined(oauthId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"oauthId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const repo = this.manager.getCustomRepository(this.oauthRepository_)
|
const repo = this.manager.getCustomRepository(this.oauthRepository_)
|
||||||
const oauth = await repo.findOne({
|
const oauth = await repo.findOne({
|
||||||
id: oauthId,
|
id: oauthId,
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ export default class OrderEditService extends TransactionBaseService {
|
|||||||
orderEditId: string,
|
orderEditId: string,
|
||||||
config: FindConfig<OrderEdit> = {}
|
config: FindConfig<OrderEdit> = {}
|
||||||
): Promise<OrderEdit> {
|
): Promise<OrderEdit> {
|
||||||
|
if (!isDefined(orderEditId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"orderEditId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.transactionManager_ ?? this.manager_
|
const manager = this.transactionManager_ ?? this.manager_
|
||||||
const orderEditRepository = manager.getCustomRepository(
|
const orderEditRepository = manager.getCustomRepository(
|
||||||
this.orderEditRepository_
|
this.orderEditRepository_
|
||||||
|
|||||||
@@ -336,6 +336,13 @@ class OrderService extends TransactionBaseService {
|
|||||||
orderId: string,
|
orderId: string,
|
||||||
config: FindConfig<Order> = {}
|
config: FindConfig<Order> = {}
|
||||||
): Promise<Order> {
|
): Promise<Order> {
|
||||||
|
if (!isDefined(orderId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"orderId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const { totalsToSelect } = this.transformQueryForTotals(config)
|
const { totalsToSelect } = this.transformQueryForTotals(config)
|
||||||
|
|
||||||
if (totalsToSelect?.length) {
|
if (totalsToSelect?.length) {
|
||||||
@@ -701,7 +708,7 @@ class OrderService extends TransactionBaseService {
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
cart.shipping_methods.map((method) => {
|
cart.shipping_methods.map(async (method) => {
|
||||||
// TODO: Due to cascade insert we have to remove the tax_lines that have been added by the cart decorate totals.
|
// TODO: Due to cascade insert we have to remove the tax_lines that have been added by the cart decorate totals.
|
||||||
// Is the cascade insert really used? Also, is it really necessary to pass the entire entities when creating or updating?
|
// Is the cascade insert really used? Also, is it really necessary to pass the entire entities when creating or updating?
|
||||||
// We normally should only pass what is needed?
|
// We normally should only pass what is needed?
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ export default class PaymentCollectionService extends TransactionBaseService {
|
|||||||
paymentCollectionId: string,
|
paymentCollectionId: string,
|
||||||
config: FindConfig<PaymentCollection> = {}
|
config: FindConfig<PaymentCollection> = {}
|
||||||
): Promise<PaymentCollection> {
|
): Promise<PaymentCollection> {
|
||||||
|
if (!isDefined(paymentCollectionId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"paymentCollectionId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.transactionManager_ ?? this.manager_
|
const manager = this.transactionManager_ ?? this.manager_
|
||||||
const paymentCollectionRepository = manager.getCustomRepository(
|
const paymentCollectionRepository = manager.getCustomRepository(
|
||||||
this.paymentCollectionRepository_
|
this.paymentCollectionRepository_
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { MedusaError } from "medusa-core-utils"
|
|||||||
import { Payment, Refund } from "../models"
|
import { Payment, Refund } from "../models"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import { EventBusService, PaymentProviderService } from "./index"
|
import { EventBusService, PaymentProviderService } from "./index"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery, isDefined } from "../utils"
|
||||||
import { FindConfig } from "../types/common"
|
import { FindConfig } from "../types/common"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -62,6 +62,13 @@ export default class PaymentService extends TransactionBaseService {
|
|||||||
paymentId: string,
|
paymentId: string,
|
||||||
config: FindConfig<Payment> = {}
|
config: FindConfig<Payment> = {}
|
||||||
): Promise<Payment> {
|
): Promise<Payment> {
|
||||||
|
if (!isDefined(paymentId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"paymentId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.transactionManager_ ?? this.manager_
|
const manager = this.transactionManager_ ?? this.manager_
|
||||||
const paymentRepository = manager.getCustomRepository(
|
const paymentRepository = manager.getCustomRepository(
|
||||||
this.paymentRepository_
|
this.paymentRepository_
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
import ProductService from "./product"
|
import ProductService from "./product"
|
||||||
import RegionService from "./region"
|
import RegionService from "./region"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery, isDefined } from "../utils"
|
||||||
import { FilterableProductProps } from "../types/product"
|
import { FilterableProductProps } from "../types/product"
|
||||||
import ProductVariantService from "./product-variant"
|
import ProductVariantService from "./product-variant"
|
||||||
import { FilterableProductVariantProps } from "../types/product-variant"
|
import { FilterableProductVariantProps } from "../types/product-variant"
|
||||||
@@ -89,6 +89,13 @@ class PriceListService extends TransactionBaseService {
|
|||||||
priceListId: string,
|
priceListId: string,
|
||||||
config: FindConfig<PriceList> = {}
|
config: FindConfig<PriceList> = {}
|
||||||
): Promise<PriceList> {
|
): Promise<PriceList> {
|
||||||
|
if (!isDefined(priceListId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"priceListId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const priceListRepo = this.manager_.getCustomRepository(this.priceListRepo_)
|
const priceListRepo = this.manager_.getCustomRepository(this.priceListRepo_)
|
||||||
|
|
||||||
const query = buildQuery({ id: priceListId }, config)
|
const query = buildQuery({ id: priceListId }, config)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
CreateProductCollection,
|
CreateProductCollection,
|
||||||
UpdateProductCollection,
|
UpdateProductCollection,
|
||||||
} from "../types/product-collection"
|
} from "../types/product-collection"
|
||||||
import { buildQuery, isString, setMetadata } from "../utils"
|
import { buildQuery, isDefined, isString, setMetadata } from "../utils"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -55,6 +55,13 @@ class ProductCollectionService extends TransactionBaseService {
|
|||||||
collectionId: string,
|
collectionId: string,
|
||||||
config: FindConfig<ProductCollection> = {}
|
config: FindConfig<ProductCollection> = {}
|
||||||
): Promise<ProductCollection> {
|
): Promise<ProductCollection> {
|
||||||
|
if (!isDefined(collectionId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"collectionId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const collectionRepo = this.manager_.getCustomRepository(
|
const collectionRepo = this.manager_.getCustomRepository(
|
||||||
this.productCollectionRepository_
|
this.productCollectionRepository_
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -182,6 +182,13 @@ class ProductService extends TransactionBaseService {
|
|||||||
include_discount_prices: false,
|
include_discount_prices: false,
|
||||||
}
|
}
|
||||||
): Promise<Product> {
|
): Promise<Product> {
|
||||||
|
if (!isDefined(productId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"productId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ id: productId }, config)
|
return await this.retrieve_({ id: productId }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +203,13 @@ class ProductService extends TransactionBaseService {
|
|||||||
productHandle: string,
|
productHandle: string,
|
||||||
config: FindProductConfig = {}
|
config: FindProductConfig = {}
|
||||||
): Promise<Product> {
|
): Promise<Product> {
|
||||||
|
if (!isDefined(productHandle)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"productHandle" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ handle: productHandle }, config)
|
return await this.retrieve_({ handle: productHandle }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,6 +224,13 @@ class ProductService extends TransactionBaseService {
|
|||||||
externalId: string,
|
externalId: string,
|
||||||
config: FindProductConfig = {}
|
config: FindProductConfig = {}
|
||||||
): Promise<Product> {
|
): Promise<Product> {
|
||||||
|
if (!isDefined(externalId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"externalId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ external_id: externalId }, config)
|
return await this.retrieve_({ external_id: externalId }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,13 @@ class PublishableApiKeyService extends TransactionBaseService {
|
|||||||
publishableApiKeyId: string,
|
publishableApiKeyId: string,
|
||||||
config: FindConfig<PublishableApiKey> = {}
|
config: FindConfig<PublishableApiKey> = {}
|
||||||
): Promise<PublishableApiKey | never> {
|
): Promise<PublishableApiKey | never> {
|
||||||
|
if (!isDefined(publishableApiKeyId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"publishableApiKeyId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ id: publishableApiKeyId }, config)
|
return await this.retrieve_({ id: publishableApiKeyId }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { RegionRepository } from "../repositories/region"
|
|||||||
import { TaxProviderRepository } from "../repositories/tax-provider"
|
import { TaxProviderRepository } from "../repositories/tax-provider"
|
||||||
import { FindConfig, Selector } from "../types/common"
|
import { FindConfig, Selector } from "../types/common"
|
||||||
import { CreateRegionInput, UpdateRegionInput } from "../types/region"
|
import { CreateRegionInput, UpdateRegionInput } from "../types/region"
|
||||||
import { buildQuery, setMetadata } from "../utils"
|
import { buildQuery, isDefined, setMetadata } from "../utils"
|
||||||
import { countries } from "../utils/countries"
|
import { countries } from "../utils/countries"
|
||||||
import { FlagRouter } from "../utils/flag-router"
|
import { FlagRouter } from "../utils/flag-router"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
@@ -495,6 +495,13 @@ class RegionService extends TransactionBaseService {
|
|||||||
regionId: string,
|
regionId: string,
|
||||||
config: FindConfig<Region> = {}
|
config: FindConfig<Region> = {}
|
||||||
): Promise<Region | never> {
|
): Promise<Region | never> {
|
||||||
|
if (!isDefined(regionId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"regionId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const regionRepository = this.manager_.getCustomRepository(
|
const regionRepository = this.manager_.getCustomRepository(
|
||||||
this.regionRepository_
|
this.regionRepository_
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Return, ReturnReason } from "../models"
|
|||||||
import { ReturnReasonRepository } from "../repositories/return-reason"
|
import { ReturnReasonRepository } from "../repositories/return-reason"
|
||||||
import { FindConfig, Selector } from "../types/common"
|
import { FindConfig, Selector } from "../types/common"
|
||||||
import { CreateReturnReason, UpdateReturnReason } from "../types/return-reason"
|
import { CreateReturnReason, UpdateReturnReason } from "../types/return-reason"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery, isDefined } from "../utils"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
@@ -84,23 +84,30 @@ class ReturnReasonService extends TransactionBaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an order by id.
|
* Gets an order by id.
|
||||||
* @param {string} id - id of order to retrieve
|
* @param {string} returnReasonId - id of order to retrieve
|
||||||
* @param {Object} config - config object
|
* @param {Object} config - config object
|
||||||
* @return {Promise<Order>} the order document
|
* @return {Promise<Order>} the order document
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
returnReasonId: string,
|
||||||
config: FindConfig<ReturnReason> = {}
|
config: FindConfig<ReturnReason> = {}
|
||||||
): Promise<ReturnReason | never> {
|
): Promise<ReturnReason | never> {
|
||||||
|
if (!isDefined(returnReasonId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"returnReasonId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const rrRepo = this.manager_.getCustomRepository(this.retReasonRepo_)
|
const rrRepo = this.manager_.getCustomRepository(this.retReasonRepo_)
|
||||||
|
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: returnReasonId }, config)
|
||||||
const item = await rrRepo.findOne(query)
|
const item = await rrRepo.findOne(query)
|
||||||
|
|
||||||
if (!item) {
|
if (!item) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Return Reason with id: ${id} was not found.`
|
`Return Reason with id: ${returnReasonId} was not found.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -251,26 +251,33 @@ class ReturnService extends TransactionBaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a return by its id.
|
* Retrieves a return by its id.
|
||||||
* @param id - the id of the return to retrieve
|
* @param returnId - the id of the return to retrieve
|
||||||
* @param config - the config object
|
* @param config - the config object
|
||||||
* @return the return
|
* @return the return
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
returnId: string,
|
||||||
config: FindConfig<Return> = {}
|
config: FindConfig<Return> = {}
|
||||||
): Promise<Return | never> {
|
): Promise<Return | never> {
|
||||||
|
if (!isDefined(returnId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"returnId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const returnRepository = this.manager_.getCustomRepository(
|
const returnRepository = this.manager_.getCustomRepository(
|
||||||
this.returnRepository_
|
this.returnRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: returnId }, config)
|
||||||
|
|
||||||
const returnObj = await returnRepository.findOne(query)
|
const returnObj = await returnRepository.findOne(query)
|
||||||
|
|
||||||
if (!returnObj) {
|
if (!returnObj) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Return with id: ${id} was not found`
|
`Return with id: ${returnId} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return returnObj
|
return returnObj
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { SalesChannel } from "../models"
|
|||||||
import { SalesChannelRepository } from "../repositories/sales-channel"
|
import { SalesChannelRepository } from "../repositories/sales-channel"
|
||||||
import StoreService from "./store"
|
import StoreService from "./store"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery, isDefined } from "../utils"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
salesChannelRepository: typeof SalesChannelRepository
|
salesChannelRepository: typeof SalesChannelRepository
|
||||||
@@ -100,6 +100,13 @@ class SalesChannelService extends TransactionBaseService {
|
|||||||
salesChannelId: string,
|
salesChannelId: string,
|
||||||
config: FindConfig<SalesChannel> = {}
|
config: FindConfig<SalesChannel> = {}
|
||||||
): Promise<SalesChannel | never> {
|
): Promise<SalesChannel | never> {
|
||||||
|
if (!isDefined(salesChannelId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"salesChannelId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ id: salesChannelId }, config)
|
return await this.retrieve_({ id: salesChannelId }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,6 +121,13 @@ class SalesChannelService extends TransactionBaseService {
|
|||||||
name: string,
|
name: string,
|
||||||
config: FindConfig<SalesChannel> = {}
|
config: FindConfig<SalesChannel> = {}
|
||||||
): Promise<SalesChannel | unknown> {
|
): Promise<SalesChannel | unknown> {
|
||||||
|
if (!isDefined(name)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"name" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.retrieve_({ name }, config)
|
return await this.retrieve_({ name }, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -183,6 +183,13 @@ class ShippingOptionService extends TransactionBaseService {
|
|||||||
optionId,
|
optionId,
|
||||||
options: { select?: (keyof ShippingOption)[]; relations?: string[] } = {}
|
options: { select?: (keyof ShippingOption)[]; relations?: string[] } = {}
|
||||||
): Promise<ShippingOption> {
|
): Promise<ShippingOption> {
|
||||||
|
if (!isDefined(optionId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"optionId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const soRepo: ShippingOptionRepository = manager.getCustomRepository(
|
const soRepo: ShippingOptionRepository = manager.getCustomRepository(
|
||||||
this.optionRepository_
|
this.optionRepository_
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
CreateShippingProfile,
|
CreateShippingProfile,
|
||||||
UpdateShippingProfile,
|
UpdateShippingProfile,
|
||||||
} from "../types/shipping-profile"
|
} from "../types/shipping-profile"
|
||||||
import { buildQuery, setMetadata } from "../utils"
|
import { buildQuery, isDefined, setMetadata } from "../utils"
|
||||||
import CustomShippingOptionService from "./custom-shipping-option"
|
import CustomShippingOptionService from "./custom-shipping-option"
|
||||||
import ProductService from "./product"
|
import ProductService from "./product"
|
||||||
import ShippingOptionService from "./shipping-option"
|
import ShippingOptionService from "./shipping-option"
|
||||||
@@ -136,6 +136,13 @@ class ShippingProfileService extends TransactionBaseService {
|
|||||||
profileId: string,
|
profileId: string,
|
||||||
options: FindConfig<ShippingProfile> = {}
|
options: FindConfig<ShippingProfile> = {}
|
||||||
): Promise<ShippingProfile> {
|
): Promise<ShippingProfile> {
|
||||||
|
if (!isDefined(profileId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"profileId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const profileRepository = this.manager_.getCustomRepository(
|
const profileRepository = this.manager_.getCustomRepository(
|
||||||
this.shippingProfileRepository_
|
this.shippingProfileRepository_
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -201,20 +201,27 @@ class SwapService extends TransactionBaseService {
|
|||||||
/**
|
/**
|
||||||
* Retrieves a swap with the given id.
|
* Retrieves a swap with the given id.
|
||||||
*
|
*
|
||||||
* @param id - the id of the swap to retrieve
|
* @param swapId - the id of the swap to retrieve
|
||||||
* @param config - the configuration to retrieve the swap
|
* @param config - the configuration to retrieve the swap
|
||||||
* @return the swap
|
* @return the swap
|
||||||
*/
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
swapId: string,
|
||||||
config: Omit<FindConfig<Swap>, "select"> & { select?: string[] } = {}
|
config: Omit<FindConfig<Swap>, "select"> & { select?: string[] } = {}
|
||||||
): Promise<Swap | never> {
|
): Promise<Swap | never> {
|
||||||
|
if (!isDefined(swapId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"swapId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const swapRepo = this.manager_.getCustomRepository(this.swapRepository_)
|
const swapRepo = this.manager_.getCustomRepository(this.swapRepository_)
|
||||||
|
|
||||||
const { cartSelects, cartRelations, ...newConfig } =
|
const { cartSelects, cartRelations, ...newConfig } =
|
||||||
this.transformQueryForCart(config)
|
this.transformQueryForCart(config)
|
||||||
|
|
||||||
const query = buildQuery({ id }, newConfig)
|
const query = buildQuery({ id: swapId }, newConfig)
|
||||||
|
|
||||||
const relations = query.relations as (keyof Swap)[]
|
const relations = query.relations as (keyof Swap)[]
|
||||||
delete query.relations
|
delete query.relations
|
||||||
|
|||||||
@@ -67,18 +67,25 @@ class TaxRateService extends TransactionBaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
taxRateId: string,
|
||||||
config: FindConfig<TaxRate> = {}
|
config: FindConfig<TaxRate> = {}
|
||||||
): Promise<TaxRate> {
|
): Promise<TaxRate> {
|
||||||
|
if (!isDefined(taxRateId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"taxRateId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const taxRateRepo = manager.getCustomRepository(this.taxRateRepository_)
|
const taxRateRepo = manager.getCustomRepository(this.taxRateRepository_)
|
||||||
const query = buildQuery({ id }, config)
|
const query = buildQuery({ id: taxRateId }, config)
|
||||||
|
|
||||||
const taxRate = await taxRateRepo.findOneWithResolution(query)
|
const taxRate = await taxRateRepo.findOneWithResolution(query)
|
||||||
if (!taxRate) {
|
if (!taxRate) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`TaxRate with ${id} was not found`
|
`TaxRate with ${taxRateId} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
FilterableUserProps,
|
FilterableUserProps,
|
||||||
UpdateUserInput,
|
UpdateUserInput,
|
||||||
} from "../types/user"
|
} from "../types/user"
|
||||||
import { buildQuery, setMetadata } from "../utils"
|
import { buildQuery, isDefined, setMetadata } from "../utils"
|
||||||
import { FlagRouter } from "../utils/flag-router"
|
import { FlagRouter } from "../utils/flag-router"
|
||||||
import { validateEmail } from "../utils/is-email"
|
import { validateEmail } from "../utils/is-email"
|
||||||
import AnalyticsConfigService from "./analytics-config"
|
import AnalyticsConfigService from "./analytics-config"
|
||||||
@@ -80,6 +80,13 @@ class UserService extends TransactionBaseService {
|
|||||||
* @return {Promise<User>} the user document.
|
* @return {Promise<User>} the user document.
|
||||||
*/
|
*/
|
||||||
async retrieve(userId: string, config: FindConfig<User> = {}): Promise<User> {
|
async retrieve(userId: string, config: FindConfig<User> = {}): Promise<User> {
|
||||||
|
if (!isDefined(userId)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`"userId" must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const manager = this.manager_
|
const manager = this.manager_
|
||||||
const userRepo = manager.getCustomRepository(this.userRepository_)
|
const userRepo = manager.getCustomRepository(this.userRepository_)
|
||||||
const query = buildQuery({ id: userId }, config)
|
const query = buildQuery({ id: userId }, config)
|
||||||
@@ -100,7 +107,7 @@ class UserService extends TransactionBaseService {
|
|||||||
* Gets a user by api token.
|
* Gets a user by api token.
|
||||||
* Throws in case of DB Error and if user was not found.
|
* Throws in case of DB Error and if user was not found.
|
||||||
* @param {string} apiToken - the token of the user to get.
|
* @param {string} apiToken - the token of the user to get.
|
||||||
* @param {string[]} relations - relations to include with the user
|
* @param {string[]} relations - relations to include with the user.
|
||||||
* @return {Promise<User>} the user document.
|
* @return {Promise<User>} the user document.
|
||||||
*/
|
*/
|
||||||
async retrieveByApiToken(
|
async retrieveByApiToken(
|
||||||
|
|||||||
Reference in New Issue
Block a user