chore(medusa): Add transactions in mutating actions 2 (#1853)

* chore(medusa): Add transaction on mutation actions

* chore(medusa): continue refactoring

* chore(medusa): continue refactoring

* chore(medusa): continue refactoring

* feat(medusa): update invite service mock to provide a withTransaction

* feat(medusa): Include pr feedback

* feat(medusa): Cleanup idempotent places

* feat(medusa): Cleanup idempotent places

* feat(medusa): Better Cleanup idempotent places

* feat(meudsa): cleanup transaction

* fix(medusa): Create cart transaction usage

* fix(medusa): Use the right variable

* fix(medusa): Use the right variable

* fix(medusa): Transaction usage in cart creation flow
This commit is contained in:
Adrien de Peretti
2022-08-02 10:04:43 +02:00
committed by GitHub
parent b54d5178c9
commit 051bb16dd7
68 changed files with 883 additions and 542 deletions
@@ -1,6 +1,7 @@
import { IsNotEmpty, IsString } from "class-validator"
import NoteService from "../../../../services/note"
import { validator } from "../../../../utils/validator"
import { EntityManager } from "typeorm"
/**
* @oas [post] /notes
@@ -42,11 +43,14 @@ export default async (req, res) => {
const noteService: NoteService = req.scope.resolve("noteService")
const result = await noteService.create({
resource_id: validated.resource_id,
resource_type: validated.resource_type,
value: validated.value,
author_id: userId,
const manager: EntityManager = req.scope.resolve("manager")
const result = await manager.transaction(async (transactionManager) => {
return await noteService.withTransaction(transactionManager).create({
resource_id: validated.resource_id,
resource_type: validated.resource_type,
value: validated.value,
author_id: userId,
})
})
res.status(200).json({ note: result })