Skip to content

Commit

Permalink
Merge pull request #24 from misterzik/development
Browse files Browse the repository at this point in the history
(Enhance)Struct:Infra-v3.1.18
  • Loading branch information
misterzik authored Jun 20, 2023
2 parents 710d3aa + 8abe1ff commit 697e5fb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 83 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@misterzik/espressojs",
"version": "3.1.17",
"version": "3.1.18",
"description": "EspressoJS Introducing Espresso.JS, your ultimate Express configuration starting point and boilerplate. With its simplicity and lack of opinionation, EspressoJS offers plug-and-play configurations built on top of Express.",
"main": "index.js",
"scripts": {
Expand Down
45 changes: 1 addition & 44 deletions routes/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,8 @@
*/

const express = require("express");
const axios = require("axios");
const router = express.Router();
const configuration = require("../../server");

const getAPI = (req, res) => {
axios
.get(configuration.api.uri, configuration.api.configs)
.then(function (response) {
if (response.status == 200) {
res.json(response.data);
} else if (response.status == 400) {
res.json({ message: "400" });
}
})
.catch((err) => res.send(err));
};

const getItem = (req, res, params) => {
axios
.get(configuration.api.uri + "/" + params, configuration.api.configs)
.then(function (response) {
if (response.status === 200) {
res.json(response.data);
} else if (response.status === 400) {
res.json({ message: "400" });
}
})
.catch((err) => res.send(err));
};

const getItemId = (req, res, params, paramsId) => {
axios
.get(
configuration.api.uri + params + "/" + paramsId + "/",
configuration.api.configs
)
.then(function (response) {
if (response.status === 200) {
res.json(response.data);
} else if (response.status === 400) {
res.json({ message: "400" });
}
})
.catch((err) => res.send(err));
};
const { getAPI, getItem, getItemId } = require("../utils");
router.get("/v1/", (req, res) => {
getAPI(req, res);
});
Expand Down
36 changes: 14 additions & 22 deletions routes/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,19 @@
* @param {*} app - Vimedev.com Labs
*/

const clientController = require("../../server/controllers/client/client.controller.js");
const { create, findAll, findOne, update } = clientController;
const url = "/api/clients/";

module.exports = (app) => {
const clientRouter = require("../../server/controllers/client/client.controller.js");
const url = "/api/clients/";
/**
* Create
*/
app.post(url, clientRouter.create);
/**
* Get All
*/
app.get(url, clientRouter.findAll);
/**
* Retrieve a single Note with clientId
*/
app.get(url + ":clientId", clientRouter.findOne);
/**
* Update a Note with clientId
*/
app.put(url + ":clientId", clientRouter.update);
/**
* Delete a Note with clientId
*/
app.delete(url + ":clientId", clientRouter.delete);
/* Create */
app.post(url, create);
/* Get All */
app.get(url, findAll);
/* Retrieve a single Note with clientId */
app.get(url + ":clientId", findOne);
/** Update a Note with clientId */
app.put(url + ":clientId", update);
/* Delete a Note with clientId */
app.delete(url + ":clientId", clientController.delete);
};
7 changes: 4 additions & 3 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
* @param {*} app - Vimedev.com Labs
*/

const Path = require("path");
const configuration = require("../server");
const api = require("./api");

module.exports = (app) => {
const Path = require("path");
const configuration = require("../server");
const api = require("./api");
app.get("/", function (res) {
res.sendFile("index.html", { root: Path.join("./public") });
});
Expand Down
42 changes: 42 additions & 0 deletions routes/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const axios = require("axios");
const configuration = require("../../server");

const handleResponse = (res, response) => {
if (response.status === 200) {
res.json(response.data);
} else if (response.status === 400) {
res.json({ message: "400" });
}
};

const getAPI = (req, res) => {
axios
.get(configuration.api.uri, configuration.api.configs)
.then(function (response) {
handleResponse(res, response);
})
.catch((err) => res.send(err));
};

const getItem = (req, res, params) => {
axios
.get(configuration.api.uri + "/" + params, configuration.api.configs)
.then(function (response) {
handleResponse(res, response);
})
.catch((err) => res.send(err));
};

const getItemId = (req, res, params, paramsId) => {
axios
.get(
configuration.api.uri + params + "/" + paramsId + "/",
configuration.api.configs
)
.then(function (response) {
handleResponse(res, response);
})
.catch((err) => res.send(err));
};

module.exports = { getAPI, getItem, getItemId };
4 changes: 2 additions & 2 deletions server/utils/espresso-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Running ....
Instance Config:
Configuration: ${cfgB.instance}
Endpoint: localhost:${cfgB.port}
Endpoint: http://localhost:${cfgB.port}
JSON:`,
cfgB,
`\n\nTo stop process press CTRL+C`
Expand Down Expand Up @@ -59,7 +59,7 @@ function envCommand(argv) {
} else {
console.warn("Config already saved...");
}
writeConfigFile(cfgB)
writeConfigFile(cfgB);
}

yargs.command({
Expand Down

0 comments on commit 697e5fb

Please sign in to comment.