express-sweet-generator 2.0.6 → 2.0.8

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/README.md CHANGED
@@ -143,8 +143,10 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
143
143
  │ ├── config.js
144
144
  │ ├── database.js
145
145
  │ └── view.js
146
- ├── exceptions
147
- │ └── UserNotFound.js
146
+ ├── errors
147
+ │ └── NotFoundError.js
148
+ ├── middlewares
149
+ │ └── checkValidationResult.js
148
150
  ├── models
149
151
  │ ├── BookModel.js
150
152
  │ ├── CommentModel.js
@@ -159,8 +161,9 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
159
161
  │ └── api
160
162
  │ └── users.js
161
163
  ├── shared
162
- │ ├── CustomValidation.js
163
- │ └── empty.js
164
+ │ └── isEmpty.js
165
+ ├── validators
166
+ │ └── isValidImageDataUrl.js
164
167
  └── views
165
168
  ├── edit-personal.hbs
166
169
  ├── error.hbs
@@ -170,7 +173,10 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
170
173
  ├── layout
171
174
  │ └── default.hbs
172
175
  └── partials
173
- └── .gitkeep
176
+ │ └── .gitkeep
177
+ └── errors
178
+ ├── 404.hbs
179
+ └── 500.hbs
174
180
  ```
175
181
 
176
182
  ## Author
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "EXPRESS SWEET application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Custom error class for "Not Found" errors.
3
+ */
4
+ module.exports = class extends Error {
5
+ /**
6
+ * Creates a new NotFoundError instance.
7
+ * @param {string} [message='The requested record could not be found.'] - The error message.
8
+ */
9
+ constructor(message = 'The requested record could not be found.') {
10
+ super(message);
11
+ this.name = 'NotFoundError';
12
+ this.statusCode = 404; // HTTP status code for "Not Found"
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ const {validationResult} = require('express-validator');
2
+
3
+ /**
4
+ * Check express-validator results. Returns 400 HTTP status if parameter is invalid.
5
+ */
6
+ module.exports = (req, res, next) => {
7
+ const result = validationResult(req);
8
+ if (result.isEmpty())
9
+ next();
10
+ else
11
+ res.status(400).end();
12
+ // res.status(400).json({errors: result.array()});
13
+ }
@@ -1,6 +1,6 @@
1
1
  const expressExtension = require('express-sweet');
2
2
  const {Media} = require('nodejs-shared');
3
- const UserNotFound = require('../exceptions/UserNotFound');
3
+ const NotFoundError = require('../errors/NotFoundError');
4
4
 
5
5
  module.exports = class extends expressExtension.database.Model {
6
6
  static get table() {
@@ -123,7 +123,7 @@ module.exports = class extends expressExtension.database.Model {
123
123
  }, set);
124
124
  const user = await this.getUser(userId);
125
125
  if (!user)
126
- throw new UserNotFound();
126
+ throw new NotFoundError();
127
127
  transaction = await super.begin();
128
128
  user.email = set.email;
129
129
  user.name = set.name;