create-sip 0.13.0 → 0.14.1
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 -0
- package/expressapi/op +13 -2
- package/expressapi/package.json +1 -0
- package/expressapi/templates/controllerTemplate.js +16 -4
- package/manager.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,3 +78,11 @@ Default database type is sqlite :memory:. If you want to use another database, e
|
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
Must be set the database path in the config/default.json file.
|
|
81
|
+
|
|
82
|
+
### Default admin user
|
|
83
|
+
|
|
84
|
+
Generate admin user:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
node op admin:generate
|
|
88
|
+
```
|
package/expressapi/op
CHANGED
|
@@ -7,6 +7,8 @@ import { generateApiKey } from 'generate-api-key'
|
|
|
7
7
|
import bcrypt from 'bcryptjs';
|
|
8
8
|
import path from 'path';
|
|
9
9
|
|
|
10
|
+
import { read } from 'read'
|
|
11
|
+
|
|
10
12
|
if(process.argv.length == 3 && process.argv[2] == 'key:generate') {
|
|
11
13
|
startGenerateKey();
|
|
12
14
|
} else if(process.argv.length == 3 && process.argv[2] == 'conf:generate') {
|
|
@@ -118,6 +120,15 @@ async function loadConfig() {
|
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
|
|
123
|
+
async function inputPassword() {
|
|
124
|
+
const password = await read({
|
|
125
|
+
prompt: 'Password: ',
|
|
126
|
+
silent: true,
|
|
127
|
+
replace: '*'
|
|
128
|
+
})
|
|
129
|
+
return password
|
|
130
|
+
}
|
|
131
|
+
|
|
121
132
|
async function startGenerateAdmin() {
|
|
122
133
|
console.log('Generate admin...')
|
|
123
134
|
try {
|
|
@@ -134,8 +145,8 @@ async function startGenerateAdmin() {
|
|
|
134
145
|
console.log('Admin already exists!')
|
|
135
146
|
return;
|
|
136
147
|
}
|
|
137
|
-
|
|
138
|
-
const hashedPassword = await bcrypt.hash(
|
|
148
|
+
const password = await inputPassword()
|
|
149
|
+
const hashedPassword = await bcrypt.hash(password, 10);
|
|
139
150
|
await User.create({
|
|
140
151
|
name: 'admin',
|
|
141
152
|
email: 'admin',
|
package/expressapi/package.json
CHANGED
|
@@ -60,19 +60,31 @@ const ThingController = {
|
|
|
60
60
|
},
|
|
61
61
|
async update(req, res) {
|
|
62
62
|
try {
|
|
63
|
-
ThingController.tryUpdate(req, res)
|
|
63
|
+
await ThingController.tryUpdate(req, res)
|
|
64
64
|
}catch(error) {
|
|
65
|
-
|
|
65
|
+
let actualMessage = '';
|
|
66
|
+
if(error.message == 'Fail! Record not found!') {
|
|
67
|
+
actualMessage = error.message
|
|
68
|
+
res.status(404)
|
|
69
|
+
}else {
|
|
70
|
+
res.status(500)
|
|
71
|
+
actualMessage = 'Fail! The query is failed!'
|
|
72
|
+
}
|
|
73
|
+
|
|
66
74
|
res.json({
|
|
67
75
|
success: false,
|
|
68
|
-
message:
|
|
76
|
+
message: actualMessage
|
|
69
77
|
})
|
|
70
78
|
}
|
|
71
79
|
},
|
|
72
80
|
async tryUpdate(req, res) {
|
|
73
|
-
const
|
|
81
|
+
const recordNumber = await Thing.update(req.body, {
|
|
74
82
|
where: { id: req.params.id }
|
|
75
83
|
})
|
|
84
|
+
if(recordNumber == 0) {
|
|
85
|
+
throw new Error('Fail! Record not found!')
|
|
86
|
+
}
|
|
87
|
+
const thing = await Thing.findByPk(req.params.id)
|
|
76
88
|
res.status(200)
|
|
77
89
|
res.json({
|
|
78
90
|
success: true,
|
package/manager.js
CHANGED
|
@@ -63,13 +63,16 @@ const genMockApi = (target) => {
|
|
|
63
63
|
const genExpressApi = (target) => {
|
|
64
64
|
copyDir(`${dir}/expressapi`, target);
|
|
65
65
|
updatePackageName(`${target}/package.json`, target);
|
|
66
|
-
console.log('ExpressJS REST API
|
|
66
|
+
console.log('ExpressJS REST API skeleton created');
|
|
67
67
|
console.log('Read docs/user_doc.md');
|
|
68
68
|
console.log('Run next commands:');
|
|
69
69
|
console.log(` cd ${target}`);
|
|
70
70
|
console.log(' npm install');
|
|
71
71
|
console.log(' node op key:generate');
|
|
72
72
|
console.log(' npm run dev');
|
|
73
|
+
console.log('Usable commands:');
|
|
74
|
+
console.log(' node op create model thing');
|
|
75
|
+
console.log(' node op create controller thing');
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
module.exports = {
|