@misterzik/espressojs 3.1.17 → 3.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/routes/api/index.js +1 -44
- package/routes/db/index.js +23 -22
- package/routes/index.js +8 -4
- package/routes/utils/index.js +42 -0
- package/server/controllers/index.js +166 -0
- package/server/models/client.model.js +1 -1
- package/server/utils/espresso-cli.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@misterzik/espressojs",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.19",
|
|
4
4
|
"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.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
package/routes/api/index.js
CHANGED
|
@@ -8,51 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
const express = require("express");
|
|
11
|
-
const axios = require("axios");
|
|
12
11
|
const router = express.Router();
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const getAPI = (req, res) => {
|
|
16
|
-
axios
|
|
17
|
-
.get(configuration.api.uri, configuration.api.configs)
|
|
18
|
-
.then(function (response) {
|
|
19
|
-
if (response.status == 200) {
|
|
20
|
-
res.json(response.data);
|
|
21
|
-
} else if (response.status == 400) {
|
|
22
|
-
res.json({ message: "400" });
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
.catch((err) => res.send(err));
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const getItem = (req, res, params) => {
|
|
29
|
-
axios
|
|
30
|
-
.get(configuration.api.uri + "/" + params, configuration.api.configs)
|
|
31
|
-
.then(function (response) {
|
|
32
|
-
if (response.status === 200) {
|
|
33
|
-
res.json(response.data);
|
|
34
|
-
} else if (response.status === 400) {
|
|
35
|
-
res.json({ message: "400" });
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
.catch((err) => res.send(err));
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const getItemId = (req, res, params, paramsId) => {
|
|
42
|
-
axios
|
|
43
|
-
.get(
|
|
44
|
-
configuration.api.uri + params + "/" + paramsId + "/",
|
|
45
|
-
configuration.api.configs
|
|
46
|
-
)
|
|
47
|
-
.then(function (response) {
|
|
48
|
-
if (response.status === 200) {
|
|
49
|
-
res.json(response.data);
|
|
50
|
-
} else if (response.status === 400) {
|
|
51
|
-
res.json({ message: "400" });
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
.catch((err) => res.send(err));
|
|
55
|
-
};
|
|
12
|
+
const { getAPI, getItem, getItemId } = require("../utils");
|
|
56
13
|
router.get("/v1/", (req, res) => {
|
|
57
14
|
getAPI(req, res);
|
|
58
15
|
});
|
package/routes/db/index.js
CHANGED
|
@@ -10,27 +10,28 @@
|
|
|
10
10
|
* @param {*} app - Vimedev.com Labs
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
const clientController = require("./controllers");
|
|
14
|
+
const url = "/api/clients/";
|
|
15
|
+
|
|
13
16
|
module.exports = (app) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
app.post(url,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
app.get(url,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
app.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
app.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
app.delete(url + ":clientId", clientRouter.delete);
|
|
17
|
+
/* Get All */
|
|
18
|
+
app.get(url, (req, res) => {
|
|
19
|
+
clientController.findAll("client", req, res);
|
|
20
|
+
});
|
|
21
|
+
/* Create */
|
|
22
|
+
app.post(url, (req, res) => {
|
|
23
|
+
clientController.create("client", req, res);
|
|
24
|
+
});
|
|
25
|
+
/* Retrieve a single Note with clientId */
|
|
26
|
+
app.get(url + ":clientId", (req, res) => {
|
|
27
|
+
clientController.findOne("client", req, res);
|
|
28
|
+
});
|
|
29
|
+
/** Update a Note with clientId */
|
|
30
|
+
app.put(url + ":clientId", (req, res) => {
|
|
31
|
+
clientController.update("client", req, res);
|
|
32
|
+
});
|
|
33
|
+
/* Delete a Note with clientId */
|
|
34
|
+
app.delete(url + ":clientId", (req, res) => {
|
|
35
|
+
clientController.delete("client", req, res);
|
|
36
|
+
});
|
|
36
37
|
};
|
package/routes/index.js
CHANGED
|
@@ -9,17 +9,21 @@
|
|
|
9
9
|
* @param {*} app - Vimedev.com Labs
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
const Path = require("path");
|
|
13
|
+
const configuration = require("../server");
|
|
14
|
+
const api = require("./api");
|
|
15
|
+
const db = require("./db");
|
|
16
|
+
|
|
12
17
|
module.exports = (app) => {
|
|
13
|
-
const Path = require("path");
|
|
14
|
-
const configuration = require("../server");
|
|
15
|
-
const api = require("./api");
|
|
16
18
|
app.get("/", function (res) {
|
|
17
19
|
res.sendFile("index.html", { root: Path.join("./public") });
|
|
18
20
|
});
|
|
19
21
|
if (configuration.api_isEnabled === true) {
|
|
20
22
|
app.use("/api", api);
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
if (configuration.mongo_isEnabled === true) {
|
|
25
|
+
db(app);
|
|
26
|
+
}
|
|
23
27
|
app.use(function (req, res, next) {
|
|
24
28
|
res.status(404).send("404 - Sorry can't find that!");
|
|
25
29
|
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
const configuration = require("../../server");
|
|
3
|
+
|
|
4
|
+
const handleResponse = (res, response) => {
|
|
5
|
+
if (response.status === 200) {
|
|
6
|
+
res.json(response.data);
|
|
7
|
+
} else if (response.status === 400) {
|
|
8
|
+
res.json({ message: "400" });
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getAPI = (req, res) => {
|
|
13
|
+
axios
|
|
14
|
+
.get(configuration.api.uri, configuration.api.configs)
|
|
15
|
+
.then(function (response) {
|
|
16
|
+
handleResponse(res, response);
|
|
17
|
+
})
|
|
18
|
+
.catch((err) => res.send(err));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getItem = (req, res, params) => {
|
|
22
|
+
axios
|
|
23
|
+
.get(configuration.api.uri + "/" + params, configuration.api.configs)
|
|
24
|
+
.then(function (response) {
|
|
25
|
+
handleResponse(res, response);
|
|
26
|
+
})
|
|
27
|
+
.catch((err) => res.send(err));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getItemId = (req, res, params, paramsId) => {
|
|
31
|
+
axios
|
|
32
|
+
.get(
|
|
33
|
+
configuration.api.uri + params + "/" + paramsId + "/",
|
|
34
|
+
configuration.api.configs
|
|
35
|
+
)
|
|
36
|
+
.then(function (response) {
|
|
37
|
+
handleResponse(res, response);
|
|
38
|
+
})
|
|
39
|
+
.catch((err) => res.send(err));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = { getAPI, getItem, getItemId };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieve and return all clients from the collection.
|
|
3
|
+
* @param {string} clientName - Name of the client model
|
|
4
|
+
* @param {*} req - Request data
|
|
5
|
+
* @param {*} res - Response data
|
|
6
|
+
*/
|
|
7
|
+
exports.findAll = (clientName, req, res) => {
|
|
8
|
+
const PropertyName = require(`../../models/${clientName}.model.js`);
|
|
9
|
+
|
|
10
|
+
PropertyName.find()
|
|
11
|
+
.then((clients) => {
|
|
12
|
+
res.send(clients);
|
|
13
|
+
})
|
|
14
|
+
.catch((err) => {
|
|
15
|
+
res.status(500).send({
|
|
16
|
+
message:
|
|
17
|
+
err.message ||
|
|
18
|
+
`Error occurred while retrieving ${clientName} clients.`,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create and save a new client to the collection.
|
|
25
|
+
* @param {string} clientName - Name of the client model
|
|
26
|
+
* @param {*} req - Request data
|
|
27
|
+
* @param {*} res - Response data
|
|
28
|
+
*/
|
|
29
|
+
exports.create = (clientName, req, res) => {
|
|
30
|
+
const PropertyName = require(`../../models/${clientName}.model.js`);
|
|
31
|
+
|
|
32
|
+
if (!req.body.email) {
|
|
33
|
+
return res.status(400).send({
|
|
34
|
+
message: "Email cannot be an empty field.",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const dataProperty = new PropertyName({
|
|
39
|
+
name: req.body.name,
|
|
40
|
+
email: req.body.email,
|
|
41
|
+
location: req.body.location,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
dataProperty
|
|
45
|
+
.save()
|
|
46
|
+
.then((data) => {
|
|
47
|
+
res.send(data);
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => {
|
|
50
|
+
res.status(500).send({
|
|
51
|
+
message:
|
|
52
|
+
err.message ||
|
|
53
|
+
`Error occurred while creating ${clientName} PropertyName.`,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Find a single client by clientId.
|
|
60
|
+
* @param {string} clientName - Name of the client model
|
|
61
|
+
* @param {*} req - Request data
|
|
62
|
+
* @param {*} res - Response data
|
|
63
|
+
*/
|
|
64
|
+
exports.findOne = (clientName, req, res) => {
|
|
65
|
+
const PropertyName = require(`../../models/${clientName}.model.js`);
|
|
66
|
+
|
|
67
|
+
PropertyName.findById(req.params.clientId)
|
|
68
|
+
.then((client) => {
|
|
69
|
+
if (!client) {
|
|
70
|
+
return res.status(404).send({
|
|
71
|
+
message:
|
|
72
|
+
`${clientName} client not found with id ` + req.params.clientId,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
res.send(client);
|
|
76
|
+
})
|
|
77
|
+
.catch((err) => {
|
|
78
|
+
if (err.kind === "ObjectId") {
|
|
79
|
+
return res.status(404).send({
|
|
80
|
+
message:
|
|
81
|
+
`${clientName} client not found with id ` + req.params.clientId,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return res.status(500).send({
|
|
85
|
+
message: "Error retrieving client with id " + req.params.clientId,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Update a client identified by clientId.
|
|
92
|
+
* @param {string} clientName - Name of the client model
|
|
93
|
+
* @param {*} req - Request data
|
|
94
|
+
* @param {*} res - Response data
|
|
95
|
+
*/
|
|
96
|
+
exports.update = (clientName, req, res) => {
|
|
97
|
+
const PropertyName = require(`../../models/${clientName}.model.js`);
|
|
98
|
+
|
|
99
|
+
if (!req.body.email) {
|
|
100
|
+
return res.status(400).send({
|
|
101
|
+
message: "Client content cannot be empty",
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
PropertyName.findByIdAndUpdate(
|
|
106
|
+
req.params.clientId,
|
|
107
|
+
{
|
|
108
|
+
name: req.body.name || "John Doe",
|
|
109
|
+
email: req.body.email,
|
|
110
|
+
location: req.body.location,
|
|
111
|
+
},
|
|
112
|
+
{ new: true }
|
|
113
|
+
)
|
|
114
|
+
.then((client) => {
|
|
115
|
+
if (!client) {
|
|
116
|
+
return res.status(404).send({
|
|
117
|
+
message:
|
|
118
|
+
`${clientName} client not found with id ` + req.params.clientId,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
res.send(client);
|
|
122
|
+
})
|
|
123
|
+
.catch((err) => {
|
|
124
|
+
if (err.kind === "ObjectId") {
|
|
125
|
+
return res.status(404).send({
|
|
126
|
+
message:
|
|
127
|
+
`${clientName} client not found with id ` + req.params.clientId,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return res.status(500).send({
|
|
131
|
+
message: "Error updating client with id " + req.params.clientId,
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Delete a client by clientId.
|
|
138
|
+
* @param {string} clientName - Name of the client model
|
|
139
|
+
* @param {*} req - Request data
|
|
140
|
+
* @param {*} res - Response data
|
|
141
|
+
*/
|
|
142
|
+
exports.delete = (clientName, req, res) => {
|
|
143
|
+
const PropertyName = require(`../../models/${clientName}.model.js`);
|
|
144
|
+
|
|
145
|
+
PropertyName.findByIdAndRemove(req.params.clientId)
|
|
146
|
+
.then((client) => {
|
|
147
|
+
if (!client) {
|
|
148
|
+
return res.status(404).send({
|
|
149
|
+
message:
|
|
150
|
+
`${clientName} client not found with id ` + req.params.clientId,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
res.send({ message: "Client deleted successfully!" });
|
|
154
|
+
})
|
|
155
|
+
.catch((err) => {
|
|
156
|
+
if (err.kind === "ObjectId" || err.name === "NotFound") {
|
|
157
|
+
return res.status(404).send({
|
|
158
|
+
message:
|
|
159
|
+
`${clientName} client not found with id ` + req.params.clientId,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return res.status(500).send({
|
|
163
|
+
message: "Could not delete client with id " + req.params.clientId,
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
@@ -28,7 +28,7 @@ Running ....
|
|
|
28
28
|
|
|
29
29
|
Instance Config:
|
|
30
30
|
Configuration: ${cfgB.instance}
|
|
31
|
-
Endpoint: localhost:${cfgB.port}
|
|
31
|
+
Endpoint: http://localhost:${cfgB.port}
|
|
32
32
|
JSON:`,
|
|
33
33
|
cfgB,
|
|
34
34
|
`\n\nTo stop process press CTRL+C`
|
|
@@ -59,7 +59,7 @@ function envCommand(argv) {
|
|
|
59
59
|
} else {
|
|
60
60
|
console.warn("Config already saved...");
|
|
61
61
|
}
|
|
62
|
-
writeConfigFile(cfgB)
|
|
62
|
+
writeConfigFile(cfgB);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
yargs.command({
|