From fb4563b44a56a3c7502f34deee5b8cb36eb7d3d8 Mon Sep 17 00:00:00 2001 From: Alvar San Martin Date: Tue, 10 Mar 2026 15:44:48 +0100 Subject: [PATCH] Generacion de docs --- docs/nfc-server/Generate activation label.yml | 96 +++++++++++++++++++ docs/nfc-server/Health check.yml | 34 +++++++ .../environments/Local development server.yml | 4 + docs/nfc-server/openapi.yaml | 90 +++++++++++++++++ src/aplication/Nfc.controller.ts | 14 ++- 5 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 docs/nfc-server/Generate activation label.yml create mode 100644 docs/nfc-server/Health check.yml create mode 100644 docs/nfc-server/environments/Local development server.yml create mode 100644 docs/nfc-server/openapi.yaml diff --git a/docs/nfc-server/Generate activation label.yml b/docs/nfc-server/Generate activation label.yml new file mode 100644 index 0000000..4e35200 --- /dev/null +++ b/docs/nfc-server/Generate activation label.yml @@ -0,0 +1,96 @@ +info: + name: Generate an activation label + type: http + seq: 2 + +http: + method: POST + url: "{{baseUrl}}/nfc/generate" + body: + type: json + data: |- + { + "cardId": "", + "override": false + } + auth: inherit + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 + +examples: + - name: 200 Response + description: Label generated or reused successfully + request: + url: "{{baseUrl}}/nfc/generate" + method: POST + body: + type: json + data: |- + { + "cardId": "", + "override": false + } + response: + status: 200 + statusText: OK + headers: + - name: Content-Type + value: application/json + body: + type: json + data: |- + { + "code": "", + "label": "", + "overriden": false, + "reused": false + } + - name: 422 Response + description: Validation error + request: + url: "{{baseUrl}}/nfc/generate" + method: POST + body: + type: json + data: |- + { + "cardId": "", + "override": false + } + response: + status: 422 + statusText: Unprocessable Entity + headers: + - name: Content-Type + value: application/json + body: + type: json + data: |- + { + "error": { + "msg": "", + "field": "" + } + } + - name: 500 Response + description: Internal server error + request: + url: "{{baseUrl}}/nfc/generate" + method: POST + body: + type: json + data: |- + { + "cardId": "", + "override": false + } + response: + status: 500 + statusText: Internal Server Error + body: + type: text + data: "" diff --git a/docs/nfc-server/Health check.yml b/docs/nfc-server/Health check.yml new file mode 100644 index 0000000..172c942 --- /dev/null +++ b/docs/nfc-server/Health check.yml @@ -0,0 +1,34 @@ +info: + name: Health check + type: http + seq: 1 + +http: + method: GET + url: "{{baseUrl}}/health" + auth: inherit + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 + +examples: + - name: 200 Response + description: Server is healthy + request: + url: "{{baseUrl}}/health" + method: GET + response: + status: 200 + statusText: OK + headers: + - name: Content-Type + value: application/json + body: + type: json + data: |- + { + "ok": false + } diff --git a/docs/nfc-server/environments/Local development server.yml b/docs/nfc-server/environments/Local development server.yml new file mode 100644 index 0000000..4742592 --- /dev/null +++ b/docs/nfc-server/environments/Local development server.yml @@ -0,0 +1,4 @@ +name: Local development server +variables: + - name: baseUrl + value: http://localhost:3000 diff --git a/docs/nfc-server/openapi.yaml b/docs/nfc-server/openapi.yaml new file mode 100644 index 0000000..3c4437c --- /dev/null +++ b/docs/nfc-server/openapi.yaml @@ -0,0 +1,90 @@ +openapi: 3.0.0 +info: + title: SF NFC Server API + description: API for managing NFC card activation codes. + version: 1.0.0 +servers: + - url: http://localhost:3000 + description: Local development server + +paths: + /health: + get: + summary: Health check + responses: + '200': + description: Server is healthy + content: + application/json: + schema: + type: object + properties: + ok: + type: boolean + + /nfc/generate: + post: + summary: Generate an activation label for an NFC card + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/GenerateLabelRequest' + responses: + '200': + description: Label generated or reused successfully + content: + application/json: + schema: + $ref: '#/components/schemas/CodeGenerationResult' + '422': + description: Validation error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '500': + description: Internal server error + +components: + schemas: + GenerateLabelRequest: + type: object + required: + - cardId + properties: + cardId: + type: string + description: Unique identifier for the NFC card + override: + type: boolean + description: Whether to force generation of a new code even if one exists + default: false + + CodeGenerationResult: + type: object + properties: + code: + type: string + description: The activation code + label: + type: string + description: The generated label content (e.g., HTML/SVG) + overriden: + type: boolean + description: True if an existing code was overridden + reused: + type: boolean + description: True if an existing code was reused + + ErrorResponse: + type: object + properties: + error: + type: object + properties: + msg: + type: string + field: + type: string diff --git a/src/aplication/Nfc.controller.ts b/src/aplication/Nfc.controller.ts index 1627255..8527a3f 100644 --- a/src/aplication/Nfc.controller.ts +++ b/src/aplication/Nfc.controller.ts @@ -2,7 +2,6 @@ import type { ServerContext } from "domain/ServerContext.js"; import type { NfcUsecases } from "./Nfc.usecases.js"; import type { Request, Response } from "express" import { baseValidator } from "./validators.js"; -import { error } from "node:console"; export class NfcController { private ctx: ServerContext; @@ -17,7 +16,7 @@ export class NfcController { } public generateActivationTag() { - return (req: Request, res: Response) => { + return async (req: Request, res: Response) => { const body = req.body const validate = baseValidator.validate(body) @@ -28,6 +27,17 @@ export class NfcController { return 1; } + const { card_id, override } = body.card_id + const pormUsecase = this.nfcUsecases.generateActivationLabel() + const useCaseRes = await pormUsecase({ card_id, override }) + + if (useCaseRes.error != undefined) { + res.status(500).json({ + error: useCaseRes.error + }) + return 1; + } + return 0;