Ruta; Funciona el endpoint
This commit is contained in:
@@ -10,11 +10,25 @@ http:
|
|||||||
type: json
|
type: json
|
||||||
data: |-
|
data: |-
|
||||||
{
|
{
|
||||||
"cardId": "",
|
"card_id": "1234",
|
||||||
"override": false
|
"override": false
|
||||||
}
|
}
|
||||||
auth: inherit
|
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:
|
settings:
|
||||||
encodeUrl: true
|
encodeUrl: true
|
||||||
timeout: 0
|
timeout: 0
|
||||||
@@ -31,7 +45,7 @@ examples:
|
|||||||
type: json
|
type: json
|
||||||
data: |-
|
data: |-
|
||||||
{
|
{
|
||||||
"cardId": "",
|
"card_id": "",
|
||||||
"override": false
|
"override": false
|
||||||
}
|
}
|
||||||
response:
|
response:
|
||||||
@@ -58,7 +72,7 @@ examples:
|
|||||||
type: json
|
type: json
|
||||||
data: |-
|
data: |-
|
||||||
{
|
{
|
||||||
"cardId": "",
|
"card_id": "",
|
||||||
"override": false
|
"override": false
|
||||||
}
|
}
|
||||||
response:
|
response:
|
||||||
@@ -85,7 +99,7 @@ examples:
|
|||||||
type: json
|
type: json
|
||||||
data: |-
|
data: |-
|
||||||
{
|
{
|
||||||
"cardId": "",
|
"card_id": "",
|
||||||
"override": false
|
"override": false
|
||||||
}
|
}
|
||||||
response:
|
response:
|
||||||
@@ -93,4 +107,7 @@ examples:
|
|||||||
statusText: Internal Server Error
|
statusText: Internal Server Error
|
||||||
body:
|
body:
|
||||||
type: text
|
type: text
|
||||||
data: ""
|
data: |-
|
||||||
|
{
|
||||||
|
"error": ""
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ http:
|
|||||||
url: "{{baseUrl}}/health"
|
url: "{{baseUrl}}/health"
|
||||||
auth: inherit
|
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:
|
settings:
|
||||||
encodeUrl: true
|
encodeUrl: true
|
||||||
timeout: 0
|
timeout: 0
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
name: Local development server
|
name: Local development server
|
||||||
|
color: "#2E8A54"
|
||||||
variables:
|
variables:
|
||||||
- name: baseUrl
|
- name: baseUrl
|
||||||
value: http://localhost:3000
|
value: http://localhost:3000
|
||||||
@@ -38,7 +38,7 @@ export class NfcController {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.status(200).json(useCaseRes)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ export class NfcUsecases {
|
|||||||
private ctx: ServerContext;
|
private ctx: ServerContext;
|
||||||
private nfcRepository: NfcRepository;
|
private nfcRepository: NfcRepository;
|
||||||
|
|
||||||
constructor(
|
constructor(args: {
|
||||||
serverContext: ServerContext,
|
serverContext: ServerContext,
|
||||||
nfcRepository: NfcRepository
|
nfcRepository: NfcRepository
|
||||||
) {
|
}) {
|
||||||
this.ctx = serverContext
|
this.ctx = args.serverContext
|
||||||
this.nfcRepository = nfcRepository
|
this.nfcRepository = args.nfcRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRandomDayOffset() {
|
private getRandomDayOffset() {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { BodyValidator, type Validator } from "./BodyValidator.js";
|
import { BodyValidator, type Validator } from "./BodyValidator.js";
|
||||||
|
|
||||||
const cardIdExists: Validator<{ cardId?: string }> = {
|
const cardIdExists: Validator<{ card_id?: string }> = {
|
||||||
field: "cardId",
|
field: "card_id",
|
||||||
validationFunc: (body) => body.cardId != undefined,
|
validationFunc: (body) => body.card_id != undefined,
|
||||||
errorMsg: "El campo cardId esta undefined"
|
errorMsg: "El campo card_id esta undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const baseValidator = new BodyValidator([cardIdExists])
|
export const baseValidator = new BodyValidator([cardIdExists])
|
||||||
|
|||||||
23
src/main.ts
23
src/main.ts
@@ -6,23 +6,46 @@ import { env } from './config/env.config.js';
|
|||||||
import type { ServerContext } from 'domain/ServerContext.js';
|
import type { ServerContext } from 'domain/ServerContext.js';
|
||||||
import { httpclient } from 'config/httpclient.config.js';
|
import { httpclient } from 'config/httpclient.config.js';
|
||||||
import { pgClient } from 'config/pgclient.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 PORT = env.PORT
|
||||||
const HOSTNAME = env.HOST
|
const HOSTNAME = env.HOST
|
||||||
|
|
||||||
assert(HOSTNAME != undefined)
|
assert(HOSTNAME != undefined)
|
||||||
|
|
||||||
|
// Instancias de las dependencias
|
||||||
|
|
||||||
const serverContext: ServerContext = {
|
const serverContext: ServerContext = {
|
||||||
HttpClient: httpclient,
|
HttpClient: httpclient,
|
||||||
PostgresClient: pgClient
|
PostgresClient: pgClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nfcRepository = new NfcRepository(serverContext)
|
||||||
|
|
||||||
|
const nfcUsecases = new NfcUsecases({
|
||||||
|
serverContext,
|
||||||
|
nfcRepository
|
||||||
|
})
|
||||||
|
|
||||||
|
const ncfControllers = new NfcController({
|
||||||
|
serverContext,
|
||||||
|
nfcUsecases
|
||||||
|
})
|
||||||
|
|
||||||
|
// Rutas
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/health", (req: Request, res: Response) => {
|
router.get("/health", (req: Request, res: Response) => {
|
||||||
res.json({ ok: true })
|
res.json({ ok: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.post("/nfc/generate", ncfControllers.generateActivationTag())
|
||||||
|
|
||||||
|
// Inicio de express
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|||||||
Reference in New Issue
Block a user