fix: Accept filters in softDelete + fulfillment location clean-up (#7198)
This commit is contained in:
1 parent
1366e2efad
commit
2f7b53488d
20 files changed
+232
-114
No files matched your search
@@ -245,6 +245,14 @@ medusaIntegrationTestRunner({
|
|||||||
object: "stock_location",
|
object: "stock_location",
|
||||||
deleted: true,
|
deleted: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const stockLocations = await api.get(
|
||||||
|
`/admin/stock-locations`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(stockLocations.status).toEqual(200)
|
||||||
|
expect(stockLocations.data.stock_locations).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should successfully delete stock location associations", async () => {
|
it("should successfully delete stock location associations", async () => {
|
||||||
@@ -390,7 +398,7 @@ medusaIntegrationTestRunner({
|
|||||||
stockLocationId = createResponse.data.stock_location.id
|
stockLocationId = createResponse.data.stock_location.id
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should create a fulfillment set for the location", async () => {
|
it("should create a fulfillment set for the location and then delete it and its associations", async () => {
|
||||||
const response = await api.post(
|
const response = await api.post(
|
||||||
`/admin/stock-locations/${stockLocationId}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
`/admin/stock-locations/${stockLocationId}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
||||||
{
|
{
|
||||||
@@ -407,6 +415,19 @@ medusaIntegrationTestRunner({
|
|||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
await api.delete(
|
||||||
|
`/admin/stock-locations/${stockLocationId}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const fulfillmentModule = appContainer.resolve(
|
||||||
|
ModuleRegistrationName.FULFILLMENT
|
||||||
|
)
|
||||||
|
|
||||||
|
const sets = await fulfillmentModule.list()
|
||||||
|
|
||||||
|
expect(sets).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
// This is really just to test the new Zod middleware. We don't need more of these.
|
// This is really just to test the new Zod middleware. We don't need more of these.
|
||||||
|
|||||||
@@ -1634,12 +1634,12 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[Modules.FULFILLMENT]: {
|
|
||||||
fulfillment_set_id: fulfillmentSet.id,
|
|
||||||
},
|
|
||||||
[Modules.STOCK_LOCATION]: {
|
[Modules.STOCK_LOCATION]: {
|
||||||
stock_location_id: location.id,
|
stock_location_id: location.id,
|
||||||
},
|
},
|
||||||
|
[Modules.FULFILLMENT]: {
|
||||||
|
fulfillment_set_id: fulfillmentSet.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[Modules.FULFILLMENT]: {
|
[Modules.FULFILLMENT]: {
|
||||||
@@ -1745,12 +1745,12 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
await remoteLink.create([
|
await remoteLink.create([
|
||||||
{
|
{
|
||||||
[Modules.FULFILLMENT]: {
|
|
||||||
fulfillment_set_id: fulfillmentSet.id,
|
|
||||||
},
|
|
||||||
[Modules.STOCK_LOCATION]: {
|
[Modules.STOCK_LOCATION]: {
|
||||||
stock_location_id: location.id,
|
stock_location_id: location.id,
|
||||||
},
|
},
|
||||||
|
[Modules.FULFILLMENT]: {
|
||||||
|
fulfillment_set_id: fulfillmentSet.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[Modules.FULFILLMENT]: {
|
[Modules.FULFILLMENT]: {
|
||||||
@@ -1849,12 +1849,12 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[Modules.FULFILLMENT]: {
|
|
||||||
fulfillment_set_id: fulfillmentSet.id,
|
|
||||||
},
|
|
||||||
[Modules.STOCK_LOCATION]: {
|
[Modules.STOCK_LOCATION]: {
|
||||||
stock_location_id: location.id,
|
stock_location_id: location.id,
|
||||||
},
|
},
|
||||||
|
[Modules.FULFILLMENT]: {
|
||||||
|
fulfillment_set_id: fulfillmentSet.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -1485,8 +1485,8 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
await remoteLinkService.create([
|
await remoteLinkService.create([
|
||||||
{
|
{
|
||||||
[Modules.FULFILLMENT]: { fulfillment_set_id: fulfillmentSet.id },
|
|
||||||
[Modules.STOCK_LOCATION]: { stock_location_id: stockLocation.id },
|
[Modules.STOCK_LOCATION]: { stock_location_id: stockLocation.id },
|
||||||
|
[Modules.FULFILLMENT]: { fulfillment_set_id: fulfillmentSet.id },
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -52,18 +52,18 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
await remoteLink.create([
|
await remoteLink.create([
|
||||||
{
|
{
|
||||||
[Modules.FULFILLMENT]: {
|
|
||||||
fulfillment_set_id: fulfillmentSet.id,
|
|
||||||
},
|
|
||||||
[Modules.STOCK_LOCATION]: {
|
[Modules.STOCK_LOCATION]: {
|
||||||
stock_location_id: euWarehouse.id,
|
stock_location_id: euWarehouse.id,
|
||||||
},
|
},
|
||||||
|
[Modules.FULFILLMENT]: {
|
||||||
|
fulfillment_set_id: fulfillmentSet.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const linkQuery = remoteQueryObjectFromString({
|
const linkQuery = remoteQueryObjectFromString({
|
||||||
entryPoint: "fulfillment_sets",
|
entryPoint: "stock_locations",
|
||||||
fields: ["id", "stock_locations.id"],
|
fields: ["id", "fulfillment_sets.id"],
|
||||||
})
|
})
|
||||||
|
|
||||||
const link = await remoteQuery(linkQuery)
|
const link = await remoteQuery(linkQuery)
|
||||||
@@ -72,10 +72,10 @@ medusaIntegrationTestRunner({
|
|||||||
expect(link).toEqual(
|
expect(link).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: fulfillmentSet.id,
|
id: euWarehouse.id,
|
||||||
stock_locations: expect.arrayContaining([
|
fulfillment_sets: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: euWarehouse.id,
|
id: fulfillmentSet.id,
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -127,12 +127,12 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
await remoteLinkService.create([
|
await remoteLinkService.create([
|
||||||
{
|
{
|
||||||
[Modules.FULFILLMENT]: {
|
|
||||||
fulfillment_set_id: fulfillmentSet.id,
|
|
||||||
},
|
|
||||||
[Modules.STOCK_LOCATION]: {
|
[Modules.STOCK_LOCATION]: {
|
||||||
stock_location_id: stockLocation.id,
|
stock_location_id: stockLocation.id,
|
||||||
},
|
},
|
||||||
|
[Modules.FULFILLMENT]: {
|
||||||
|
fulfillment_set_id: fulfillmentSet.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -24,12 +24,12 @@ export const associateFulfillmentSetsWithLocationStep = createStep(
|
|||||||
.map((link) => {
|
.map((link) => {
|
||||||
return link.fulfillment_set_ids.map((id) => {
|
return link.fulfillment_set_ids.map((id) => {
|
||||||
return {
|
return {
|
||||||
[Modules.FULFILLMENT]: {
|
|
||||||
fulfillment_set_id: id,
|
|
||||||
},
|
|
||||||
[Modules.STOCK_LOCATION]: {
|
[Modules.STOCK_LOCATION]: {
|
||||||
stock_location_id: link.location_id,
|
stock_location_id: link.location_id,
|
||||||
},
|
},
|
||||||
|
[Modules.FULFILLMENT]: {
|
||||||
|
fulfillment_set_id: id,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
|
import {
|
||||||
|
DeleteEntityInput,
|
||||||
|
ModuleRegistrationName,
|
||||||
|
Modules,
|
||||||
|
} from "@medusajs/modules-sdk"
|
||||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|
||||||
|
|
||||||
export const deleteStockLocationsStepId = "delete-stock-locations-step"
|
export const deleteStockLocationsStepId = "delete-stock-locations-step"
|
||||||
export const deleteStockLocationsStep = createStep(
|
export const deleteStockLocationsStep = createStep(
|
||||||
deleteStockLocationsStepId,
|
deleteStockLocationsStepId,
|
||||||
async (input: string[], { container }) => {
|
async (input: string[], { container }) => {
|
||||||
const service = container.resolve(ModuleRegistrationName.STOCK_LOCATION)
|
const service = container.resolve(ModuleRegistrationName.STOCK_LOCATION)
|
||||||
|
|
||||||
await service.softDelete(input)
|
const softDeletedEntities = await service.softDelete(input)
|
||||||
|
|
||||||
return new StepResponse(void 0, input)
|
return new StepResponse(
|
||||||
|
{
|
||||||
|
[Modules.STOCK_LOCATION]: softDeletedEntities,
|
||||||
|
} as DeleteEntityInput,
|
||||||
|
input
|
||||||
|
)
|
||||||
},
|
},
|
||||||
async (deletedLocationIds, { container }) => {
|
async (deletedLocationIds, { container }) => {
|
||||||
if (!deletedLocationIds?.length) {
|
if (!deletedLocationIds?.length) {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
import { Modules } from "@medusajs/modules-sdk"
|
|
||||||
import { deleteStockLocationsStep } from "../steps"
|
|
||||||
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
|
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
|
||||||
|
import { deleteStockLocationsStep } from "../steps"
|
||||||
|
|
||||||
interface WorkflowInput {
|
interface WorkflowInput {
|
||||||
ids: string[]
|
ids: string[]
|
||||||
@@ -12,10 +11,8 @@ export const deleteStockLocationsWorkflowId = "delete-stock-locations-workflow"
|
|||||||
export const deleteStockLocationsWorkflow = createWorkflow(
|
export const deleteStockLocationsWorkflow = createWorkflow(
|
||||||
deleteStockLocationsWorkflowId,
|
deleteStockLocationsWorkflowId,
|
||||||
(input: WorkflowData<WorkflowInput>) => {
|
(input: WorkflowData<WorkflowInput>) => {
|
||||||
deleteStockLocationsStep(input.ids)
|
const softDeletedEntities = deleteStockLocationsStep(input.ids)
|
||||||
|
|
||||||
removeRemoteLinkStep({
|
removeRemoteLinkStep(softDeletedEntities)
|
||||||
[Modules.STOCK_LOCATION]: { stock_location_id: input.ids },
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -3,8 +3,8 @@ import { Context } from "../shared-context"
|
|||||||
import {
|
import {
|
||||||
BaseFilterable,
|
BaseFilterable,
|
||||||
FilterQuery,
|
FilterQuery,
|
||||||
FindOptions,
|
|
||||||
FilterQuery as InternalFilterQuery,
|
FilterQuery as InternalFilterQuery,
|
||||||
|
FindOptions,
|
||||||
UpsertWithReplaceConfig,
|
UpsertWithReplaceConfig,
|
||||||
} from "./index"
|
} from "./index"
|
||||||
|
|
||||||
@@ -61,7 +61,11 @@ export interface RepositoryService<T = any> extends BaseRepositoryService<T> {
|
|||||||
* @returns [T[], Record<string, string[]>] the second value being the map of the entity names and ids that were soft deleted
|
* @returns [T[], Record<string, string[]>] the second value being the map of the entity names and ids that were soft deleted
|
||||||
*/
|
*/
|
||||||
softDelete(
|
softDelete(
|
||||||
idsOrFilter: string[] | InternalFilterQuery,
|
idsOrFilter:
|
||||||
|
| string
|
||||||
|
| string[]
|
||||||
|
| InternalFilterQuery
|
||||||
|
| InternalFilterQuery[],
|
||||||
context?: Context
|
context?: Context
|
||||||
): Promise<[T[], Record<string, unknown[]>]>
|
): Promise<[T[], Record<string, unknown[]>]>
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,11 @@ export interface InternalModuleService<
|
|||||||
): Promise<void>
|
): Promise<void>
|
||||||
|
|
||||||
softDelete(
|
softDelete(
|
||||||
idsOrFilter: string[] | InternalFilterQuery,
|
idsOrFilter:
|
||||||
|
| string
|
||||||
|
| string[]
|
||||||
|
| InternalFilterQuery
|
||||||
|
| InternalFilterQuery[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]>
|
): Promise<[TEntity[], Record<string, unknown[]>]>
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
LoadStrategy,
|
LoadStrategy,
|
||||||
ReferenceType,
|
ReferenceType,
|
||||||
RequiredEntityData,
|
RequiredEntityData,
|
||||||
wrap,
|
|
||||||
} from "@mikro-orm/core"
|
} from "@mikro-orm/core"
|
||||||
import { FindOptions as MikroOptions } from "@mikro-orm/core/drivers/IDatabaseDriver"
|
import { FindOptions as MikroOptions } from "@mikro-orm/core/drivers/IDatabaseDriver"
|
||||||
import {
|
import {
|
||||||
@@ -25,9 +24,9 @@ import {
|
|||||||
} from "@mikro-orm/core/typings"
|
} from "@mikro-orm/core/typings"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
import {
|
import {
|
||||||
MedusaError,
|
|
||||||
arrayDifference,
|
arrayDifference,
|
||||||
isString,
|
isString,
|
||||||
|
MedusaError,
|
||||||
promiseAll,
|
promiseAll,
|
||||||
} from "../../common"
|
} from "../../common"
|
||||||
import { buildQuery } from "../../modules-sdk"
|
import { buildQuery } from "../../modules-sdk"
|
||||||
@@ -35,9 +34,9 @@ import {
|
|||||||
getSoftDeletedCascadedEntitiesIdsMappedBy,
|
getSoftDeletedCascadedEntitiesIdsMappedBy,
|
||||||
transactionWrapper,
|
transactionWrapper,
|
||||||
} from "../utils"
|
} from "../utils"
|
||||||
import { mikroOrmUpdateDeletedAtRecursively } from "./utils"
|
|
||||||
import { mikroOrmSerializer } from "./mikro-orm-serializer"
|
|
||||||
import { dbErrorMapper } from "./db-error-mapper"
|
import { dbErrorMapper } from "./db-error-mapper"
|
||||||
|
import { mikroOrmSerializer } from "./mikro-orm-serializer"
|
||||||
|
import { mikroOrmUpdateDeletedAtRecursively } from "./utils"
|
||||||
|
|
||||||
export class MikroOrmBase<T = any> {
|
export class MikroOrmBase<T = any> {
|
||||||
readonly manager_: any
|
readonly manager_: any
|
||||||
@@ -101,6 +100,17 @@ export class MikroOrmBaseRepository<T extends object = object>
|
|||||||
super(...arguments)
|
super(...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static buildUniqueCompositeKeyValue(keys: string[], data: object) {
|
||||||
|
return keys.map((k) => data[k]).join("_")
|
||||||
|
}
|
||||||
|
|
||||||
|
static retrievePrimaryKeys(entity: EntityClass<any> | EntitySchema) {
|
||||||
|
return (
|
||||||
|
(entity as EntitySchema).meta?.primaryKeys ??
|
||||||
|
(entity as EntityClass<any>).prototype.__meta.primaryKeys ?? ["id"]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
create(data: unknown[], context?: Context): Promise<T[]> {
|
create(data: unknown[], context?: Context): Promise<T[]> {
|
||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
@@ -142,21 +152,14 @@ export class MikroOrmBaseRepository<T extends object = object>
|
|||||||
}
|
}
|
||||||
|
|
||||||
async softDelete(
|
async softDelete(
|
||||||
idsOrFilter: string[] | InternalFilterQuery,
|
filters:
|
||||||
|
| string
|
||||||
|
| string[]
|
||||||
|
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)
|
||||||
|
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)[],
|
||||||
sharedContext: Context = {}
|
sharedContext: Context = {}
|
||||||
): Promise<[T[], Record<string, unknown[]>]> {
|
): Promise<[T[], Record<string, unknown[]>]> {
|
||||||
const isArray = Array.isArray(idsOrFilter)
|
const entities = await this.find({ where: filters as any }, sharedContext)
|
||||||
// TODO handle composite keys
|
|
||||||
const filter =
|
|
||||||
isArray || isString(idsOrFilter)
|
|
||||||
? {
|
|
||||||
id: {
|
|
||||||
$in: isArray ? idsOrFilter : [idsOrFilter],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: idsOrFilter
|
|
||||||
|
|
||||||
const entities = await this.find({ where: filter as any }, sharedContext)
|
|
||||||
const date = new Date()
|
const date = new Date()
|
||||||
|
|
||||||
const manager = this.getActiveManager<SqlEntityManager>(sharedContext)
|
const manager = this.getActiveManager<SqlEntityManager>(sharedContext)
|
||||||
@@ -286,17 +289,6 @@ export function mikroOrmBaseRepositoryFactory<T extends object = object>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static buildUniqueCompositeKeyValue(keys: string[], data: object) {
|
|
||||||
return keys.map((k) => data[k]).join("_")
|
|
||||||
}
|
|
||||||
|
|
||||||
static retrievePrimaryKeys(entity: EntityClass<T> | EntitySchema<T>) {
|
|
||||||
return (
|
|
||||||
(entity as EntitySchema<T>).meta?.primaryKeys ??
|
|
||||||
(entity as EntityClass<T>).prototype.__meta.primaryKeys ?? ["id"]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(data: any[], context?: Context): Promise<T[]> {
|
async create(data: any[], context?: Context): Promise<T[]> {
|
||||||
const manager = this.getActiveManager<EntityManager>(context)
|
const manager = this.getActiveManager<EntityManager>(context)
|
||||||
|
|
||||||
@@ -768,6 +760,32 @@ export function mikroOrmBaseRepositoryFactory<T extends object = object>(
|
|||||||
|
|
||||||
return orderedEntities
|
return orderedEntities
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async softDelete(
|
||||||
|
filters:
|
||||||
|
| string
|
||||||
|
| string[]
|
||||||
|
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)
|
||||||
|
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)[],
|
||||||
|
sharedContext: Context = {}
|
||||||
|
): Promise<[T[], Record<string, unknown[]>]> {
|
||||||
|
const primaryKeys =
|
||||||
|
MikroOrmAbstractBaseRepository_.retrievePrimaryKeys(entity)
|
||||||
|
|
||||||
|
const filterArray = Array.isArray(filters) ? filters : [filters]
|
||||||
|
const normalizedFilters: FilterQuery = {
|
||||||
|
$or: filterArray.map((filter) => {
|
||||||
|
// TODO: add support for composite keys
|
||||||
|
if (isString(filter)) {
|
||||||
|
return { [primaryKeys[0]]: filter }
|
||||||
|
}
|
||||||
|
|
||||||
|
return filter
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
return await super.softDelete(normalizedFilters, sharedContext)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MikroOrmAbstractBaseRepository_ as unknown as {
|
return MikroOrmAbstractBaseRepository_ as unknown as {
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ export const LINKS = {
|
|||||||
Modules.STOCK_LOCATION,
|
Modules.STOCK_LOCATION,
|
||||||
"location_id"
|
"location_id"
|
||||||
),
|
),
|
||||||
FulfillmentSetLocation: composeLinkName(
|
LocationFulfillmentSet: composeLinkName(
|
||||||
Modules.FULFILLMENT,
|
|
||||||
"fulfillment_set_id",
|
|
||||||
Modules.STOCK_LOCATION,
|
Modules.STOCK_LOCATION,
|
||||||
"location_id"
|
"stock_location_id",
|
||||||
|
Modules.FULFILLMENT,
|
||||||
|
"fulfillment_set_id"
|
||||||
),
|
),
|
||||||
OrderPromotion: composeLinkName(
|
OrderPromotion: composeLinkName(
|
||||||
Modules.ORDER,
|
Modules.ORDER,
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ import {
|
|||||||
SoftDeleteReturn,
|
SoftDeleteReturn,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
|
MapToConfig,
|
||||||
isString,
|
isString,
|
||||||
kebabCase,
|
kebabCase,
|
||||||
lowerCaseFirst,
|
lowerCaseFirst,
|
||||||
mapObjectTo,
|
mapObjectTo,
|
||||||
MapToConfig,
|
|
||||||
pluralize,
|
pluralize,
|
||||||
upperCaseFirst,
|
upperCaseFirst,
|
||||||
} from "../common"
|
} from "../common"
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ import {
|
|||||||
MedusaError,
|
MedusaError,
|
||||||
shouldForceTransaction,
|
shouldForceTransaction,
|
||||||
} from "../common"
|
} from "../common"
|
||||||
|
import { FreeTextSearchFilterKey } from "../dal"
|
||||||
import { buildQuery } from "./build-query"
|
import { buildQuery } from "./build-query"
|
||||||
import {
|
import {
|
||||||
InjectManager,
|
InjectManager,
|
||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
} from "./decorators"
|
} from "./decorators"
|
||||||
import { FreeTextSearchFilterKey } from "../dal"
|
|
||||||
|
|
||||||
type SelectorAndData = {
|
type SelectorAndData = {
|
||||||
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
|
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
|
||||||
@@ -440,10 +440,17 @@ export function internalModuleServiceFactory<
|
|||||||
|
|
||||||
@InjectTransactionManager(propertyRepositoryName)
|
@InjectTransactionManager(propertyRepositoryName)
|
||||||
async softDelete(
|
async softDelete(
|
||||||
idsOrFilter: string[] | InternalFilterQuery,
|
idsOrFilter:
|
||||||
|
| string
|
||||||
|
| string[]
|
||||||
|
| InternalFilterQuery
|
||||||
|
| InternalFilterQuery[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
||||||
if (Array.isArray(idsOrFilter) && !idsOrFilter.length) {
|
if (
|
||||||
|
(Array.isArray(idsOrFilter) && !idsOrFilter.length) ||
|
||||||
|
(!Array.isArray(idsOrFilter) && !idsOrFilter)
|
||||||
|
) {
|
||||||
return [[], {}]
|
return [[], {}]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,17 +14,17 @@ import {
|
|||||||
UpdateServiceZoneDTO,
|
UpdateServiceZoneDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
arrayDifference,
|
|
||||||
EmitEvents,
|
EmitEvents,
|
||||||
FulfillmentUtils,
|
FulfillmentUtils,
|
||||||
getSetDifference,
|
|
||||||
InjectManager,
|
InjectManager,
|
||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
isString,
|
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
Modules,
|
Modules,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
|
arrayDifference,
|
||||||
|
getSetDifference,
|
||||||
|
isString,
|
||||||
promiseAll,
|
promiseAll,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -2,54 +2,42 @@ import { Modules } from "@medusajs/modules-sdk"
|
|||||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||||
import { LINKS } from "@medusajs/utils"
|
import { LINKS } from "@medusajs/utils"
|
||||||
|
|
||||||
export const FulfillmentSetLocation: ModuleJoinerConfig = {
|
export const LocationFulfillmentSet: ModuleJoinerConfig = {
|
||||||
serviceName: LINKS.FulfillmentSetLocation,
|
serviceName: LINKS.LocationFulfillmentSet,
|
||||||
isLink: true,
|
isLink: true,
|
||||||
databaseConfig: {
|
databaseConfig: {
|
||||||
tableName: "fulfillment_set_location",
|
tableName: "location_fulfillment_set",
|
||||||
idPrefix: "fsloc",
|
idPrefix: "locfs",
|
||||||
},
|
},
|
||||||
alias: [
|
alias: [
|
||||||
{
|
{
|
||||||
name: ["fulfillment_set_location", "fulfillment_set_locations"],
|
name: ["location_fulfillment_set", "location_fulfillment_sets"],
|
||||||
args: {
|
args: {
|
||||||
entity: "LinkFulfillmentSetLocation",
|
entity: "LinkLocationFulfillmentSet",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
primaryKeys: ["id", "fulfillment_set_id", "stock_location_id"],
|
primaryKeys: ["id", "stock_location_id", "fulfillment_set_id"],
|
||||||
relationships: [
|
relationships: [
|
||||||
{
|
|
||||||
serviceName: Modules.FULFILLMENT,
|
|
||||||
primaryKey: "id",
|
|
||||||
foreignKey: "fulfillment_set_id",
|
|
||||||
alias: "fulfillment_set",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
serviceName: Modules.STOCK_LOCATION,
|
serviceName: Modules.STOCK_LOCATION,
|
||||||
primaryKey: "id",
|
primaryKey: "id",
|
||||||
foreignKey: "stock_location_id",
|
foreignKey: "stock_location_id",
|
||||||
alias: "location",
|
alias: "location",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
serviceName: Modules.FULFILLMENT,
|
||||||
|
primaryKey: "id",
|
||||||
|
foreignKey: "fulfillment_set_id",
|
||||||
|
alias: "fulfillment_set",
|
||||||
|
deleteCascade: true,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
extends: [
|
extends: [
|
||||||
{
|
|
||||||
serviceName: Modules.FULFILLMENT,
|
|
||||||
fieldAlias: {
|
|
||||||
stock_locations: "locations_link.location",
|
|
||||||
},
|
|
||||||
relationship: {
|
|
||||||
serviceName: LINKS.FulfillmentSetLocation,
|
|
||||||
primaryKey: "fulfillment_set_id",
|
|
||||||
foreignKey: "id",
|
|
||||||
alias: "locations_link",
|
|
||||||
isList: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
serviceName: Modules.STOCK_LOCATION,
|
serviceName: Modules.STOCK_LOCATION,
|
||||||
relationship: {
|
relationship: {
|
||||||
serviceName: LINKS.FulfillmentSetLocation,
|
serviceName: LINKS.LocationFulfillmentSet,
|
||||||
primaryKey: "stock_location_id",
|
primaryKey: "stock_location_id",
|
||||||
foreignKey: "id",
|
foreignKey: "id",
|
||||||
alias: "fulfillment_set_link",
|
alias: "fulfillment_set_link",
|
||||||
@@ -59,5 +47,14 @@ export const FulfillmentSetLocation: ModuleJoinerConfig = {
|
|||||||
fulfillment_sets: "fulfillment_set_link.fulfillment_set",
|
fulfillment_sets: "fulfillment_set_link.fulfillment_set",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
serviceName: Modules.FULFILLMENT,
|
||||||
|
relationship: {
|
||||||
|
serviceName: LINKS.LocationFulfillmentSet,
|
||||||
|
primaryKey: "fulfillment_set_id",
|
||||||
|
foreignKey: "id",
|
||||||
|
alias: "locations_link",
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,8 @@ export * from "./cart-payment-collection"
|
|||||||
export * from "./cart-promotion"
|
export * from "./cart-promotion"
|
||||||
export * from "./cart-region"
|
export * from "./cart-region"
|
||||||
export * from "./cart-sales-channel"
|
export * from "./cart-sales-channel"
|
||||||
export * from "./fulfillment-set-location"
|
|
||||||
export * from "./inventory-level-stock-location"
|
export * from "./inventory-level-stock-location"
|
||||||
|
export * from "./location-fulfillment-set"
|
||||||
export * from "./order-customer"
|
export * from "./order-customer"
|
||||||
export * from "./order-promotion"
|
export * from "./order-promotion"
|
||||||
export * from "./order-region"
|
export * from "./order-region"
|
||||||
@@ -18,3 +18,4 @@ export * from "./region-payment-provider"
|
|||||||
export * from "./sales-channel-location"
|
export * from "./sales-channel-location"
|
||||||
export * from "./shipping-option-price-set"
|
export * from "./shipping-option-price-set"
|
||||||
export * from "./store-default-currency"
|
export * from "./store-default-currency"
|
||||||
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
|
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||||
|
import { LINKS } from "@medusajs/utils"
|
||||||
|
|
||||||
|
export const LocationFulfillmentSet: ModuleJoinerConfig = {
|
||||||
|
serviceName: LINKS.LocationFulfillmentSet,
|
||||||
|
isLink: true,
|
||||||
|
databaseConfig: {
|
||||||
|
tableName: "location_fulfillment_set",
|
||||||
|
idPrefix: "locfs",
|
||||||
|
},
|
||||||
|
alias: [
|
||||||
|
{
|
||||||
|
name: ["location_fulfillment_set", "location_fulfillment_sets"],
|
||||||
|
args: {
|
||||||
|
entity: "LinkLocationFulfillmentSet",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
primaryKeys: ["id", "stock_location_id", "fulfillment_set_id"],
|
||||||
|
relationships: [
|
||||||
|
{
|
||||||
|
serviceName: Modules.STOCK_LOCATION,
|
||||||
|
primaryKey: "id",
|
||||||
|
foreignKey: "stock_location_id",
|
||||||
|
alias: "location",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceName: Modules.FULFILLMENT,
|
||||||
|
primaryKey: "id",
|
||||||
|
foreignKey: "fulfillment_set_id",
|
||||||
|
alias: "fulfillment_set",
|
||||||
|
deleteCascade: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
extends: [
|
||||||
|
{
|
||||||
|
serviceName: Modules.STOCK_LOCATION,
|
||||||
|
relationship: {
|
||||||
|
serviceName: LINKS.LocationFulfillmentSet,
|
||||||
|
primaryKey: "stock_location_id",
|
||||||
|
foreignKey: "id",
|
||||||
|
alias: "fulfillment_set_link",
|
||||||
|
isList: true,
|
||||||
|
},
|
||||||
|
fieldAlias: {
|
||||||
|
fulfillment_sets: "fulfillment_set_link.fulfillment_set",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceName: Modules.FULFILLMENT,
|
||||||
|
relationship: {
|
||||||
|
serviceName: LINKS.LocationFulfillmentSet,
|
||||||
|
primaryKey: "fulfillment_set_id",
|
||||||
|
foreignKey: "id",
|
||||||
|
alias: "locations_link",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import moduleSchema from "./schema"
|
|||||||
|
|
||||||
export const LinkableKeys = {
|
export const LinkableKeys = {
|
||||||
stock_location_id: StockLocation.name,
|
stock_location_id: StockLocation.name,
|
||||||
|
location_id: StockLocation.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
const entityLinkableKeysMap: MapToConfig = {}
|
const entityLinkableKeysMap: MapToConfig = {}
|
||||||
@@ -21,10 +22,7 @@ export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
|||||||
export const joinerConfig: ModuleJoinerConfig = {
|
export const joinerConfig: ModuleJoinerConfig = {
|
||||||
serviceName: Modules.STOCK_LOCATION,
|
serviceName: Modules.STOCK_LOCATION,
|
||||||
primaryKeys: ["id"],
|
primaryKeys: ["id"],
|
||||||
linkableKeys: {
|
linkableKeys: LinkableKeys,
|
||||||
stock_location_id: StockLocation.name,
|
|
||||||
location_id: StockLocation.name,
|
|
||||||
},
|
|
||||||
schema: moduleSchema,
|
schema: moduleSchema,
|
||||||
alias: [
|
alias: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
|
import {
|
||||||
|
DALUtils,
|
||||||
|
Searchable,
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
BeforeCreate,
|
BeforeCreate,
|
||||||
Entity,
|
Entity,
|
||||||
|
Filter,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OnInit,
|
OnInit,
|
||||||
PrimaryKey,
|
PrimaryKey,
|
||||||
Property,
|
Property,
|
||||||
} from "@mikro-orm/core"
|
} from "@mikro-orm/core"
|
||||||
import {
|
|
||||||
createPsqlIndexStatementHelper,
|
|
||||||
generateEntityId,
|
|
||||||
Searchable,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
|
|
||||||
import { StockLocationAddress } from "./stock-location-address"
|
import { StockLocationAddress } from "./stock-location-address"
|
||||||
|
|
||||||
@@ -21,6 +23,7 @@ const StockLocationDeletedAtIndex = createPsqlIndexStatementHelper({
|
|||||||
})
|
})
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||||
export class StockLocation {
|
export class StockLocation {
|
||||||
@PrimaryKey({ columnType: "text" })
|
@PrimaryKey({ columnType: "text" })
|
||||||
id: string
|
id: string
|
||||||
|
|||||||
Reference in new issue
Block a user