fix(link-modules): recreate dismissed link (#6764)

* fix(link-modules): recreate dismissed link

* rm type

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Carlos R. L. Rodrigues
2024-03-20 15:12:48 -03:00
committed by GitHub
parent eefde48eef
commit 60070fb65f
4 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/link-modules": patch
---
Recreate dismissed link

View File

@@ -238,6 +238,35 @@ medusaIntegrationTestRunner({
}),
])
})
it("Should dismiss the link of a given pair of keys and recreate it", async function () {
await links.linkServiceName.create("123", "abc", {
extra_field: 333,
another_field: "value**",
})
await links.linkServiceName.dismiss("123", "abc")
const values = await links.linkServiceName.list()
expect(values).toHaveLength(0)
await links.linkServiceName.create("123", "abc", {
another_field: "changed",
})
const values2 = await links.linkServiceName.list()
expect(values2).toEqual([
expect.objectContaining({
product_id: "123",
inventory_item_id: "abc",
extra_field: 333,
another_field: "changed",
deleted_at: null,
}),
])
})
})
},
})

View File

@@ -37,6 +37,7 @@ export function getLinkRepository(model: EntitySchema) {
link.id,
this.joinerConfig_.databaseConfig?.idPrefix ?? "link"
)
link.deleted_at = null
return manager.create(model, link)
})

View File

@@ -84,6 +84,13 @@ export function generateEntity(
filters: {
[SoftDeletableFilterKey]: mikroOrmSoftDeletableFilterOptions,
},
hooks: {
beforeUpdate: [
(args) => {
args.entity.updated_at = new Date()
},
],
},
indexes: [
{
properties: ["id"],