Ruta; Funciona el endpoint

This commit is contained in:
2026-03-10 16:34:04 +01:00
parent fb4563b44a
commit 005e66679d
7 changed files with 71 additions and 14 deletions

View File

@@ -10,11 +10,25 @@ http:
type: json
data: |-
{
"cardId": "",
"card_id": "1234",
"override": false
}
auth: inherit
runtime:
scripts:
- type: tests
code: |-
test("Should return 200", () => {
const body = res.getBody()
expect(res.getStatus()).to.equal(200)
})
test("Body should include the label", () => {
const body = res.getBody()
expect(body.label).to.be.defined()
)}
settings:
encodeUrl: true
timeout: 0
@@ -31,7 +45,7 @@ examples:
type: json
data: |-
{
"cardId": "",
"card_id": "",
"override": false
}
response:
@@ -58,7 +72,7 @@ examples:
type: json
data: |-
{
"cardId": "",
"card_id": "",
"override": false
}
response:
@@ -85,7 +99,7 @@ examples:
type: json
data: |-
{
"cardId": "",
"card_id": "",
"override": false
}
response:
@@ -93,4 +107,7 @@ examples:
statusText: Internal Server Error
body:
type: text
data: ""
data: |-
{
"error": ""
}

View File

@@ -8,6 +8,22 @@ http:
url: "{{baseUrl}}/health"
auth: inherit
runtime:
scripts:
- type: tests
code: |-
test("Should return 200", () => {
const body = res.getBody()
expect(res.getStatus()).to.equal(200)
})
test("Body should be ok:true", () => {
const body = res.getBody()
expect(body).to.eql({
ok:true
})
})
settings:
encodeUrl: true
timeout: 0

View File

@@ -1,4 +1,5 @@
name: Local development server
color: "#2E8A54"
variables:
- name: baseUrl
value: http://localhost:3000

View File

@@ -38,7 +38,7 @@ export class NfcController {
return 1;
}
res.status(200).json(useCaseRes)
return 0;
}

View File

@@ -9,12 +9,12 @@ export class NfcUsecases {
private ctx: ServerContext;
private nfcRepository: NfcRepository;
constructor(
constructor(args: {
serverContext: ServerContext,
nfcRepository: NfcRepository
) {
this.ctx = serverContext
this.nfcRepository = nfcRepository
}) {
this.ctx = args.serverContext
this.nfcRepository = args.nfcRepository
}
private getRandomDayOffset() {

View File

@@ -1,9 +1,9 @@
import { BodyValidator, type Validator } from "./BodyValidator.js";
const cardIdExists: Validator<{ cardId?: string }> = {
field: "cardId",
validationFunc: (body) => body.cardId != undefined,
errorMsg: "El campo cardId esta undefined"
const cardIdExists: Validator<{ card_id?: string }> = {
field: "card_id",
validationFunc: (body) => body.card_id != undefined,
errorMsg: "El campo card_id esta undefined"
}
export const baseValidator = new BodyValidator([cardIdExists])

View File

@@ -6,23 +6,46 @@ import { env } from './config/env.config.js';
import type { ServerContext } from 'domain/ServerContext.js';
import { httpclient } from 'config/httpclient.config.js';
import { pgClient } from 'config/pgclient.config.js';
import { NfcController } from 'aplication/Nfc.controller.js';
import { NfcUsecases } from 'aplication/Nfc.usecases.js';
import { NfcRepository } from 'infrastructure/Nfc.repository.js';
const PORT = env.PORT
const HOSTNAME = env.HOST
assert(HOSTNAME != undefined)
// Instancias de las dependencias
const serverContext: ServerContext = {
HttpClient: httpclient,
PostgresClient: pgClient
}
const nfcRepository = new NfcRepository(serverContext)
const nfcUsecases = new NfcUsecases({
serverContext,
nfcRepository
})
const ncfControllers = new NfcController({
serverContext,
nfcUsecases
})
// Rutas
const router = Router();
router.get("/health", (req: Request, res: Response) => {
res.json({ ok: true })
})
router.post("/nfc/generate", ncfControllers.generateActivationTag())
// Inicio de express
const app = express();
app.use(express.json());