express-sweet-generator 2.0.11 → 2.0.13

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.
Files changed (39) hide show
  1. package/README.md +8 -4
  2. package/package.json +1 -1
  3. package/templates/cjs/bin/www.ejs +3 -3
  4. package/templates/cjs/config/view.js +5 -1
  5. package/templates/cjs/models/UserModel.js +9 -1
  6. package/templates/cjs/public/build/login.js +3 -7
  7. package/templates/{esm/public/build/editPersonal.js → cjs/public/build/profile-edit.js} +115 -105
  8. package/templates/cjs/public/build/users.js +185 -185
  9. package/templates/cjs/routes/api/profile.js +29 -0
  10. package/templates/cjs/routes/api/users.js +0 -18
  11. package/templates/cjs/routes/profile.js +16 -0
  12. package/templates/cjs/routes/users.js +1 -12
  13. package/templates/cjs/views/layout/default.hbs +14 -5
  14. package/templates/{esm/views/edit-personal.hbs → cjs/views/profile/edit.hbs} +4 -4
  15. package/templates/{esm/views/personal.hbs → cjs/views/profile/show.hbs} +1 -1
  16. package/templates/client/src/api/ProfileApi.js +11 -0
  17. package/templates/client/src/api/UserApi.js +0 -4
  18. package/templates/client/src/login.js +4 -4
  19. package/templates/client/src/{editPersonal.js → profile-edit.js} +9 -7
  20. package/templates/client/src/users.js +14 -10
  21. package/templates/client/webpack.config.js +1 -1
  22. package/templates/esm/bin/www.ejs +3 -3
  23. package/templates/esm/config/view.js +5 -1
  24. package/templates/esm/models/UserModel.js +9 -1
  25. package/templates/esm/public/build/login.js +3 -7
  26. package/templates/{cjs/public/build/editPersonal.js → esm/public/build/profile-edit.js} +115 -105
  27. package/templates/esm/public/build/users.js +185 -185
  28. package/templates/esm/routes/api/profile.js +29 -0
  29. package/templates/esm/routes/api/users.js +0 -18
  30. package/templates/esm/routes/profile.js +16 -0
  31. package/templates/esm/routes/users.js +1 -12
  32. package/templates/esm/views/layout/default.hbs +14 -5
  33. package/templates/{cjs/views/edit-personal.hbs → esm/views/profile/edit.hbs} +4 -4
  34. package/templates/{cjs/views/personal.hbs → esm/views/profile/show.hbs} +1 -1
  35. /package/templates/cjs/public/build/{editPersonal.css → profile-edit.css} +0 -0
  36. /package/templates/cjs/views/{users.hbs → users/index.hbs} +0 -0
  37. /package/templates/client/src/{editPersonal.css → profile-edit.css} +0 -0
  38. /package/templates/esm/public/build/{editPersonal.css → profile-edit.css} +0 -0
  39. /package/templates/esm/views/{users.hbs → users/index.hbs} +0 -0
@@ -0,0 +1,29 @@
1
+ // import * as expressExtension from 'express-sweet';
2
+ import {Router} from 'express';
3
+ import {body} from 'express-validator';
4
+ import UserModel from '../../models/UserModel.js';
5
+ import NotFoundError from '../../errors/NotFoundError.js';
6
+ import isValidImageDataUrl from '../../validators/isValidImageDataUrl.js';
7
+ import checkValidationResult from '../../middlewares/checkValidationResult.js';
8
+
9
+ const router = Router();
10
+
11
+ router.put('/', [
12
+ body('user.email').trim().not().isEmpty().isEmail(),
13
+ body('user.name').trim().not().isEmpty().isLength({max: 30}),
14
+ body('user.password').trim().optional({nullable: true, checkFalsy: true}).isLength({max: 128}),
15
+ body('user.icon').not().isEmpty().custom(isValidImageDataUrl),
16
+ checkValidationResult,
17
+ ], async (req, res, next) => {
18
+ try {
19
+ await UserModel.updateUser(req.user.id, req.body.user);
20
+ res.json(true);
21
+ } catch (error) {
22
+ if (error instanceof NotFoundError)
23
+ res.json({error: error.name});
24
+ else
25
+ next(error);
26
+ }
27
+ });
28
+
29
+ export default router;
@@ -84,22 +84,4 @@ router.delete('/:userId(\\d+)', async (req, res) => {
84
84
  res.json(true);
85
85
  });
86
86
 
87
- router.put('/profile', [
88
- body('user.email').trim().not().isEmpty().isEmail(),
89
- body('user.name').trim().not().isEmpty().isLength({max: 30}),
90
- body('user.password').trim().optional({nullable: true, checkFalsy: true}).isLength({max: 128}),
91
- body('user.icon').not().isEmpty().custom(isValidImageDataUrl),
92
- checkValidationResult,
93
- ], async (req, res, next) => {
94
- try {
95
- await UserModel.updateUser(req.user.id, req.body.user);
96
- res.json(true);
97
- } catch (error) {
98
- if (error instanceof NotFoundError)
99
- res.json({error: error.name});
100
- else
101
- next(error);
102
- }
103
- });
104
-
105
87
  export default router;
@@ -0,0 +1,16 @@
1
+ import {Router} from 'express';
2
+ import UserModel from '../models/UserModel.js';
3
+
4
+ const router = Router();
5
+
6
+ router.get('/', async (req, res) => {
7
+ const user = await UserModel.getUser(req.user.id);
8
+ res.render('profile/show', {user: user.toJSON()});
9
+ });
10
+
11
+ router.get('/edit', async (req, res) => {
12
+ const user = await UserModel.getUser(req.user.id);
13
+ res.render('profile/edit', {user: user.toJSON()});
14
+ });
15
+
16
+ export default router;
@@ -1,20 +1,9 @@
1
1
  import {Router} from 'express';
2
- import UserModel from '../models/UserModel.js';
3
2
 
4
3
  const router = Router();
5
4
 
6
5
  router.get('/', (req, res) => {
7
- res.render('users');
8
- });
9
-
10
- router.get('/personal', async (req, res) => {
11
- const user = await UserModel.getUser(req.user.id);
12
- res.render('personal', {user: user.toJSON()});
13
- });
14
-
15
- router.get('/edit-personal', async (req, res) => {
16
- const user = await UserModel.getUser(req.user.id);
17
- res.render('edit-personal', {user: user.toJSON()});
6
+ res.render('users/index');
18
7
  });
19
8
 
20
9
  export default router;
@@ -33,6 +33,9 @@
33
33
  data-kt-app-sidebar-push-toolbar="true"
34
34
  data-kt-app-sidebar-push-footer="true"
35
35
  data-kt-app-toolbar-enabled="true"
36
+ {{#if (eq sidebar_minimize_state "on")}}
37
+ data-kt-app-sidebar-minimize="on"
38
+ {{/if}}
36
39
  class="app-default"
37
40
  {{else}}
38
41
  class="app-blank"
@@ -109,9 +112,9 @@
109
112
  </div>
110
113
  <!--end:Menu item-->
111
114
  <!--begin:Menu item-->
112
- <div class="menu-item menu-here-bg me-0 me-lg-2 {{#if (eq currentPath '/users/personal')}}here{{/if}}">
115
+ <div class="menu-item menu-here-bg me-0 me-lg-2 {{#if (eq currentPath '/profile')}}here{{/if}}">
113
116
  <!--begin:Menu link-->
114
- <a class="menu-link" href="/users/personal">
117
+ <a class="menu-link" href="/profile">
115
118
  <span class="menu-title">Profile Settings</span>
116
119
  </a>
117
120
  <!--end:Menu link-->
@@ -230,7 +233,7 @@
230
233
  <!--end::Menu separator-->
231
234
  <!--begin::Menu item-->
232
235
  <div class="menu-item px-5">
233
- <a href="/users/personal" class="menu-link px-5">Profile Settings</a>
236
+ <a href="/profile" class="menu-link px-5">Profile Settings</a>
234
237
  </div>
235
238
  <!--end::Menu item-->
236
239
  <!--begin::Menu item-->
@@ -283,7 +286,13 @@
283
286
  4. Add "active" class to to sidebar toggle element with "kt_app_sidebar_toggle" id.
284
287
  }
285
288
  -->
286
- <div id="kt_app_sidebar_toggle" class="app-sidebar-toggle btn btn-icon btn-shadow btn-sm btn-color-muted btn-active-color-primary body-bg h-30px w-30px position-absolute top-50 start-100 translate-middle rotate" data-kt-toggle="true" data-kt-toggle-state="active" data-kt-toggle-target="body" data-kt-toggle-name="app-sidebar-minimize">
289
+ <div
290
+ id="kt_app_sidebar_toggle"
291
+ class="app-sidebar-toggle btn btn-icon btn-shadow btn-sm btn-color-muted btn-active-color-primary body-bg h-30px w-30px position-absolute top-50 start-100 translate-middle rotate {{#if (eq sidebar_minimize_state "on")}}active{{/if}}"
292
+ data-kt-toggle="true"
293
+ data-kt-toggle-state="active"
294
+ data-kt-toggle-target="body"
295
+ data-kt-toggle-name="app-sidebar-minimize">
287
296
  <i class="ki-duotone ki-double-left fs-2 rotate-180">
288
297
  <span class="path1"></span>
289
298
  <span class="path2"></span>
@@ -328,7 +337,7 @@
328
337
  <!--begin:Menu item-->
329
338
  <div class="menu-item">
330
339
  <!--begin:Menu link-->
331
- <a class="menu-link {{#if (or (eq currentPath '/users/personal') (eq currentPath '/users/edit-personal'))}}active{{/if}}" href="/users/personal">
340
+ <a class="menu-link {{#if (or (eq currentPath '/profile') (eq currentPath '/profile/edit'))}}active{{/if}}" href="/profile">
332
341
  <span class="menu-icon">
333
342
  <i class="ki-duotone ki-address-book fs-2">
334
343
  <span class="path1"></span>
@@ -1,14 +1,14 @@
1
1
  {{!< default}}
2
2
  {{#contentFor 'title'}}Edit personal settings{{/contentFor}}
3
- {{#contentFor 'style'}}<link rel="stylesheet" type="text/css" href="{{cacheBusting '/build/editPersonal.css' ''}}">{{/contentFor}}
4
- {{#contentFor 'script'}}<script src="{{cacheBusting '/build/editPersonal.js' ''}}"></script>{{/contentFor}}
3
+ {{#contentFor 'style'}}<link rel="stylesheet" type="text/css" href="{{cacheBusting '/build/profile-edit.css' ''}}">{{/contentFor}}
4
+ {{#contentFor 'script'}}<script src="{{cacheBusting '/build/profile-edit.js' ''}}"></script>{{/contentFor}}
5
5
  <input data-ref="user.iconPath" type="hidden" value="{{user.icon}}">
6
6
  <input data-ref="user.modified" type="hidden" value="{{formatDate 'x' user.modified}}">
7
7
 
8
8
  <!--begin::Basic info-->
9
9
  <div class="card mb-5 mb-xl-10">
10
10
  <!--begin::Form-->
11
- <form data-ref="personalForm" class="form" novalidate="novalidate">
11
+ <form data-ref="profileEditForm" class="form" novalidate="novalidate">
12
12
  <!--begin::Card body-->
13
13
  <div class="card-body p-9">
14
14
  <!--begin::Input group-->
@@ -85,7 +85,7 @@
85
85
  <!--end::Card body-->
86
86
  <!--begin::Actions-->
87
87
  <div class="card-footer d-flex justify-content-end py-6 px-9">
88
- <a href="/users/personal" class="btn btn-light btn-active-light-primary me-2">Back to Profile</a>
88
+ <a href="/profile" class="btn btn-light btn-active-light-primary me-2">Back to Profile</a>
89
89
  <button type="submit" class="btn btn-primary">Update Profile</button>
90
90
  </div>
91
91
  <!--end::Actions-->
@@ -5,7 +5,7 @@
5
5
  <!--begin::Card header-->
6
6
  <div class="card-header cursor-pointer justify-content-end">
7
7
  <!--begin::Action-->
8
- <a href="/users/edit-personal" class="btn btn-primary align-self-center">Edit Profile</a>
8
+ <a href="/profile/edit" class="btn btn-primary align-self-center">Edit Profile</a>
9
9
  <!--end::Action-->
10
10
  </div>
11
11
  <!--end::Card header-->