express-sweet-generator 2.0.5 → 2.0.7
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 +8 -8
- package/bin/express-sweet-cli.js +4 -4
- package/package.json +1 -1
- package/templates/cjs/config/config.js +6 -6
- package/templates/cjs/errors/NotFoundError.js +14 -0
- package/templates/cjs/models/UserModel.js +6 -6
- package/templates/cjs/public/build/editPersonal.js +105 -105
- package/templates/cjs/public/build/login.js +7 -7
- package/templates/cjs/public/build/users.js +198 -189
- package/templates/cjs/routes/api/users.js +27 -27
- package/templates/client/src/api/UserApi.js +1 -1
- package/templates/client/src/editPersonal.js +3 -3
- package/templates/client/src/login.js +2 -2
- package/templates/client/src/modals/UserModal.js +5 -5
- package/templates/client/src/shared/Api.js +4 -4
- package/templates/client/src/shared/reloadDataTableWithDelay.js +12 -0
- package/templates/client/src/users.js +4 -8
- package/templates/esm/config/config.js +6 -6
- package/templates/esm/errors/NotFoundError.js +14 -0
- package/templates/esm/models/UserModel.js +6 -6
- package/templates/esm/public/build/editPersonal.js +105 -105
- package/templates/esm/public/build/login.js +7 -7
- package/templates/esm/public/build/users.js +198 -189
- package/templates/esm/routes/api/users.js +27 -27
- package/templates/cjs/exceptions/UserNotFound.js +0 -6
- package/templates/esm/exceptions/UserNotFound.js +0 -6
|
@@ -2,7 +2,7 @@ import * as expressExtension from 'express-sweet';
|
|
|
2
2
|
import {Router} from 'express';
|
|
3
3
|
import {query, body, validationResult} from 'express-validator';
|
|
4
4
|
import UserModel from '../../models/UserModel.js';
|
|
5
|
-
import
|
|
5
|
+
import NotFoundError from '../../errors/NotFoundError.js';
|
|
6
6
|
import * as CustomValidation from '../../shared/CustomValidation.js';
|
|
7
7
|
|
|
8
8
|
const router = Router();
|
|
@@ -11,9 +11,9 @@ router.post('/login', [
|
|
|
11
11
|
body('email').trim().not().isEmpty().isEmail(),
|
|
12
12
|
body('password').trim().not().isEmpty()
|
|
13
13
|
], async (req, res, next) => {
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
return void res.status(400).json({errors:
|
|
14
|
+
const result = validationResult(req);
|
|
15
|
+
if (!result.isEmpty())
|
|
16
|
+
return void res.status(400).json({errors: result.array()});
|
|
17
17
|
const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
|
|
18
18
|
res.json(isAuthenticated);
|
|
19
19
|
});
|
|
@@ -31,9 +31,9 @@ router.get('/', [
|
|
|
31
31
|
query('dir').optional({nullable: true, checkFalsy: true}).isIn(['asc', 'desc']),
|
|
32
32
|
query('search').trim().optional({nullable: true, checkFalsy: true}).trim()
|
|
33
33
|
], async (req, res) => {
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
36
|
-
return void res.status(400).json({errors:
|
|
34
|
+
const result = validationResult(req);
|
|
35
|
+
if (!result.isEmpty())
|
|
36
|
+
return void res.status(400).json({errors: result.array()});
|
|
37
37
|
const data = await UserModel.paginate(req.query);
|
|
38
38
|
data.draw = req.query.draw;
|
|
39
39
|
res.json(data);
|
|
@@ -43,9 +43,9 @@ router.get('/email-exists', [
|
|
|
43
43
|
query('user.email').trim().not().isEmpty(),
|
|
44
44
|
query('excludeUserId').optional({nullable: true, checkFalsy: true}).isInt({min: 1})
|
|
45
45
|
], async (req, res) => {
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
return void res.status(400).json({errors:
|
|
46
|
+
const result = validationResult(req);
|
|
47
|
+
if (!result.isEmpty())
|
|
48
|
+
return void res.status(400).json({errors: result.array()});
|
|
49
49
|
const emailExists = await UserModel.emailExists(req.query.user.email, req.query.excludeUserId || null);
|
|
50
50
|
res.json({valid: !emailExists});
|
|
51
51
|
});
|
|
@@ -56,9 +56,9 @@ router.post('/', [
|
|
|
56
56
|
body('user.password').trim().not().isEmpty().isLength({max: 128}),
|
|
57
57
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
58
58
|
], async (req, res) => {
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
61
|
-
return void res.status(400).json({errors:
|
|
59
|
+
const result = validationResult(req);
|
|
60
|
+
if (!result.isEmpty())
|
|
61
|
+
return void res.status(400).json({errors: result.array()});
|
|
62
62
|
await UserModel.createUser(req.body.user);
|
|
63
63
|
res.json(true);
|
|
64
64
|
});
|
|
@@ -75,16 +75,16 @@ router.put('/:userId(\\d+)', [
|
|
|
75
75
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
76
76
|
], async (req, res, next) => {
|
|
77
77
|
try {
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
80
|
-
return void res.status(400).json({errors:
|
|
78
|
+
const result = validationResult(req);
|
|
79
|
+
if (!result.isEmpty())
|
|
80
|
+
return void res.status(400).json({errors: result.array()});
|
|
81
81
|
await UserModel.updateUser(req.params.userId, req.body.user);
|
|
82
82
|
res.json(true);
|
|
83
|
-
} catch (
|
|
84
|
-
if (
|
|
85
|
-
res.json({error:
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof NotFoundError)
|
|
85
|
+
res.json({error: error.name});
|
|
86
86
|
else
|
|
87
|
-
next(
|
|
87
|
+
next(error);
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
|
|
@@ -100,16 +100,16 @@ router.put('/profile', [
|
|
|
100
100
|
body('user.icon').not().isEmpty().custom(CustomValidation.isImageDataUrl)
|
|
101
101
|
], async (req, res, next) => {
|
|
102
102
|
try {
|
|
103
|
-
const
|
|
104
|
-
if (!
|
|
105
|
-
return void res.status(400).json({errors:
|
|
103
|
+
const result = validationResult(req);
|
|
104
|
+
if (!result.isEmpty())
|
|
105
|
+
return void res.status(400).json({errors: result.array()});
|
|
106
106
|
await UserModel.updateUser(req.user.id, req.body.user);
|
|
107
107
|
res.json(true);
|
|
108
|
-
} catch (
|
|
109
|
-
if (
|
|
110
|
-
res.json({error:
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (error instanceof NotFoundError)
|
|
110
|
+
res.json({error: error.name});
|
|
111
111
|
else
|
|
112
|
-
next(
|
|
112
|
+
next(error);
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
|