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 +11 -5
- package/package.json +1 -1
- package/templates/cjs/errors/NotFoundError.js +14 -0
- package/templates/cjs/middlewares/checkValidationResult.js +13 -0
- package/templates/cjs/models/UserModel.js +2 -2
- package/templates/cjs/public/build/editPersonal.js +98 -98
- package/templates/cjs/public/build/users.js +174 -174
- package/templates/cjs/routes/api/users.js +18 -29
- package/templates/cjs/shared/isEmpty.js +10 -0
- package/templates/cjs/validators/isValidImageDataUrl.js +16 -0
- package/templates/client/src/editPersonal.js +1 -1
- package/templates/client/src/modals/UserModal.js +1 -1
- package/templates/esm/errors/NotFoundError.js +14 -0
- package/templates/esm/middlewares/checkValidationResult.js +13 -0
- package/templates/esm/models/UserModel.js +2 -2
- package/templates/esm/public/build/editPersonal.js +98 -98
- package/templates/esm/public/build/users.js +174 -174
- package/templates/esm/routes/api/users.js +18 -29
- package/templates/esm/shared/isEmpty.js +10 -0
- package/templates/esm/validators/isValidImageDataUrl.js +16 -0
- package/templates/cjs/exceptions/UserNotFound.js +0 -6
- package/templates/cjs/shared/CustomValidation.js +0 -12
- package/templates/cjs/shared/empty.js +0 -8
- package/templates/esm/exceptions/UserNotFound.js +0 -6
- package/templates/esm/shared/CustomValidation.js +0 -12
- package/templates/esm/shared/empty.js +0 -8
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
|
-
├──
|
|
147
|
-
│ └──
|
|
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
|
-
│
|
|
163
|
-
|
|
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
|
-
|
|
176
|
+
│ └── .gitkeep
|
|
177
|
+
└── errors
|
|
178
|
+
├── 404.hbs
|
|
179
|
+
└── 500.hbs
|
|
174
180
|
```
|
|
175
181
|
|
|
176
182
|
## Author
|
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
126
|
+
throw new NotFoundError();
|
|
127
127
|
transaction = await super.begin();
|
|
128
128
|
user.email = set.email;
|
|
129
129
|
user.name = set.name;
|