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 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('admin', 10);
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',
@@ -22,6 +22,7 @@
22
22
  "jsonwebtoken": "^9.0.0",
23
23
  "mariadb": "^3.1.2",
24
24
  "morgan": "^1.10.0",
25
+ "read": "^4.1.0",
25
26
  "replace": "^1.2.2",
26
27
  "sequelize": "^6.32.0",
27
28
  "sqlite3": "^5.1.6"
@@ -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
- res.status(500)
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: 'Error! The query is failed!'
76
+ message: actualMessage
69
77
  })
70
78
  }
71
79
  },
72
80
  async tryUpdate(req, res) {
73
- const thing = await Thing.update(req.body, {
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 sablon created');
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 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sip",
3
- "version": "0.13.0",
3
+ "version": "0.14.1",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "create-sip": "create-sip.js"