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
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
|
-
```
|
|
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
|

|
|
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
|
-
```
|
|
17
|
+
```bash
|
|
18
18
|
express-sweet -o esm myapp
|
|
19
19
|
```
|
|
20
20
|
1. Then install dependencies.
|
|
21
|
-
```
|
|
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
|
-
```
|
|
119
|
+
```bash
|
|
120
120
|
NODE_ENV=development
|
|
121
121
|
```
|
|
122
122
|
1. Run the application with the following command.
|
|
123
|
-
```
|
|
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
|
-
```
|
|
128
|
+
```bash
|
|
129
129
|
.
|
|
130
130
|
├── .env
|
|
131
131
|
├── app.js
|
|
@@ -143,8 +143,8 @@ 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
148
|
├── models
|
|
149
149
|
│ ├── BookModel.js
|
|
150
150
|
│ ├── CommentModel.js
|
package/bin/express-sweet-cli.js
CHANGED
|
@@ -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, (
|
|
116
|
-
if (
|
|
117
|
-
throw
|
|
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
|
@@ -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(
|
|
69
|
-
* @type {(
|
|
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: (
|
|
72
|
-
* if (
|
|
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: (
|
|
81
|
-
if (
|
|
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});
|
|
@@ -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
|
+
}
|
|
@@ -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() {
|
|
@@ -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 (
|
|
108
|
+
} catch (error) {
|
|
109
109
|
if (transaction)
|
|
110
110
|
await transaction.rollback();
|
|
111
|
-
throw
|
|
111
|
+
throw error;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -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;
|
|
@@ -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 (
|
|
136
|
+
} catch (error) {
|
|
137
137
|
if (transaction)
|
|
138
138
|
await transaction.rollback();
|
|
139
|
-
throw
|
|
139
|
+
throw error;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|