Skip to content

Commit

Permalink
chore: make apis nullable (#7763)
Browse files Browse the repository at this point in the history
what:

- makes top level attributes of each object an optional field in the http layer where possible

RESOLVES CORE-2229
  • Loading branch information
riqwan authored Jun 20, 2024
1 parent 33c4cd3 commit f615577
Show file tree
Hide file tree
Showing 64 changed files with 431 additions and 416 deletions.
4 changes: 2 additions & 2 deletions integration-tests/factories/simple-order-edit-factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { OrderEdit } from "@medusajs/medusa"
import { DataSource } from "typeorm"
import { OrderFactoryData, simpleOrderFactory } from "./simple-order-factory"
import { OrderEdit } from "@medusajs/medusa"

export type OrderEditFactoryData = {
id?: string
order?: OrderFactoryData
order_id?: string
internal_note?: string
internal_note?: string | null
declined_reason?: string
payment_collection_id?: string
confirmed_at?: Date | string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ function prepareFulfillmentData({
} as FulfillmentWorkflow.CreateFulfillmentItemWorkflowDTO
})

let locationId: string | undefined = input.location_id
let locationId: string | undefined | null = input.location_id

if (!locationId) {
locationId = shippingOption.service_zone.fulfillment_set.location?.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function prepareFulfillmentData({
} as FulfillmentWorkflow.CreateFulfillmentItemWorkflowDTO
})

let locationId: string | undefined = input.location_id
let locationId: string | undefined | null = input.location_id
if (!locationId) {
locationId = returnShippingOption.service_zone.fulfillment_set.location?.id
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/types/src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,5 @@ export type KebabCase<S extends string> =
? `${Lowercase<T>}-${KebabCase<`${Lowercase<U>}${V}`>}`
: `${T}${KebabCase<`${U}${V}`>}`
: S

export type MetadataType = Record<string, unknown> | null
54 changes: 28 additions & 26 deletions packages/core/types/src/customer/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { MetadataType } from "../common"

/**
* The customer address to be created.
*/
export interface CreateCustomerAddressDTO {
/**
* The address's name.
*/
address_name?: string
address_name?: string | null

/**
* Whether the address is default shipping.
Expand All @@ -25,57 +27,57 @@ export interface CreateCustomerAddressDTO {
/**
* The company.
*/
company?: string
company?: string | null

/**
* The first name.
*/
first_name?: string
first_name?: string | null

/**
* The last name.
*/
last_name?: string
last_name?: string | null

/**
* The address 1.
*/
address_1?: string
address_1?: string | null

/**
* The address 2.
*/
address_2?: string
address_2?: string | null

/**
* The city.
*/
city?: string
city?: string | null

/**
* The country code.
*/
country_code?: string
country_code?: string | null

/**
* The province.
*/
province?: string
province?: string | null

/**
* The postal code.
*/
postal_code?: string
postal_code?: string | null

/**
* The phone.
*/
phone?: string
phone?: string | null

/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
metadata?: MetadataType
}

/**
Expand Down Expand Up @@ -160,7 +162,7 @@ export interface UpdateCustomerAddressDTO {
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
metadata?: MetadataType
}

/**
Expand All @@ -170,32 +172,32 @@ export interface CreateCustomerDTO {
/**
* The company name of the customer.
*/
company_name?: string
company_name?: string | null

/**
* The first name of the customer.
*/
first_name?: string
first_name?: string | null

/**
* The last name of the customer.
*/
last_name?: string
last_name?: string | null

/**
* The email of the customer.
*/
email?: string
email?: string | null

/**
* The phone of the customer.
*/
phone?: string
phone?: string | null

/**
* Who created the customer.
*/
created_by?: string
created_by?: string | null

/**
* The addresses of the customer.
Expand All @@ -205,7 +207,7 @@ export interface CreateCustomerDTO {
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown>
metadata?: MetadataType
}

/**
Expand Down Expand Up @@ -245,7 +247,7 @@ export interface UpdateCustomerDTO {
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
metadata?: MetadataType
}

/**
Expand Down Expand Up @@ -280,7 +282,7 @@ export interface CustomerUpdatableFields {
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
metadata?: MetadataType
}

/**
Expand All @@ -295,7 +297,7 @@ export interface CustomerGroupUpdatableFields {
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
metadata?: MetadataType
}

/**
Expand All @@ -320,7 +322,7 @@ export interface UpdateCustomerGroupDTO {
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
metadata?: MetadataType
}

/**
Expand All @@ -335,7 +337,7 @@ export interface CreateCustomerGroupDTO {
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
metadata?: MetadataType

/**
* Who created the customer group. For example,
Expand All @@ -361,5 +363,5 @@ export interface UpdateCustomerGroupDTO {
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
metadata?: MetadataType
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface UpdateServiceZoneDTO {
/**
* The name of the service zone.
*/
name?: string
name?: string | null

/**
* The geo zones associated with the service zone.
Expand Down
14 changes: 7 additions & 7 deletions packages/core/types/src/inventory/mutations/reservation-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface UpdateReservationItemInput {
/**
* The description of the reservation item.
*/
description?: string
description?: string | null
/**
* Allow backorder of the item. If true, it won't check inventory levels before reserving it.
*/
Expand All @@ -36,7 +36,7 @@ export interface CreateReservationItemInput {
/**
* The ID of the associated line item.
*/
line_item_id?: string
line_item_id?: string | null
/**
* The ID of the associated inventory item.
*/
Expand All @@ -56,23 +56,23 @@ export interface CreateReservationItemInput {
/**
* The description of the reservation.
*/
description?: string
description?: string | null
/**
* The user or system that created the reservation. Can be any form of identification string.
*/
created_by?: string
created_by?: string | null
/**
* An ID associated with an external third-party system that the reservation item is connected to.
*/
external_id?: string
external_id?: string | null
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
}

export interface ReserveQuantityContext {
locationId?: string
lineItemId?: string
locationId?: string | null
lineItemId?: string | null
salesChannelId?: string | null
}
26 changes: 13 additions & 13 deletions packages/core/types/src/order/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export interface CreateOrderChangeDTO {
claim_id?: string
exchange_id?: string
description?: string
internal_note?: string
internal_note?: string | null
requested_by?: string
requested_at?: Date
created_by?: string
Expand All @@ -265,7 +265,7 @@ export interface UpdateOrderChangeDTO {
id: string
status?: string
description?: string
internal_note?: string
internal_note?: string | null
requested_by?: string
requested_at?: Date
confirmed_by?: string
Expand Down Expand Up @@ -309,14 +309,14 @@ export interface CreateOrderChangeActionDTO {
reference?: string
reference_id?: string
action: ChangeActionType
internal_note?: string
internal_note?: string | null
amount?: BigNumberInput
details?: Record<string, unknown>
}

export interface UpdateOrderChangeActionDTO {
id: string
internal_note?: string
internal_note?: string | null
}

/** ORDER TRANSACTION START */
Expand All @@ -326,7 +326,7 @@ export interface CreateOrderTransactionDTO {
description?: string
reference?: string
reference_id?: string
internal_note?: string
internal_note?: string | null
created_by?: string
amount: BigNumberInput
currency_code: string
Expand All @@ -338,7 +338,7 @@ export interface UpdateOrderTransactionDTO {
amount?: BigNumberInput
currency_code?: string
description?: string
internal_note?: string
internal_note?: string | null
reference?: string
reference_id?: string
metadata?: Record<string, unknown> | null
Expand Down Expand Up @@ -378,8 +378,8 @@ export interface UpdateOrderItemWithSelectorDTO {
interface BaseOrderBundledItemActionsDTO {
id: string
quantity: BigNumberInput
internal_note?: string
note?: string
internal_note?: string | null
note?: string | null
metadata?: Record<string, unknown> | null
}
interface BaseOrderBundledActionsDTO {
Expand All @@ -389,10 +389,10 @@ interface BaseOrderBundledActionsDTO {
exchange_id?: string

description?: string
internal_note?: string
internal_note?: string | null
reference?: string
reference_id?: string
created_by?: string
created_by?: string | null
metadata?: Record<string, unknown> | null
}

Expand All @@ -414,9 +414,9 @@ export interface CreateOrderReturnDTO extends BaseOrderBundledActionsDTO {
items: {
id: string
quantity: BigNumberInput
internal_note?: string
note?: string
reason_id?: string
internal_note?: string | null
note?: string | null
reason_id?: string | null
metadata?: Record<string, any>
}[]
shipping_method?: Omit<CreateOrderShippingMethodDTO, "order_id"> | string
Expand Down
4 changes: 2 additions & 2 deletions packages/core/types/src/pricing/common/money-amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ export interface UpdateMoneyAmountDTO {
/**
* The minimum quantity required to be purchased for this money amount to be applied.
*/
min_quantity?: BigNumberInput
min_quantity?: BigNumberInput | null
/**
* The maximum quantity required to be purchased for this money amount to be applied.
*/
max_quantity?: BigNumberInput
max_quantity?: BigNumberInput | null
}

/**
Expand Down
Loading

0 comments on commit f615577

Please sign in to comment.