@misterzik/espressojs 3.1.19 → 3.2.0
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@misterzik/espressojs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
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
|
@@ -9,15 +9,17 @@
|
|
|
9
9
|
|
|
10
10
|
const express = require("express");
|
|
11
11
|
const router = express.Router();
|
|
12
|
-
const
|
|
13
|
-
router.get("/v1/", (req, res) => {
|
|
14
|
-
getAPI(req, res);
|
|
15
|
-
});
|
|
16
|
-
router.get("/v1/:item", (req, res, next) => {
|
|
17
|
-
getItem(req, res, req.params.item);
|
|
18
|
-
});
|
|
19
|
-
router.get("/v1/:item/:itemId", (req, res, next) => {
|
|
20
|
-
getItemId(req, res, req.params.item, req.params.itemId);
|
|
21
|
-
});
|
|
12
|
+
const configuration = require("../../server");
|
|
22
13
|
|
|
23
|
-
|
|
14
|
+
// const { getAPI, getItem, getItemId } = require("../utils");
|
|
15
|
+
// router.get("/v1/", (req, res) => {
|
|
16
|
+
// getAPI(req, res);
|
|
17
|
+
// });
|
|
18
|
+
// router.get("/v1/:item", (req, res, next) => {
|
|
19
|
+
// getItem(req, res, req.params.item);
|
|
20
|
+
// });
|
|
21
|
+
// router.get("/v1/:item/:itemId", (req, res, next) => {
|
|
22
|
+
// getItemId(req, res, req.params.item, req.params.itemId);
|
|
23
|
+
// });
|
|
24
|
+
|
|
25
|
+
module.exports = { router, configuration };
|
package/routes/db/index.js
CHANGED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* _| _| _| _| _|_|_|
|
|
3
|
-
* _| _| _|_| _|_| _| _|
|
|
4
|
-
* _| _| _| _| _| _| _|
|
|
5
|
-
* _| _| _| _| _| _|
|
|
6
|
-
* _| _| _| _|_|_|
|
|
7
|
-
* EspressoJS - EspressoJS / Espresso is your one-stop
|
|
8
|
-
* Express Configuration starting point
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const Client = require("../../models/client.model.js");
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Retrieve and return all clients from the collection.
|
|
15
|
-
* @param {*} req - Request data
|
|
16
|
-
* @param {*} res - Response data
|
|
17
|
-
*/
|
|
18
|
-
exports.findAll = (req, res) => {
|
|
19
|
-
Client.find()
|
|
20
|
-
.then((clients) => {
|
|
21
|
-
res.send(clients);
|
|
22
|
-
})
|
|
23
|
-
.catch((err) => {
|
|
24
|
-
res.status(500).send({
|
|
25
|
-
message: err.message || "Error occurred while retrieving clients.",
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Create and save a new client to the collection.
|
|
32
|
-
* @param {*} req - Request data
|
|
33
|
-
* @param {*} res - Response data
|
|
34
|
-
*/
|
|
35
|
-
exports.create = (req, res) => {
|
|
36
|
-
if (!req.body.email) {
|
|
37
|
-
return res.status(400).send({
|
|
38
|
-
message: "Email cannot be an empty field.",
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const client = new Client({
|
|
43
|
-
name: req.body.name || "John Doe",
|
|
44
|
-
email: req.body.email,
|
|
45
|
-
location: req.body.location,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
client
|
|
49
|
-
.save()
|
|
50
|
-
.then((data) => {
|
|
51
|
-
res.send(data);
|
|
52
|
-
})
|
|
53
|
-
.catch((err) => {
|
|
54
|
-
res.status(500).send({
|
|
55
|
-
message: err.message || "Error occurred while creating the client.",
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Find a single client by clientId.
|
|
62
|
-
* @param {*} req - Request data
|
|
63
|
-
* @param {*} res - Response data
|
|
64
|
-
*/
|
|
65
|
-
exports.findOne = (req, res) => {
|
|
66
|
-
Client.findById(req.params.clientId)
|
|
67
|
-
.then((client) => {
|
|
68
|
-
if (!client) {
|
|
69
|
-
return res.status(404).send({
|
|
70
|
-
message: "Client not found with id " + req.params.clientId,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
res.send(client);
|
|
74
|
-
})
|
|
75
|
-
.catch((err) => {
|
|
76
|
-
if (err.kind === "ObjectId") {
|
|
77
|
-
return res.status(404).send({
|
|
78
|
-
message: "Client not found with id " + req.params.clientId,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return res.status(500).send({
|
|
82
|
-
message: "Error retrieving client with id " + req.params.clientId,
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Update a client identified by clientId.
|
|
89
|
-
* @param {*} req - Request data
|
|
90
|
-
* @param {*} res - Response data
|
|
91
|
-
*/
|
|
92
|
-
exports.update = (req, res) => {
|
|
93
|
-
if (!req.body.email) {
|
|
94
|
-
return res.status(400).send({
|
|
95
|
-
message: "Client content cannot be empty",
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
Client.findByIdAndUpdate(
|
|
100
|
-
req.params.clientId,
|
|
101
|
-
{
|
|
102
|
-
name: req.body.name || "John Doe",
|
|
103
|
-
email: req.body.email,
|
|
104
|
-
location: req.body.location,
|
|
105
|
-
},
|
|
106
|
-
{ new: true }
|
|
107
|
-
)
|
|
108
|
-
.then((client) => {
|
|
109
|
-
if (!client) {
|
|
110
|
-
return res.status(404).send({
|
|
111
|
-
message: "Client not found with id " + req.params.clientId,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
res.send(client);
|
|
115
|
-
})
|
|
116
|
-
.catch((err) => {
|
|
117
|
-
if (err.kind === "ObjectId") {
|
|
118
|
-
return res.status(404).send({
|
|
119
|
-
message: "Client not found with id " + req.params.clientId,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return res.status(500).send({
|
|
123
|
-
message: "Error updating client with id " + req.params.clientId,
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Delete a client by clientId.
|
|
130
|
-
* @param {*} req - Request data
|
|
131
|
-
* @param {*} res - Response data
|
|
132
|
-
*/
|
|
133
|
-
exports.delete = (req, res) => {
|
|
134
|
-
Client.findByIdAndRemove(req.params.clientId)
|
|
135
|
-
.then((client) => {
|
|
136
|
-
if (!client) {
|
|
137
|
-
return res.status(404).send({
|
|
138
|
-
message: "Client not found with id " + req.params.clientId,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
res.send({ message: "Client deleted successfully!" });
|
|
142
|
-
})
|
|
143
|
-
.catch((err) => {
|
|
144
|
-
if (err.kind === "ObjectId" || err.name === "NotFound") {
|
|
145
|
-
return res.status(404).send({
|
|
146
|
-
message: "Client not found with id " + req.params.clientId,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
return res.status(500).send({
|
|
150
|
-
message: "Could not delete client with id " + req.params.clientId,
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
};
|