chore(medusa): Add transaction on mutation actions (2) (#1855)
**What** Wrap all actions that require the usage of an atomic phase into a transaction from the handler **Info** The following end points have been removed since that they rely on non existing stuff and can't be used and are not used admin - create-order admin - delete order metadata admin - set region metadata admin - remove region metadata Fixes CORE-358
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { StoreService } from "../../../../services"
|
||||
import { EntityManager } from "typeorm"
|
||||
/**
|
||||
* @oas [post] /store/currencies/{code}
|
||||
* operationId: "PostStoreCurrenciesCode"
|
||||
@@ -23,6 +24,12 @@ export default async (req, res) => {
|
||||
const { currency_code } = req.params
|
||||
|
||||
const storeService: StoreService = req.scope.resolve("storeService")
|
||||
const data = await storeService.addCurrency(currency_code)
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
const data = await manager.transaction(async (transactionManager) => {
|
||||
return await storeService
|
||||
.withTransaction(transactionManager)
|
||||
.addCurrency(currency_code)
|
||||
})
|
||||
|
||||
res.status(200).json({ store: data })
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { StoreService } from "../../../../services"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [delete] /store/currencies/{code}
|
||||
@@ -24,6 +25,12 @@ export default async (req, res) => {
|
||||
const { currency_code } = req.params
|
||||
|
||||
const storeService: StoreService = req.scope.resolve("storeService")
|
||||
const data = await storeService.removeCurrency(currency_code)
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
const data = await manager.transaction(async (transactionManager) => {
|
||||
return await storeService
|
||||
.withTransaction(transactionManager)
|
||||
.removeCurrency(currency_code)
|
||||
})
|
||||
|
||||
res.status(200).json({ store: data })
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { IsArray, IsOptional, IsString, IsObject } from "class-validator"
|
||||
import { StoreService } from "../../../../services"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [post] /store
|
||||
@@ -45,7 +46,12 @@ export default async (req, res) => {
|
||||
|
||||
const storeService: StoreService = req.scope.resolve("storeService")
|
||||
|
||||
const store = await storeService.update(validatedBody)
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
const store = await manager.transaction(async (transactionManager) => {
|
||||
return await storeService
|
||||
.withTransaction(transactionManager)
|
||||
.update(validatedBody)
|
||||
})
|
||||
|
||||
res.status(200).json({ store })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user