feat(pricing, types, utils): Soft delete pricing entities (#5858)

This commit is contained in:
Philip Korsholm
2024-01-04 09:02:49 +01:00
committed by GitHub
parent 1468646b99
commit 3550750975
30 changed files with 795 additions and 159 deletions
+16 -12
View File
@@ -1,5 +1,3 @@
import { SoftDeletableFilterKey } from "./mikro-orm-soft-deletable-filter"
export const mikroOrmUpdateDeletedAtRecursively = async <
T extends object = any
>(
@@ -22,19 +20,25 @@ export const mikroOrmUpdateDeletedAtRecursively = async <
)
for (const relation of relationsToCascade) {
let collectionRelation = entity[relation.name]
let entityRelation = entity[relation.name]
if (!collectionRelation.isInitialized()) {
await collectionRelation.init()
// Handle optional relationships
if (relation.nullable && !entityRelation) {
continue
}
const relationEntities = await collectionRelation.getItems({
filters: {
[SoftDeletableFilterKey]: {
withDeleted: true,
},
},
})
const isCollection = "toArray" in entityRelation
let relationEntities: any[] = []
if (isCollection) {
if (!entityRelation.isInitialized()) {
entityRelation = await entityRelation.init({ populate: true })
}
relationEntities = entityRelation.getItems()
} else {
const initializedEntityRelation = await entityRelation.__helper?.init()
relationEntities = [initializedEntityRelation]
}
await mikroOrmUpdateDeletedAtRecursively(manager, relationEntities, value)
}