fix(utils): medusa internal service returned data should match typings (#12715)
FIXES SUP-1824 **What** The medusa internal service update should always return the data in the expected shape described by the interface. The medusa service should not have to handle the reshapre
This commit is contained in:
@@ -129,7 +129,7 @@ export default class AuthModuleService
|
||||
populate: true,
|
||||
})
|
||||
|
||||
return Array.isArray(data) ? serializedUsers : serializedUsers[0]
|
||||
return serializedUsers
|
||||
}
|
||||
|
||||
async register(
|
||||
@@ -206,7 +206,7 @@ export default class AuthModuleService
|
||||
AuthTypes.ProviderIdentityDTO[]
|
||||
>(updatedProviders)
|
||||
|
||||
return Array.isArray(data) ? serializedProviders : serializedProviders[0]
|
||||
return serializedProviders
|
||||
}
|
||||
|
||||
async updateProvider(
|
||||
|
||||
@@ -218,7 +218,7 @@ export default class CustomerModuleService
|
||||
populate: true,
|
||||
})
|
||||
|
||||
return isString(idsOrSelector) ? serialized[0] : serialized
|
||||
return serialized
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
|
||||
@@ -2021,9 +2021,11 @@ export default class FulfillmentModuleService
|
||||
})
|
||||
}
|
||||
|
||||
const result = await this.baseRepository_.serialize(fulfillment)
|
||||
const result = await this.baseRepository_.serialize<FulfillmentDTO>(
|
||||
fulfillment
|
||||
)
|
||||
|
||||
return Array.isArray(result) ? result[0] : result
|
||||
return result
|
||||
}
|
||||
|
||||
async retrieveFulfillmentOptions(
|
||||
|
||||
@@ -1052,7 +1052,7 @@ export default class InventoryModuleService
|
||||
context
|
||||
)
|
||||
|
||||
return result[0]
|
||||
return result
|
||||
}
|
||||
|
||||
@InjectManager()
|
||||
|
||||
@@ -359,15 +359,13 @@ export default class PaymentModuleService
|
||||
}
|
||||
)
|
||||
|
||||
paymentSession = (
|
||||
await this.paymentSessionService_.update(
|
||||
{
|
||||
id: paymentSession!.id,
|
||||
data: { ...input.data, ...providerPaymentSession.data },
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
)[0]
|
||||
paymentSession = await this.paymentSessionService_.update(
|
||||
{
|
||||
id: paymentSession!.id,
|
||||
data: { ...input.data, ...providerPaymentSession.data },
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
} catch (error) {
|
||||
if (providerPaymentSession) {
|
||||
await this.paymentProviderService_.deleteSession(input.provider_id, {
|
||||
@@ -440,7 +438,7 @@ export default class PaymentModuleService
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize(updated[0], { populate: true })
|
||||
return await this.baseRepository_.serialize(updated, { populate: true })
|
||||
}
|
||||
|
||||
@InjectManager()
|
||||
@@ -605,7 +603,7 @@ export default class PaymentModuleService
|
||||
// NOTE: currently there is no update with the provider but maybe data could be updated
|
||||
const result = await this.paymentService_.update(data, sharedContext)
|
||||
|
||||
return await this.baseRepository_.serialize<PaymentDTO>(result[0])
|
||||
return await this.baseRepository_.serialize<PaymentDTO>(result)
|
||||
}
|
||||
|
||||
// TODO: This method should return a capture, not a payment
|
||||
|
||||
@@ -285,6 +285,59 @@ moduleIntegrationTestRunner<Service>({
|
||||
)
|
||||
})
|
||||
|
||||
it("should update a product and its allowed relations using selector", async () => {
|
||||
const updateData = [
|
||||
{
|
||||
selector: {
|
||||
id: productOne.id,
|
||||
},
|
||||
data: {
|
||||
title: "update test 1",
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const products = await service.update(updateData)
|
||||
|
||||
expect(products.length).toEqual(1)
|
||||
|
||||
let result = await service.retrieve(productOne.id)
|
||||
let serialized = JSON.parse(JSON.stringify(result))
|
||||
|
||||
expect(serialized).toEqual(
|
||||
expect.objectContaining({
|
||||
id: productOne.id,
|
||||
title: "update test 1",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should update a single product and its allowed relations", async () => {
|
||||
const updateData = {
|
||||
id: productOne.id,
|
||||
title: "update test 1",
|
||||
}
|
||||
|
||||
const product = await service.update(updateData)
|
||||
|
||||
expect(product).toEqual(
|
||||
expect.objectContaining({
|
||||
id: productOne.id,
|
||||
title: "update test 1",
|
||||
})
|
||||
)
|
||||
|
||||
let result = await service.retrieve(productOne.id)
|
||||
let serialized = JSON.parse(JSON.stringify(result))
|
||||
|
||||
expect(serialized).toEqual(
|
||||
expect.objectContaining({
|
||||
id: productOne.id,
|
||||
title: "update test 1",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when id is not present", async () => {
|
||||
let error
|
||||
const updateData = [
|
||||
|
||||
Reference in New Issue
Block a user