From d4eef1e6c157686a664dd603333ee4f158a7df5f Mon Sep 17 00:00:00 2001 From: Makussu Date: Tue, 21 May 2024 09:31:32 +0200 Subject: [PATCH] :crying_emoji: --- index.js | 21 ++- readme.org | 2 + routes/accounts.js | 13 +- test/Swagger UI.html | 286 +++++++++++++++++++++++++++++++++++++++ test/create_account.hurl | 4 +- 5 files changed, 314 insertions(+), 12 deletions(-) create mode 100644 readme.org create mode 100644 test/Swagger UI.html diff --git a/index.js b/index.js index 21a7b44..8b567e0 100644 --- a/index.js +++ b/index.js @@ -14,11 +14,22 @@ const swaggerDocument = YAML.parse(file); app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); // Validator -// app.use(express.json()) -// app.use( -// OpenApiValidator.middleware({ -// apiSpec: './open_api.yaml', -// validateResponses: +app.use(express.json()) +app.use( + OpenApiValidator.middleware({ + apiSpec: './open_api.yaml', + validateResponses: true + }) +); + +app.use((err, req, res, next) => { + res.status(err.status || 500).json ({ + code: err.status, + message: err.message, + additionalPropl: err.errors, + }); +}); + // Routes app.use(express.json()); diff --git a/readme.org b/readme.org new file mode 100644 index 0000000..8079935 --- /dev/null +++ b/readme.org @@ -0,0 +1,2 @@ +* TODO What is account.number? +id? wtf diff --git a/routes/accounts.js b/routes/accounts.js index 3fef5b5..ba0ac61 100644 --- a/routes/accounts.js +++ b/routes/accounts.js @@ -5,6 +5,11 @@ const db = require("../dependencies"); router.get("/", (req, res) => { const accs = db.prepare("SELECT * FROM accounts").all(); + new_accs = []; + for (let i=0; i < accs.length; i++) { + accs[i]["subaccounts"] = []; + } + console.log(accs) res.send(accs); }); @@ -12,13 +17,9 @@ router.post("/", (req, res, next) => { const name = req.body.name; const des = req.body.description; const type = req.body.type; - // res.json(req.body.name); - res.send({ - 'name': name, - 'description': des, - 'type': type - }) const new_acc = db.prepare(`INSERT INTO accounts (name, qualifiedName, description, type, balance, localBalance) VALUES ('${name}', 'test','${des}', '${type}', 0, 0)`).run() + res.status(204).send() + console.log(new_acc); }); diff --git a/test/Swagger UI.html b/test/Swagger UI.html new file mode 100644 index 0000000..876b33f --- /dev/null +++ b/test/Swagger UI.html @@ -0,0 +1,286 @@ + + + + + + + Swagger UI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Buchhaltungs-API
 1.0.0 
OAS 3.0

Buchhaltungs-API für das Web-Anwendungen-Projekt

Servers
Computed URL:../api/v1

Server variables

apiVersion

+ +normal + + + + + + + + + + \ No newline at end of file diff --git a/test/create_account.hurl b/test/create_account.hurl index 9257995..a701d67 100644 --- a/test/create_account.hurl +++ b/test/create_account.hurl @@ -1,6 +1,8 @@ POST http://localhost:3000/api/v1/accounts/ { + "number": 23123, "name": "Aktiva", "description": "Girokonto bei der Musterbank eG", - "type": "default" + "type": "default", + "parentAccount": "Aktiva:Barvermögen:Bargeld" }