051bb16dd7
* 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
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { IsNotEmpty, IsString } from "class-validator"
|
|
import NoteService from "../../../../services/note"
|
|
import { validator } from "../../../../utils/validator"
|
|
import { EntityManager } from "typeorm"
|
|
|
|
/**
|
|
* @oas [post] /notes
|
|
* operationId: "PostNotes"
|
|
* summary: "Creates a Note"
|
|
* description: "Creates a Note which can be associated with any resource as required."
|
|
* x-authenticated: true
|
|
* requestBody:
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* properties:
|
|
* resource_id:
|
|
* type: string
|
|
* description: The id of the resource which the Note relates to.
|
|
* resource_type:
|
|
* type: string
|
|
* description: The type of resource which the Note relates to.
|
|
* value:
|
|
* type: string
|
|
* description: The content of the Note to create.
|
|
* tags:
|
|
* - Note
|
|
* responses:
|
|
* 200:
|
|
* description: OK
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* properties:
|
|
* note:
|
|
* $ref: "#/components/schemas/note"
|
|
*
|
|
*/
|
|
export default async (req, res) => {
|
|
const validated = await validator(AdminPostNotesReq, req.body)
|
|
|
|
const userId: string = req.user.id || req.user.userId
|
|
|
|
const noteService: NoteService = req.scope.resolve("noteService")
|
|
|
|
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 })
|
|
}
|
|
|
|
export class AdminPostNotesReq {
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
resource_id: string
|
|
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
resource_type: string
|
|
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
value: string
|
|
}
|