create-sip 1.2.1 → 1.2.2

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
@@ -182,7 +182,29 @@ Use next command:
182
182
  node op db:import employee employees.csv --sep ";"
183
183
  ```
184
184
 
185
- ## Migration
185
+ ### Database synchronization
186
+
187
+ Models and database tables can be synchronized, but this can be dangerous.
188
+
189
+ Database synchronization can be set up in the app/models/modrels.js file. Default values are:
190
+
191
+ ```js
192
+ { alter: true }
193
+ ```
194
+
195
+ This preserves the data and existing structure.
196
+
197
+ Possible values:
198
+
199
+ ```js
200
+ { force: true }
201
+ ```
202
+
203
+ The latter deletes the contents of the database table!
204
+
205
+ If the value is false, there is no synchronization in either case.
206
+
207
+ ### Migration
186
208
 
187
209
  Generate migration:
188
210
 
@@ -1,6 +1,6 @@
1
- # sip expressapi sabon
1
+ # sip expressapi template
2
2
 
3
- Express based REST API sablon
3
+ Express based REST API template
4
4
 
5
5
  ## Install
6
6
 
@@ -106,6 +106,28 @@ The keys in the JSON file and the field names in the CSV file must match the mod
106
106
 
107
107
  If the CSV file contains quotation marks, they are automatically removed.
108
108
 
109
+ ## Database synchronization
110
+
111
+ Models and database tables can be synchronized, but this can be dangerous.
112
+
113
+ Database synchronization can be set up in the app/models/modrels.js file. Default values are:
114
+
115
+ ```js
116
+ { alter: true }
117
+ ```
118
+
119
+ This preserves the data and existing structure.
120
+
121
+ Possible values:
122
+
123
+ ```js
124
+ { force: true }
125
+ ```
126
+
127
+ The latter deletes the contents of the database table!
128
+
129
+ If the value is false, there is no synchronization in either case.
130
+
109
131
  ## Migration
110
132
 
111
133
  Generate a migration:
@@ -88,7 +88,42 @@ const UserController = {
88
88
  data: userData
89
89
  })
90
90
  },
91
-
91
+ async updatePassword(req, res) {
92
+ var clientError = false;
93
+ try {
94
+ if(!req.body.password ||
95
+ !req.body.password_confirmation) {
96
+ clientError = true
97
+ throw new Error('Error! Bad request data!')
98
+ }
99
+ if(req.body.password != req.body.password_confirmation) {
100
+ clientError = true
101
+ throw new Error('Error! The two password is not same!')
102
+ }
103
+ await UserController.tryUpdatePassword(req, res)
104
+ }catch(error) {
105
+ if (clientError) {
106
+ res.status(400)
107
+ }else {
108
+ res.status(500)
109
+ }
110
+ res.json({
111
+ success: false,
112
+ message: 'Error! The query is failed!',
113
+ error: error.message
114
+ })
115
+ }
116
+ },
117
+ async tryUpdatePassword(req, res) {
118
+ const user = await User.findByPk(req.params.id)
119
+ user.password = bcrypt.hashSync(req.body.password)
120
+ await user.save()
121
+ res.status(200)
122
+ res.json({
123
+ success: true,
124
+ data: user
125
+ })
126
+ }
92
127
  }
93
128
 
94
129
  export default UserController
@@ -3,10 +3,12 @@ const router = Router()
3
3
 
4
4
  import AuthController from '../controllers/authController.js';
5
5
  import UserController from '../controllers/userController.js';
6
- import verifyToken from '../middlewares/authjwt.js';
6
+ import verifyToken from '../middleware/authjwt.js';
7
7
 
8
8
  router.post('/register', AuthController.register)
9
9
  router.post('/login', AuthController.login)
10
10
  router.get('/users', [verifyToken], UserController.index)
11
-
11
+ router.get('/users/:id', [verifyToken], UserController.show)
12
+ router.put('/users/:id/password', [verifyToken], UserController.updatePassword)
13
+
12
14
  export default router
@@ -0,0 +1,34 @@
1
+ import { DataTypes } from 'sequelize';
2
+
3
+ async function up({context: QueryInterface}) {
4
+ await QueryInterface.createTable('users', {
5
+ id: {
6
+ allowNull: false,
7
+ autoIncrement: true,
8
+ primaryKey: true,
9
+ type: DataTypes.INTEGER
10
+ },
11
+ name: {
12
+ type: DataTypes.STRING,
13
+ allowNull: false
14
+ },
15
+ email: {
16
+ type: DataTypes.STRING,
17
+ allowNull: true
18
+ },
19
+ password: {
20
+ type: DataTypes.STRING,
21
+ allowNull: false
22
+ },
23
+ roleId: {
24
+ type: DataTypes.INTEGER,
25
+ defaultValue: 0
26
+ }
27
+ });
28
+ }
29
+
30
+ async function down({context: QueryInterface}) {
31
+ await QueryInterface.dropTable('users');
32
+ }
33
+
34
+ export { up, down }
@@ -85,13 +85,70 @@ node op db:import thing things.csv ";"
85
85
  node op db:import thing things.csv :
86
86
  ```
87
87
 
88
- ## Migration
88
+ ## Database
89
89
 
90
- ```cmd
91
- node op make:migration thing
92
- node op migrate:run
93
- node op migrate:fresh
94
- node op migrate:rollback
95
- node op migrate:rollback --step 2
96
- node op migrate:reset
90
+ ### Database synchronization
91
+
92
+ Models and database tables can be synchronized, but this can be dangerous.
93
+
94
+ Database synchronization can be set up in the app/models/modrels.js file. Default values are:
95
+
96
+ ```js
97
+ { alter: true }
98
+ ```
99
+
100
+ This preserves the data and existing structure.
101
+
102
+ Possible values:
103
+
104
+ ```js
105
+ { force: true }
106
+ ```
107
+
108
+ The latter deletes the contents of the database table!
109
+
110
+ If the value is false, there is no synchronization in either case.
111
+
112
+ ### Migration
113
+
114
+ Generate a migration:
115
+
116
+ ```bash
117
+ node op make/migration thing
118
+ ```
119
+
120
+ Run all migration:
121
+
122
+ ```bash
123
+ node op migration:run
124
+ ```
125
+
126
+ Run a migration:
127
+
128
+ ```bash
129
+ node op migration:run <migration_name>
130
+ ```
131
+
132
+ Rollback a migration:
133
+
134
+ ```bash
135
+ node op migration:rollback
136
+ ```
137
+
138
+ Rollback two migrations:
139
+
140
+ ```bash
141
+ node op migration:rollback 2
142
+ ```
143
+
144
+ Reset the database:
145
+
146
+ ```bash
147
+ node op migration:reset
148
+ ```
149
+
150
+ Reset the database and run all migrations:
151
+
152
+ ```bash
153
+ node op migration:fresh
97
154
  ```
package/expressapi/op CHANGED
@@ -8,11 +8,12 @@ import bcrypt from 'bcryptjs';
8
8
  import path from 'path';
9
9
  import { read } from 'read';
10
10
 
11
- const { argv } = yargs(hideBin(process.argv))
11
+ yargs(hideBin(process.argv))
12
12
  .version()
13
+ .strict()
13
14
  .usage('Használat: node op <command> [name]')
14
15
  .help()
15
- .demandCommand(1, 'Not enough arguments!')
16
+ .demandCommand(2, 'Not enough arguments!')
16
17
  .command('make:model <name>',
17
18
  'Generates a new Sequelize model',
18
19
  (yargs) => {
@@ -51,7 +52,7 @@ const { argv } = yargs(hideBin(process.argv))
51
52
  }
52
53
  )
53
54
  .command('conf:generate',
54
- 'Generates a new config file',
55
+ 'Generates a new config file: config/default.json from config/default.json.example',
55
56
  (yargs) => {
56
57
  return yargs
57
58
  },
@@ -60,7 +61,7 @@ const { argv } = yargs(hideBin(process.argv))
60
61
  }
61
62
  )
62
63
  .command('admin:generate',
63
- 'Generates a new admin user',
64
+ 'Generates a new admin user in database table: users',
64
65
  (yargs) => {
65
66
  return yargs
66
67
  },
@@ -258,6 +259,9 @@ async function startGenerateConf() {
258
259
  console.log('Generate conf...');
259
260
  const sourceFileName = 'config/default.json.example';
260
261
  const destinationFileName = 'config/default.json';
262
+ if(await startCheckIfFileExists(destinationFileName)) {
263
+ process.exit(1);
264
+ }
261
265
  try {
262
266
  await fse.copyFile(sourceFileName, destinationFileName)
263
267
  } catch (error) {