@adaptivestone/framework 4.1.0 → 4.2.0
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/CHANGELOG.md
CHANGED
package/commands/CreateUser.js
CHANGED
|
@@ -4,21 +4,63 @@ const AbstractCommand = require('../modules/AbstractCommand');
|
|
|
4
4
|
class CreateUser extends AbstractCommand {
|
|
5
5
|
async run() {
|
|
6
6
|
const User = this.app.getModel('User');
|
|
7
|
-
const { email, password, roles } = this.args;
|
|
7
|
+
const { id, email, password, roles, update } = this.args;
|
|
8
8
|
|
|
9
|
-
if (!email
|
|
9
|
+
if (!email && !id) {
|
|
10
10
|
this.logger.error('Input validation failded');
|
|
11
|
-
this.logger.error('Please add "email"
|
|
11
|
+
this.logger.error('Please add "email" or "id" variables');
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
|
|
15
|
+
let user;
|
|
16
|
+
|
|
17
|
+
if (id) {
|
|
18
|
+
user = await User.findOne({ _id: id });
|
|
19
|
+
} else if (email) {
|
|
20
|
+
user = await User.findOne({ email });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (user && !update) {
|
|
24
|
+
this.logger.error(
|
|
25
|
+
'We are found a user in database. But "update" option is not providing. Exitin',
|
|
26
|
+
);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!user && !password) {
|
|
31
|
+
this.logger.error(
|
|
32
|
+
'For a new user we alway asking for a password. Please provide it and rerun command',
|
|
33
|
+
);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!user && !email) {
|
|
38
|
+
this.logger.error(
|
|
39
|
+
'For a new user we alway asking for a email. Please provide it and rerun command',
|
|
40
|
+
);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!user) {
|
|
45
|
+
user = new User();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (password) {
|
|
49
|
+
user.password = password;
|
|
50
|
+
}
|
|
51
|
+
if (email) {
|
|
52
|
+
user.email = email;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (roles) {
|
|
56
|
+
user.roles = roles.split(',');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await user.save();
|
|
60
|
+
|
|
19
61
|
await user.generateToken();
|
|
20
62
|
|
|
21
|
-
this.logger.info(`User was created ${JSON.stringify(user, 0, 4)}`);
|
|
63
|
+
this.logger.info(`User was created/updated ${JSON.stringify(user, 0, 4)}`);
|
|
22
64
|
|
|
23
65
|
return user;
|
|
24
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
const RateLimiter = require('./RateLimiter');
|
|
2
2
|
|
|
3
3
|
describe('rate limiter methods', () => {
|
|
4
|
+
it('have description fields', async () => {
|
|
5
|
+
expect.assertions(1);
|
|
6
|
+
const middleware = new RateLimiter(global.server.app, {
|
|
7
|
+
driver: 'redis',
|
|
8
|
+
});
|
|
9
|
+
expect(middleware.constructor.description).toBeDefined();
|
|
10
|
+
});
|
|
11
|
+
|
|
4
12
|
it('can create redis rateLimiter', async () => {
|
|
5
13
|
expect.assertions(1);
|
|
6
14
|
|