Chore/rm main entity concept (#7709)
**What** Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate. This pr also includes various fixes in different modules Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
2895ccfba8
commit
48963f55ef
@@ -15,7 +15,7 @@ import {
|
||||
ReservationItemRes,
|
||||
} from "../../types/api-responses"
|
||||
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { client } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
@@ -68,7 +68,7 @@ export const useUpdateReservationItem = (
|
||||
options?: UseMutationOptions<ReservationItemRes, Error, UpdateReservationReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: InventoryNext.UpdateReservationItemInput) =>
|
||||
mutationFn: (payload: InventoryTypes.UpdateReservationItemInput) =>
|
||||
client.reservations.update(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from "../../types/api-responses"
|
||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
||||
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
|
||||
async function retrieveReservation(id: string, query?: Record<string, any>) {
|
||||
return getRequest<ReservationRes>(`/admin/reservations/${id}`, query)
|
||||
@@ -16,14 +16,14 @@ async function listReservations(query?: Record<string, any>) {
|
||||
}
|
||||
|
||||
async function createReservation(
|
||||
payload: InventoryNext.CreateReservationItemInput
|
||||
payload: InventoryTypes.CreateReservationItemInput
|
||||
) {
|
||||
return postRequest<ReservationRes>(`/admin/reservations`, payload)
|
||||
}
|
||||
|
||||
async function updateReservation(
|
||||
id: string,
|
||||
payload: InventoryNext.UpdateReservationItemInput
|
||||
payload: InventoryTypes.UpdateReservationItemInput
|
||||
) {
|
||||
return postRequest<ReservationRes>(`/admin/reservations/${id}`, payload)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ async function retrieveWorkflowExecution(
|
||||
)
|
||||
}
|
||||
|
||||
async function listWorkflowExecutions(query?: Record<string, any>) {
|
||||
async function listWorkflowExecutionss(query?: Record<string, any>) {
|
||||
return getRequest<WorkflowExecutionListRes>(
|
||||
`/admin/workflows-executions`,
|
||||
query
|
||||
@@ -23,5 +23,5 @@ async function listWorkflowExecutions(query?: Record<string, any>) {
|
||||
|
||||
export const workflowExecutions = {
|
||||
retrieve: retrieveWorkflowExecution,
|
||||
list: listWorkflowExecutions,
|
||||
list: listWorkflowExecutionss,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AdjustInventoryForm } from "./components/adjust-inventory-form"
|
||||
import { Heading } from "@medusajs/ui"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { RouteDrawer } from "../../../../../components/route-modal"
|
||||
import { useInventoryItem } from "../../../../../hooks/api/inventory"
|
||||
import { useParams } from "react-router-dom"
|
||||
@@ -19,7 +19,7 @@ export const AdjustInventoryDrawer = () => {
|
||||
} = useInventoryItem(id!)
|
||||
|
||||
const inventoryLevel = inventoryItem?.location_levels!.find(
|
||||
(level: InventoryNext.InventoryLevelDTO) =>
|
||||
(level: InventoryTypes.InventoryLevelDTO) =>
|
||||
level.location_id === location_id
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from "../../../../../../components/route-modal"
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { z } from "zod"
|
||||
@@ -16,7 +16,7 @@ import { CountrySelect } from "../../../../../../components/inputs/country-selec
|
||||
import { useUpdateInventoryItem } from "../../../../../../hooks/api/inventory"
|
||||
|
||||
type EditInventoryItemAttributeFormProps = {
|
||||
item: InventoryNext.InventoryItemDTO
|
||||
item: InventoryTypes.InventoryItemDTO
|
||||
}
|
||||
|
||||
const EditInventoryItemAttributesSchema = z.object({
|
||||
@@ -29,7 +29,7 @@ const EditInventoryItemAttributesSchema = z.object({
|
||||
origin_country: z.string().optional(),
|
||||
})
|
||||
|
||||
const getDefaultValues = (item: InventoryNext.InventoryItemDTO) => {
|
||||
const getDefaultValues = (item: InventoryTypes.InventoryItemDTO) => {
|
||||
return {
|
||||
height: item.height ?? undefined,
|
||||
width: item.width ?? undefined,
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from "../../../../../../components/route-modal"
|
||||
|
||||
import { Form } from "../../../../../../components/common/form"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useUpdateInventoryItem } from "../../../../../../hooks/api/inventory"
|
||||
@@ -15,7 +15,7 @@ import { z } from "zod"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
|
||||
type EditInventoryItemFormProps = {
|
||||
item: InventoryNext.InventoryItemDTO
|
||||
item: InventoryTypes.InventoryItemDTO
|
||||
}
|
||||
|
||||
const EditInventoryItemSchema = z.object({
|
||||
@@ -23,7 +23,7 @@ const EditInventoryItemSchema = z.object({
|
||||
sku: z.string().min(1),
|
||||
})
|
||||
|
||||
const getDefaultValues = (item: InventoryNext.InventoryItemDTO) => {
|
||||
const getDefaultValues = (item: InventoryTypes.InventoryItemDTO) => {
|
||||
return {
|
||||
title: item.title ?? undefined,
|
||||
sku: item.sku ?? undefined,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Container, Heading } from "@medusajs/ui"
|
||||
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { PencilSquare } from "@medusajs/icons"
|
||||
import { SectionRow } from "../../../../../components/common/section"
|
||||
import { getFormattedCountry } from "../../../../../lib/addresses"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
type InventoryItemAttributeSectionProps = {
|
||||
inventoryItem: InventoryNext.InventoryItemDTO
|
||||
inventoryItem: InventoryTypes.InventoryItemDTO
|
||||
}
|
||||
|
||||
export const InventoryItemAttributeSection = ({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { useDeleteInventoryItemLevel } from "../../../../../hooks/api/inventory"
|
||||
import { usePrompt } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next"
|
||||
export const LocationActions = ({
|
||||
level,
|
||||
}: {
|
||||
level: InventoryNext.InventoryLevelDTO
|
||||
level: InventoryTypes.InventoryLevelDTO
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const prompt = usePrompt()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { InventoryNext, StockLocationDTO } from "@medusajs/types"
|
||||
import { InventoryTypes, StockLocationDTO } from "@medusajs/types"
|
||||
|
||||
import { LocationActions } from "./location-actions"
|
||||
import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell"
|
||||
@@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next"
|
||||
/**
|
||||
* Adds missing properties to the InventoryLevelDTO type.
|
||||
*/
|
||||
interface ExtendedLocationLevel extends InventoryNext.InventoryLevelDTO {
|
||||
interface ExtendedLocationLevel extends InventoryTypes.InventoryLevelDTO {
|
||||
stock_locations: StockLocationDTO[]
|
||||
reserved_quantity: number
|
||||
stocked_quantity: number
|
||||
|
||||
@@ -2,14 +2,14 @@ import { PencilSquare, Trash } from "@medusajs/icons"
|
||||
import { toast, usePrompt } from "@medusajs/ui"
|
||||
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { useDeleteReservationItem } from "../../../../../hooks/api/reservations"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
export const ReservationActions = ({
|
||||
reservation,
|
||||
}: {
|
||||
reservation: InventoryNext.ReservationItemDTO
|
||||
reservation: InventoryTypes.ReservationItemDTO
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const prompt = usePrompt()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DataTable } from "../../../../../components/table/data-table"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||
import { useReservationItems } from "../../../../../hooks/api/reservations"
|
||||
import { useReservationTableColumn } from "./use-reservation-list-table-columns"
|
||||
@@ -10,7 +10,7 @@ const PAGE_SIZE = 20
|
||||
export const ReservationItemTable = ({
|
||||
inventoryItem,
|
||||
}: {
|
||||
inventoryItem: InventoryNext.InventoryItemDTO
|
||||
inventoryItem: InventoryTypes.InventoryItemDTO
|
||||
}) => {
|
||||
const { searchParams, raw } = useReservationsTableQuery({
|
||||
pageSize: PAGE_SIZE,
|
||||
@@ -29,7 +29,7 @@ export const ReservationItemTable = ({
|
||||
columns,
|
||||
count,
|
||||
enablePagination: true,
|
||||
getRowId: (row: InventoryNext.ReservationItemDTO) => row.id,
|
||||
getRowId: (row: InventoryTypes.ReservationItemDTO) => row.id,
|
||||
pageSize: PAGE_SIZE,
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { InventoryNext, StockLocationDTO } from "@medusajs/types"
|
||||
import { InventoryTypes, StockLocationDTO } from "@medusajs/types"
|
||||
|
||||
import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell"
|
||||
import { ReservationActions } from "./reservation-actions"
|
||||
@@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next"
|
||||
/**
|
||||
* Adds missing properties to the InventoryItemDTO type.
|
||||
*/
|
||||
interface ExtendedReservationItem extends InventoryNext.ReservationItemDTO {
|
||||
interface ExtendedReservationItem extends InventoryTypes.ReservationItemDTO {
|
||||
line_item: { order_id: string }
|
||||
location: StockLocationDTO
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Button, Container, Heading } from "@medusajs/ui"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
|
||||
import { DataTable } from "../../../../components/table/data-table"
|
||||
import { useDataTable } from "../../../../hooks/use-data-table"
|
||||
@@ -33,7 +33,7 @@ export const InventoryListTable = () => {
|
||||
const columns = useInventoryTableColumns()
|
||||
|
||||
const { table } = useDataTable({
|
||||
data: (inventory_items ?? []) as InventoryNext.InventoryItemDTO[],
|
||||
data: (inventory_items ?? []) as InventoryTypes.InventoryItemDTO[],
|
||||
columns,
|
||||
count,
|
||||
enablePagination: true,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { InventoryNext, ProductVariantDTO } from "@medusajs/types"
|
||||
import { InventoryTypes, ProductVariantDTO } from "@medusajs/types"
|
||||
|
||||
import { InventoryActions } from "./inventory-actions"
|
||||
import { PlaceholderCell } from "../../../../components/table/table-cells/common/placeholder-cell"
|
||||
@@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next"
|
||||
/**
|
||||
* Adds missing properties to the InventoryItemDTO type.
|
||||
*/
|
||||
interface ExtendedInventoryItem extends InventoryNext.InventoryItemDTO {
|
||||
interface ExtendedInventoryItem extends InventoryTypes.InventoryItemDTO {
|
||||
variants?: ProductVariantDTO[] | null
|
||||
stocked_quantity?: number
|
||||
reserved_quantity?: number
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as zod from "zod"
|
||||
|
||||
import { Button, Input, Select, Text, Textarea, toast } from "@medusajs/ui"
|
||||
import { InventoryNext, StockLocationDTO } from "@medusajs/types"
|
||||
import { InventoryTypes, StockLocationDTO } from "@medusajs/types"
|
||||
import {
|
||||
RouteDrawer,
|
||||
useRouteModal,
|
||||
@@ -16,7 +16,7 @@ import { z } from "zod"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
|
||||
type EditReservationFormProps = {
|
||||
reservation: InventoryNext.ReservationItemDTO
|
||||
reservation: InventoryTypes.ReservationItemDTO
|
||||
locations: StockLocationDTO[]
|
||||
item: InventoryItemRes["inventory_item"]
|
||||
}
|
||||
@@ -46,7 +46,7 @@ const AttributeGridRow = ({
|
||||
)
|
||||
}
|
||||
|
||||
const getDefaultValues = (reservation: InventoryNext.ReservationItemDTO) => {
|
||||
const getDefaultValues = (reservation: InventoryTypes.ReservationItemDTO) => {
|
||||
return {
|
||||
quantity: reservation.quantity,
|
||||
location_id: reservation.location_id,
|
||||
@@ -85,7 +85,8 @@ export const EditReservationForm = ({
|
||||
const locationId = form.watch("location_id")
|
||||
|
||||
const level = item.location_levels!.find(
|
||||
(level: InventoryNext.InventoryLevelDTO) => level.location_id === locationId
|
||||
(level: InventoryTypes.InventoryLevelDTO) =>
|
||||
level.location_id === locationId
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { EditReservationForm } from "./components/edit-reservation-form"
|
||||
import { Heading } from "@medusajs/ui"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { RouteDrawer } from "../../../../../components/route-modal"
|
||||
import { useInventoryItem } from "../../../../../hooks/api/inventory"
|
||||
import { useParams } from "react-router-dom"
|
||||
@@ -23,7 +23,7 @@ export const ReservationEdit = () => {
|
||||
const { stock_locations } = useStockLocations(
|
||||
{
|
||||
id: inventoryItem?.location_levels?.map(
|
||||
(l: InventoryNext.InventoryLevelDTO) => l.location_id
|
||||
(l: InventoryTypes.InventoryLevelDTO) => l.location_id
|
||||
),
|
||||
},
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ import { AdminReservationResponse, StockLocationDTO } from "@medusajs/types"
|
||||
import { Container, Heading } from "@medusajs/ui"
|
||||
|
||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import { PencilSquare } from "@medusajs/icons"
|
||||
import { SectionRow } from "../../../../../components/common/section"
|
||||
import { useInventoryItem } from "../../../../../hooks/api/inventory"
|
||||
@@ -34,7 +34,7 @@ export const ReservationGeneralSection = ({
|
||||
}
|
||||
|
||||
const locationLevel = inventoryItem.location_levels!.find(
|
||||
(l: InventoryNext.InventoryLevelDTO) =>
|
||||
(l: InventoryTypes.InventoryLevelDTO) =>
|
||||
l.location_id === reservation.location_id
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from "../../../../../../components/route-modal"
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
import React from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -81,7 +81,7 @@ export const CreateReservationForm = () => {
|
||||
{
|
||||
id:
|
||||
selectedInventoryItem?.location_levels?.map(
|
||||
(level: InventoryNext.InventoryLevelDTO) => level.location_id
|
||||
(level: InventoryTypes.InventoryLevelDTO) => level.location_id
|
||||
) ?? [],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
CreateShippingOptionDTO,
|
||||
CreateShippingProfileDTO,
|
||||
CreateStockLocationInput,
|
||||
InventoryNext,
|
||||
InventoryTypes,
|
||||
UpdateApiKeyDTO,
|
||||
UpdateCampaignDTO,
|
||||
UpdatePriceListDTO,
|
||||
@@ -112,7 +112,7 @@ export type UpdateCampaignReq = UpdateCampaignDTO
|
||||
|
||||
// Reservations
|
||||
export type UpdateReservationReq = Omit<
|
||||
InventoryNext.UpdateReservationItemInput,
|
||||
InventoryTypes.UpdateReservationItemInput,
|
||||
"id"
|
||||
>
|
||||
export type CreateReservationReq = InventoryNext.CreateReservationItemInput
|
||||
export type CreateReservationReq = InventoryTypes.CreateReservationItemInput
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
CustomerGroupDTO,
|
||||
FulfillmentDTO,
|
||||
FulfillmentProviderDTO,
|
||||
InventoryNext,
|
||||
InventoryTypes,
|
||||
InviteDTO,
|
||||
OrderDTO,
|
||||
PaymentProviderDTO,
|
||||
@@ -70,9 +70,9 @@ export type FulfillmentListRes = { fulfillments: FulfillmentDTO[] } & ListRes
|
||||
export type FulfillmentDeleteRes = DeleteRes
|
||||
|
||||
// Reservations
|
||||
export type ReservationRes = { reservation: InventoryNext.ReservationItemDTO }
|
||||
export type ReservationRes = { reservation: InventoryTypes.ReservationItemDTO }
|
||||
export type ReservationListRes = {
|
||||
reservations: InventoryNext.ReservationItemDTO[]
|
||||
reservations: InventoryTypes.ReservationItemDTO[]
|
||||
} & ListRes
|
||||
export type ReservationDeleteRes = DeleteRes
|
||||
|
||||
@@ -152,11 +152,11 @@ export type TaxRateDeleteRes = DeleteRes
|
||||
export type ReservationItemDeleteRes = DeleteRes
|
||||
|
||||
export type ReservationItemListRes = {
|
||||
reservations: InventoryNext.ReservationItemDTO[]
|
||||
reservations: InventoryTypes.ReservationItemDTO[]
|
||||
} & ListRes
|
||||
|
||||
export type ReservationItemRes = {
|
||||
reservation: InventoryNext.ReservationItemDTO
|
||||
reservation: InventoryTypes.ReservationItemDTO
|
||||
}
|
||||
// Price Lists
|
||||
export type PriceListRes = { price_list: PriceListDTO }
|
||||
|
||||
Reference in New Issue
Block a user