diff --git a/.changeset/rare-eggs-draw.md b/.changeset/rare-eggs-draw.md new file mode 100644 index 0000000..f2ca392 --- /dev/null +++ b/.changeset/rare-eggs-draw.md @@ -0,0 +1,5 @@ +--- +'@crystallize/import-utilities': minor +--- + +fix the move of an existing item in children diff --git a/src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts b/src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts index f4290c0..0ccb7a6 100644 --- a/src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts +++ b/src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts @@ -17,6 +17,7 @@ import { EVENT_NAMES, ItemEventPayloadCreatedOrUpdated, getItemVersionsForLanguages, + getTenantRootItemId, getTranslation, validShapeIdentifier, } from '../utils' @@ -546,7 +547,7 @@ export async function createOrUpdateItem( context, }) } - + const realRootItemId = await getTenantRootItemId(context) if (item._options?.moveToRoot) { if (item._parentId !== rootItemId) { await context.callPIM({ @@ -559,7 +560,7 @@ export async function createOrUpdateItem( item._exists && item._parentId !== parentId && itemId !== parentId && - parentId !== rootItemId // Do not move items to root unless _moveToRoot is set + parentId !== realRootItemId // Do not move items to root unless _moveToRoot is set ) { /** * Move the item if it is a part of a children array, diff --git a/src/bootstrap-tenant/bootstrapper/items/handleItem.ts b/src/bootstrap-tenant/bootstrapper/items/handleItem.ts index 7ee6461..7a02a93 100644 --- a/src/bootstrap-tenant/bootstrapper/items/handleItem.ts +++ b/src/bootstrap-tenant/bootstrapper/items/handleItem.ts @@ -19,9 +19,9 @@ export async function handleItem( if (!item) { return finishedItems } - let parentId = rootItemId + // updating the id and parentId of the item from the DB const itemAndParentId = await getItemId({ context, externalReference: item.externalReference, @@ -33,6 +33,7 @@ export async function handleItem( item.id = itemAndParentId.itemId item._parentId = itemAndParentId.parentId + // if that's mention in the spec, we take the parent id if (item.parentExternalReference || item.parentCataloguePath) { const parentItemAndParentId = await getItemId({ context,