express-sweet-generator 2.0.5 → 2.0.6

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
@@ -4,7 +4,7 @@
4
4
  A comprehensive list of changes in each version may be found in the [CHANGELOG](CHANGELOG.md).
5
5
 
6
6
  ## Installation
7
- ```sh
7
+ ```bash
8
8
  npm install -g express-sweet-generator
9
9
  ```
10
10
 
@@ -14,11 +14,11 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
14
14
  ![Image](screencaps/demonstration.webp)
15
15
 
16
16
  1. For example, the following creates an Express app named `myapp`. The app will be created in a folder named `myapp` in the current working directory.
17
- ```sh
17
+ ```bash
18
18
  express-sweet -o esm myapp
19
19
  ```
20
20
  1. Then install dependencies.
21
- ```sh
21
+ ```bash
22
22
  cd myapp/
23
23
  npm install
24
24
  ```
@@ -116,16 +116,16 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
116
116
  }
117
117
  ```
118
118
  1. The DB to be accessed can be defined for each environment. Specify the environment in the `.env` file
119
- ```sh
119
+ ```bash
120
120
  NODE_ENV=development
121
121
  ```
122
122
  1. Run the application with the following command.
123
- ```sh
123
+ ```bash
124
124
  npm start
125
125
  ```
126
126
  1. Then, load `http://localhost:3000/` in your browser to access the app.
127
127
  The generated app has the following directory structure:
128
- ```sh
128
+ ```bash
129
129
  .
130
130
  ├── .env
131
131
  ├── app.js
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const ejs = require('ejs');
3
3
  const fs = require('fs-extra');
4
4
  const path = require('path');
@@ -112,9 +112,9 @@ function getAppName(installDir) {
112
112
  * @param {Function} fn
113
113
  */
114
114
  function existsInstallationDirectory(dir, fn) {
115
- fs.readdir(dir, (err, files) => {
116
- if (err && err.code !== 'ENOENT')
117
- throw err;
115
+ fs.readdir(dir, (error, files) => {
116
+ if (error && error.code !== 'ENOENT')
117
+ throw error;
118
118
  fn(!files || !files.length);
119
119
  });
120
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "EXPRESS SWEET application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -65,11 +65,11 @@ module.exports = {
65
65
 
66
66
  /**
67
67
  * Hooks the default behavior on request errors.
68
- * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
69
- * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
68
+ * If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
69
+ * @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
70
70
  * @example
71
- * hook_handle_error: (err, req, res, next) => {
72
- * if (err.status === 404)
71
+ * hook_handle_error: (error, req, res, next) => {
72
+ * if (error.status === 404)
73
73
  * // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
74
74
  * res.render('errors/404');
75
75
  * else
@@ -77,8 +77,8 @@ module.exports = {
77
77
  * res.render('error/500');
78
78
  * },
79
79
  */
80
- hook_handle_error: (err, req, res, next) => {
81
- if (err.status === 404)
80
+ hook_handle_error: (error, req, res, next) => {
81
+ if (error.status === 404)
82
82
  res.status(404).render('errors/404', {isErrorPage: true});
83
83
  else
84
84
  res.status(500).render('errors/500', {isErrorPage: true});
@@ -105,10 +105,10 @@ module.exports = class extends expressExtension.database.Model {
105
105
  }, {transaction});
106
106
  await this.#updateUserIcon(user, set.icon, transaction);
107
107
  await transaction.commit();
108
- } catch (err) {
108
+ } catch (error) {
109
109
  if (transaction)
110
110
  await transaction.rollback();
111
- throw err;
111
+ throw error;
112
112
  }
113
113
  }
114
114
 
@@ -133,10 +133,10 @@ module.exports = class extends expressExtension.database.Model {
133
133
  await user.save({transaction});
134
134
  await this.#updateUserIcon(user, set.icon, transaction);
135
135
  await transaction.commit();
136
- } catch (err) {
136
+ } catch (error) {
137
137
  if (transaction)
138
138
  await transaction.rollback();
139
- throw err;
139
+ throw error;
140
140
  }
141
141
  }
142
142
 
@@ -124,13 +124,13 @@ var build = __webpack_require__(236);
124
124
  /**
125
125
  * Handles API errors.
126
126
  * @param {number} code The HTTP status code.
127
- * @param {Error} err The error object.
127
+ * @param {Error} error The error object.
128
128
  * @return {void}
129
129
  */
130
- errorHook(code, err) {
130
+ errorHook(code, error) {
131
131
  // Check if the error object and request properties exist to avoid runtime errors
132
- if (err && err.request && err.request.responseURL) {
133
- const {pathname} = new URL(err.request.responseURL);
132
+ if (error && error.request && error.request.responseURL) {
133
+ const {pathname} = new URL(error.request.responseURL);
134
134
  if (pathname !== '/api/users/login' && code === 401) {
135
135
  // Redirect to the login page if an authentication error occurs on a non-login request.
136
136
  location.replace('/');
@@ -141,7 +141,7 @@ var build = __webpack_require__(236);
141
141
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
142
142
 
143
143
 
144
- /* harmony default export */ const UserApi = (class extends components.Api {
144
+ /* harmony default export */ const UserApi = (class extends Api {
145
145
  constructor() {
146
146
  super('/api/users');
147
147
  }
@@ -238,10 +238,10 @@ function initForm() {
238
238
  await build.components.Dialog.info('Email address has been changed. Please re-login.');
239
239
  return void userApi.logout();
240
240
  }
241
- } catch (err) {
241
+ } catch (error) {
242
242
  validation.offIndicator();
243
243
  build.components.Dialog.unknownError();
244
- throw err;
244
+ throw error;
245
245
  }
246
246
  });
247
247
  ref.personalForm
@@ -124,13 +124,13 @@ var build = __webpack_require__(236);
124
124
  /**
125
125
  * Handles API errors.
126
126
  * @param {number} code The HTTP status code.
127
- * @param {Error} err The error object.
127
+ * @param {Error} error The error object.
128
128
  * @return {void}
129
129
  */
130
- errorHook(code, err) {
130
+ errorHook(code, error) {
131
131
  // Check if the error object and request properties exist to avoid runtime errors
132
- if (err && err.request && err.request.responseURL) {
133
- const {pathname} = new URL(err.request.responseURL);
132
+ if (error && error.request && error.request.responseURL) {
133
+ const {pathname} = new URL(error.request.responseURL);
134
134
  if (pathname !== '/api/users/login' && code === 401) {
135
135
  // Redirect to the login page if an authentication error occurs on a non-login request.
136
136
  location.replace('/');
@@ -141,7 +141,7 @@ var build = __webpack_require__(236);
141
141
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
142
142
 
143
143
 
144
- /* harmony default export */ const UserApi = (class extends components.Api {
144
+ /* harmony default export */ const UserApi = (class extends Api {
145
145
  constructor() {
146
146
  super('/api/users');
147
147
  }
@@ -205,10 +205,10 @@ function initForm() {
205
205
  if (!data)
206
206
  return void validation.setError('email', 'userNotFound');
207
207
  location.href = '/';
208
- } catch (err) {
208
+ } catch (error) {
209
209
  validation.offIndicator();
210
210
  build.components.Dialog.unknownError();
211
- throw err;
211
+ throw error;
212
212
  }
213
213
  });
214
214
  }
@@ -262,6 +262,19 @@ var dist_build = __webpack_require__(236);
262
262
  }
263
263
  });
264
264
 
265
+ ;// CONCATENATED MODULE: ./src/shared/reloadDataTableWithDelay.js
266
+ /**
267
+ * Reloads a DataTable after a specified delay.
268
+ * @param {object} dataTable The DataTable instance to reload.
269
+ * @param {number} delay The delay in milliseconds before reloading.
270
+ */
271
+ /* harmony default export */ const reloadDataTableWithDelay = ((dataTable, delay = 500) => {
272
+ let timer;
273
+ return function() { // Preserve the timer using a closure
274
+ clearTimeout(timer);
275
+ timer = setTimeout(() => dataTable.reload(), delay);
276
+ };
277
+ });
265
278
  ;// CONCATENATED MODULE: ./src/shared/Api.js
266
279
 
267
280
 
@@ -300,13 +313,13 @@ var dist_build = __webpack_require__(236);
300
313
  /**
301
314
  * Handles API errors.
302
315
  * @param {number} code The HTTP status code.
303
- * @param {Error} err The error object.
316
+ * @param {Error} error The error object.
304
317
  * @return {void}
305
318
  */
306
- errorHook(code, err) {
319
+ errorHook(code, error) {
307
320
  // Check if the error object and request properties exist to avoid runtime errors
308
- if (err && err.request && err.request.responseURL) {
309
- const {pathname} = new URL(err.request.responseURL);
321
+ if (error && error.request && error.request.responseURL) {
322
+ const {pathname} = new URL(error.request.responseURL);
310
323
  if (pathname !== '/api/users/login' && code === 401) {
311
324
  // Redirect to the login page if an authentication error occurs on a non-login request.
312
325
  location.replace('/');
@@ -317,7 +330,7 @@ var dist_build = __webpack_require__(236);
317
330
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
318
331
 
319
332
 
320
- /* harmony default export */ const UserApi = (class extends components.Api {
333
+ /* harmony default export */ const UserApi = (class extends Api {
321
334
  constructor() {
322
335
  super('/api/users');
323
336
  }
@@ -603,10 +616,10 @@ var dist_build = __webpack_require__(236);
603
616
  this.#validator.offIndicator();
604
617
  dist_build.components.Toast.success('User created.');
605
618
  super.hide(true);
606
- } catch (err) {
619
+ } catch (error) {
607
620
  this.#validator.offIndicator();
608
621
  dist_build.components.Dialog.unknownError();
609
- throw err;
622
+ throw error;
610
623
  }
611
624
  });
612
625
  }
@@ -628,10 +641,10 @@ var dist_build = __webpack_require__(236);
628
641
  }
629
642
  dist_build.components.Toast.success('User updated.');
630
643
  super.hide(true);
631
- } catch (err) {
644
+ } catch (error) {
632
645
  this.#validator.offIndicator();
633
646
  dist_build.components.Dialog.unknownError();
634
- throw err;
647
+ throw error;
635
648
  }
636
649
  });
637
650
  }
@@ -718,6 +731,7 @@ var dist_build = __webpack_require__(236);
718
731
 
719
732
 
720
733
 
734
+
721
735
  function initTable() {
722
736
  userTable = new Datatable(ref.userTable, {
723
737
  ajax: {
@@ -800,23 +814,18 @@ function initForm() {
800
814
  throw Error('Unknown error');
801
815
  dist_build.components.Toast.success(`${name} was deleted.`);
802
816
  userTable.reload();
803
- } catch (err) {
817
+ } catch (error) {
804
818
  dist_build.components.Dialog.unknownError();
805
- throw err;
819
+ throw error;
806
820
  }
807
821
  })
808
- .on('input', '[data-on-search-change]' , evnt => {
809
- if (searchTimer)
810
- clearTimeout(searchTimer);
811
- searchTimer = setTimeout(() => userTable.reload(), 300);
812
- });
822
+ .on('input', '[data-on-search-change]' , reloadDataTableWithDelay(userTable));
813
823
  }
814
824
 
815
825
  const userApi = new UserApi();
816
826
  const userModal = new UserModal();
817
827
  const ref = dist_build.components.selectRef('#kt_app_content_container');
818
828
  let userTable;
819
- let searchTimer;
820
829
  initTable();
821
830
  initForm();
822
831
  })();
@@ -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 errs = validationResult(req);
15
- if (!errs.isEmpty())
16
- return void res.status(400).json({errors: errs.array()});
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 errs = validationResult(req);
35
- if (!errs.isEmpty())
36
- return void res.status(400).json({errors: errs.array()});
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 errs = validationResult(req);
47
- if (!errs.isEmpty())
48
- return void res.status(400).json({errors: errs.array()});
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 errs = validationResult(req);
60
- if (!errs.isEmpty())
61
- return void res.status(400).json({errors: errs.array()});
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 errs = validationResult(req);
79
- if (!errs.isEmpty())
80
- return void res.status(400).json({errors: errs.array()});
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 (err) {
84
- if (err instanceof UserNotFound)
85
- res.json({error: err.name});
83
+ } catch (error) {
84
+ if (error instanceof UserNotFound)
85
+ res.json({error: error.name});
86
86
  else
87
- next(err);
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 errs = validationResult(req);
104
- if (!errs.isEmpty())
105
- return void res.status(400).json({errors: errs.array()});
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 (err) {
109
- if (err instanceof UserNotFound)
110
- res.json({error: err.name});
108
+ } catch (error) {
109
+ if (error instanceof UserNotFound)
110
+ res.json({error: error.name});
111
111
  else
112
- next(err);
112
+ next(error);
113
113
  }
114
114
  });
115
115
 
@@ -1,6 +1,6 @@
1
1
  import Api from '~/shared/Api';
2
2
 
3
- export default class extends components.Api {
3
+ export default class extends Api {
4
4
  constructor() {
5
5
  super('/api/users');
6
6
  }
@@ -61,10 +61,10 @@ function initForm() {
61
61
  await components.Dialog.info('Email address has been changed. Please re-login.');
62
62
  return void userApi.logout();
63
63
  }
64
- } catch (err) {
64
+ } catch (error) {
65
65
  validation.offIndicator();
66
66
  components.Dialog.unknownError();
67
- throw err;
67
+ throw error;
68
68
  }
69
69
  });
70
70
  ref.personalForm
@@ -28,10 +28,10 @@ function initForm() {
28
28
  if (!data)
29
29
  return void validation.setError('email', 'userNotFound');
30
30
  location.href = '/';
31
- } catch (err) {
31
+ } catch (error) {
32
32
  validation.offIndicator();
33
33
  components.Dialog.unknownError();
34
- throw err;
34
+ throw error;
35
35
  }
36
36
  });
37
37
  }
@@ -250,10 +250,10 @@ export default class extends components.Modal {
250
250
  this.#validator.offIndicator();
251
251
  components.Toast.success('User created.');
252
252
  super.hide(true);
253
- } catch (err) {
253
+ } catch (error) {
254
254
  this.#validator.offIndicator();
255
255
  components.Dialog.unknownError();
256
- throw err;
256
+ throw error;
257
257
  }
258
258
  });
259
259
  }
@@ -275,10 +275,10 @@ export default class extends components.Modal {
275
275
  }
276
276
  components.Toast.success('User updated.');
277
277
  super.hide(true);
278
- } catch (err) {
278
+ } catch (error) {
279
279
  this.#validator.offIndicator();
280
280
  components.Dialog.unknownError();
281
- throw err;
281
+ throw error;
282
282
  }
283
283
  });
284
284
  }
@@ -35,13 +35,13 @@ export default class extends components.Api {
35
35
  /**
36
36
  * Handles API errors.
37
37
  * @param {number} code The HTTP status code.
38
- * @param {Error} err The error object.
38
+ * @param {Error} error The error object.
39
39
  * @return {void}
40
40
  */
41
- errorHook(code, err) {
41
+ errorHook(code, error) {
42
42
  // Check if the error object and request properties exist to avoid runtime errors
43
- if (err && err.request && err.request.responseURL) {
44
- const {pathname} = new URL(err.request.responseURL);
43
+ if (error && error.request && error.request.responseURL) {
44
+ const {pathname} = new URL(error.request.responseURL);
45
45
  if (pathname !== '/api/users/login' && code === 401) {
46
46
  // Redirect to the login page if an authentication error occurs on a non-login request.
47
47
  location.replace('/');
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Reloads a DataTable after a specified delay.
3
+ * @param {object} dataTable The DataTable instance to reload.
4
+ * @param {number} delay The delay in milliseconds before reloading.
5
+ */
6
+ export default (dataTable, delay = 500) => {
7
+ let timer;
8
+ return function() { // Preserve the timer using a closure
9
+ clearTimeout(timer);
10
+ timer = setTimeout(() => dataTable.reload(), delay);
11
+ };
12
+ }
@@ -2,6 +2,7 @@ import '~/users.css';
2
2
  import hbs from 'handlebars-extd';
3
3
  import {components} from 'metronic-extension';
4
4
  import Datatable from '~/shared/Datatable';
5
+ import reloadDataTableWithDelay from '~/shared/reloadDataTableWithDelay';
5
6
  import UserApi from '~/api/UserApi';
6
7
  import UserModal from '~/modals/UserModal';
7
8
 
@@ -87,22 +88,17 @@ function initForm() {
87
88
  throw Error('Unknown error');
88
89
  components.Toast.success(`${name} was deleted.`);
89
90
  userTable.reload();
90
- } catch (err) {
91
+ } catch (error) {
91
92
  components.Dialog.unknownError();
92
- throw err;
93
+ throw error;
93
94
  }
94
95
  })
95
- .on('input', '[data-on-search-change]' , evnt => {
96
- if (searchTimer)
97
- clearTimeout(searchTimer);
98
- searchTimer = setTimeout(() => userTable.reload(), 300);
99
- });
96
+ .on('input', '[data-on-search-change]' , reloadDataTableWithDelay(userTable));
100
97
  }
101
98
 
102
99
  const userApi = new UserApi();
103
100
  const userModal = new UserModal();
104
101
  const ref = components.selectRef('#kt_app_content_container');
105
102
  let userTable;
106
- let searchTimer;
107
103
  initTable();
108
104
  initForm();
@@ -65,11 +65,11 @@ export default {
65
65
 
66
66
  /**
67
67
  * Hooks the default behavior on request errors.
68
- * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
69
- * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
68
+ * If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
69
+ * @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
70
70
  * @example
71
- * hook_handle_error: (err, req, res, next) => {
72
- * if (err.status === 404)
71
+ * hook_handle_error: (error, req, res, next) => {
72
+ * if (error.status === 404)
73
73
  * // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
74
74
  * res.render('errors/404');
75
75
  * else
@@ -77,8 +77,8 @@ export default {
77
77
  * res.render('error/500');
78
78
  * },
79
79
  */
80
- hook_handle_error: (err, req, res, next) => {
81
- if (err.status === 404)
80
+ hook_handle_error: (error, req, res, next) => {
81
+ if (error.status === 404)
82
82
  res.status(404).render('errors/404', {isErrorPage: true});
83
83
  else
84
84
  res.status(500).render('errors/500', {isErrorPage: true});
@@ -105,10 +105,10 @@ export default class extends expressExtension.database.Model {
105
105
  }, {transaction});
106
106
  await this.#updateUserIcon(user, set.icon, transaction);
107
107
  await transaction.commit();
108
- } catch (err) {
108
+ } catch (error) {
109
109
  if (transaction)
110
110
  await transaction.rollback();
111
- throw err;
111
+ throw error;
112
112
  }
113
113
  }
114
114
 
@@ -133,10 +133,10 @@ export default class extends expressExtension.database.Model {
133
133
  await user.save({transaction});
134
134
  await this.#updateUserIcon(user, set.icon, transaction);
135
135
  await transaction.commit();
136
- } catch (err) {
136
+ } catch (error) {
137
137
  if (transaction)
138
138
  await transaction.rollback();
139
- throw err;
139
+ throw error;
140
140
  }
141
141
  }
142
142
 
@@ -124,13 +124,13 @@ var build = __webpack_require__(236);
124
124
  /**
125
125
  * Handles API errors.
126
126
  * @param {number} code The HTTP status code.
127
- * @param {Error} err The error object.
127
+ * @param {Error} error The error object.
128
128
  * @return {void}
129
129
  */
130
- errorHook(code, err) {
130
+ errorHook(code, error) {
131
131
  // Check if the error object and request properties exist to avoid runtime errors
132
- if (err && err.request && err.request.responseURL) {
133
- const {pathname} = new URL(err.request.responseURL);
132
+ if (error && error.request && error.request.responseURL) {
133
+ const {pathname} = new URL(error.request.responseURL);
134
134
  if (pathname !== '/api/users/login' && code === 401) {
135
135
  // Redirect to the login page if an authentication error occurs on a non-login request.
136
136
  location.replace('/');
@@ -141,7 +141,7 @@ var build = __webpack_require__(236);
141
141
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
142
142
 
143
143
 
144
- /* harmony default export */ const UserApi = (class extends components.Api {
144
+ /* harmony default export */ const UserApi = (class extends Api {
145
145
  constructor() {
146
146
  super('/api/users');
147
147
  }
@@ -238,10 +238,10 @@ function initForm() {
238
238
  await build.components.Dialog.info('Email address has been changed. Please re-login.');
239
239
  return void userApi.logout();
240
240
  }
241
- } catch (err) {
241
+ } catch (error) {
242
242
  validation.offIndicator();
243
243
  build.components.Dialog.unknownError();
244
- throw err;
244
+ throw error;
245
245
  }
246
246
  });
247
247
  ref.personalForm
@@ -124,13 +124,13 @@ var build = __webpack_require__(236);
124
124
  /**
125
125
  * Handles API errors.
126
126
  * @param {number} code The HTTP status code.
127
- * @param {Error} err The error object.
127
+ * @param {Error} error The error object.
128
128
  * @return {void}
129
129
  */
130
- errorHook(code, err) {
130
+ errorHook(code, error) {
131
131
  // Check if the error object and request properties exist to avoid runtime errors
132
- if (err && err.request && err.request.responseURL) {
133
- const {pathname} = new URL(err.request.responseURL);
132
+ if (error && error.request && error.request.responseURL) {
133
+ const {pathname} = new URL(error.request.responseURL);
134
134
  if (pathname !== '/api/users/login' && code === 401) {
135
135
  // Redirect to the login page if an authentication error occurs on a non-login request.
136
136
  location.replace('/');
@@ -141,7 +141,7 @@ var build = __webpack_require__(236);
141
141
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
142
142
 
143
143
 
144
- /* harmony default export */ const UserApi = (class extends components.Api {
144
+ /* harmony default export */ const UserApi = (class extends Api {
145
145
  constructor() {
146
146
  super('/api/users');
147
147
  }
@@ -205,10 +205,10 @@ function initForm() {
205
205
  if (!data)
206
206
  return void validation.setError('email', 'userNotFound');
207
207
  location.href = '/';
208
- } catch (err) {
208
+ } catch (error) {
209
209
  validation.offIndicator();
210
210
  build.components.Dialog.unknownError();
211
- throw err;
211
+ throw error;
212
212
  }
213
213
  });
214
214
  }
@@ -262,6 +262,19 @@ var dist_build = __webpack_require__(236);
262
262
  }
263
263
  });
264
264
 
265
+ ;// CONCATENATED MODULE: ./src/shared/reloadDataTableWithDelay.js
266
+ /**
267
+ * Reloads a DataTable after a specified delay.
268
+ * @param {object} dataTable The DataTable instance to reload.
269
+ * @param {number} delay The delay in milliseconds before reloading.
270
+ */
271
+ /* harmony default export */ const reloadDataTableWithDelay = ((dataTable, delay = 500) => {
272
+ let timer;
273
+ return function() { // Preserve the timer using a closure
274
+ clearTimeout(timer);
275
+ timer = setTimeout(() => dataTable.reload(), delay);
276
+ };
277
+ });
265
278
  ;// CONCATENATED MODULE: ./src/shared/Api.js
266
279
 
267
280
 
@@ -300,13 +313,13 @@ var dist_build = __webpack_require__(236);
300
313
  /**
301
314
  * Handles API errors.
302
315
  * @param {number} code The HTTP status code.
303
- * @param {Error} err The error object.
316
+ * @param {Error} error The error object.
304
317
  * @return {void}
305
318
  */
306
- errorHook(code, err) {
319
+ errorHook(code, error) {
307
320
  // Check if the error object and request properties exist to avoid runtime errors
308
- if (err && err.request && err.request.responseURL) {
309
- const {pathname} = new URL(err.request.responseURL);
321
+ if (error && error.request && error.request.responseURL) {
322
+ const {pathname} = new URL(error.request.responseURL);
310
323
  if (pathname !== '/api/users/login' && code === 401) {
311
324
  // Redirect to the login page if an authentication error occurs on a non-login request.
312
325
  location.replace('/');
@@ -317,7 +330,7 @@ var dist_build = __webpack_require__(236);
317
330
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
318
331
 
319
332
 
320
- /* harmony default export */ const UserApi = (class extends components.Api {
333
+ /* harmony default export */ const UserApi = (class extends Api {
321
334
  constructor() {
322
335
  super('/api/users');
323
336
  }
@@ -603,10 +616,10 @@ var dist_build = __webpack_require__(236);
603
616
  this.#validator.offIndicator();
604
617
  dist_build.components.Toast.success('User created.');
605
618
  super.hide(true);
606
- } catch (err) {
619
+ } catch (error) {
607
620
  this.#validator.offIndicator();
608
621
  dist_build.components.Dialog.unknownError();
609
- throw err;
622
+ throw error;
610
623
  }
611
624
  });
612
625
  }
@@ -628,10 +641,10 @@ var dist_build = __webpack_require__(236);
628
641
  }
629
642
  dist_build.components.Toast.success('User updated.');
630
643
  super.hide(true);
631
- } catch (err) {
644
+ } catch (error) {
632
645
  this.#validator.offIndicator();
633
646
  dist_build.components.Dialog.unknownError();
634
- throw err;
647
+ throw error;
635
648
  }
636
649
  });
637
650
  }
@@ -718,6 +731,7 @@ var dist_build = __webpack_require__(236);
718
731
 
719
732
 
720
733
 
734
+
721
735
  function initTable() {
722
736
  userTable = new Datatable(ref.userTable, {
723
737
  ajax: {
@@ -800,23 +814,18 @@ function initForm() {
800
814
  throw Error('Unknown error');
801
815
  dist_build.components.Toast.success(`${name} was deleted.`);
802
816
  userTable.reload();
803
- } catch (err) {
817
+ } catch (error) {
804
818
  dist_build.components.Dialog.unknownError();
805
- throw err;
819
+ throw error;
806
820
  }
807
821
  })
808
- .on('input', '[data-on-search-change]' , evnt => {
809
- if (searchTimer)
810
- clearTimeout(searchTimer);
811
- searchTimer = setTimeout(() => userTable.reload(), 300);
812
- });
822
+ .on('input', '[data-on-search-change]' , reloadDataTableWithDelay(userTable));
813
823
  }
814
824
 
815
825
  const userApi = new UserApi();
816
826
  const userModal = new UserModal();
817
827
  const ref = dist_build.components.selectRef('#kt_app_content_container');
818
828
  let userTable;
819
- let searchTimer;
820
829
  initTable();
821
830
  initForm();
822
831
  })();
@@ -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 errs = validationResult(req);
15
- if (!errs.isEmpty())
16
- return void res.status(400).json({errors: errs.array()});
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 errs = validationResult(req);
35
- if (!errs.isEmpty())
36
- return void res.status(400).json({errors: errs.array()});
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 errs = validationResult(req);
47
- if (!errs.isEmpty())
48
- return void res.status(400).json({errors: errs.array()});
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 errs = validationResult(req);
60
- if (!errs.isEmpty())
61
- return void res.status(400).json({errors: errs.array()});
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 errs = validationResult(req);
79
- if (!errs.isEmpty())
80
- return void res.status(400).json({errors: errs.array()});
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 (err) {
84
- if (err instanceof UserNotFound)
85
- res.json({error: err.name});
83
+ } catch (error) {
84
+ if (error instanceof UserNotFound)
85
+ res.json({error: error.name});
86
86
  else
87
- next(err);
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 errs = validationResult(req);
104
- if (!errs.isEmpty())
105
- return void res.status(400).json({errors: errs.array()});
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 (err) {
109
- if (err instanceof UserNotFound)
110
- res.json({error: err.name});
108
+ } catch (error) {
109
+ if (error instanceof UserNotFound)
110
+ res.json({error: error.name});
111
111
  else
112
- next(err);
112
+ next(error);
113
113
  }
114
114
  });
115
115