feat: Typescript for API layer (#817)

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com>
Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Sebastian Rindom <seb@medusa-commerce.com>
This commit is contained in:
Oliver Windall Juhl
2021-11-18 15:19:17 +01:00
committed by GitHub
parent 55e200bf68
commit 373532ecbc
413 changed files with 20961 additions and 10353 deletions
@@ -0,0 +1,67 @@
import { IsNotEmpty, IsString } from "class-validator"
import NoteService from "../../../../services/note"
import { validator } from "../../../../utils/validator"
/**
* @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 result = await noteService.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
}