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

@@ -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());