nodefony 7.0.0-beta.8 → 7.0.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.
Files changed (138) hide show
  1. package/CHANGELOG.md +375 -8505
  2. package/README.md +30 -27
  3. package/autoloader.es6 +46 -48
  4. package/builder.es6 +66 -76
  5. package/cli/builder/bundles/bundle.js +57 -63
  6. package/cli/builder/bundles/controller.js +34 -38
  7. package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
  8. package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
  9. package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +27 -38
  10. package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
  11. package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
  12. package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
  13. package/cli/builder/bundles/users-bundle/Resources/config/config.js +13 -6
  14. package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
  15. package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
  16. package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
  17. package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
  18. package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -77
  19. package/cli/builder/bundles/users-bundle/Resources/js/users.js +3 -0
  20. package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
  21. package/cli/builder/bundles/users-bundle/Resources/scss/custom.scss +6 -4
  22. package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
  23. package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
  24. package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +12 -14
  25. package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
  26. package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
  27. package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -35
  28. package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
  29. package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
  30. package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
  31. package/cli/builder/bundles/users-bundle/package.json +29 -27
  32. package/cli/builder/bundles/users-bundle/readme.md +7 -7
  33. package/cli/builder/bundles/users-bundle/services/usersService.js +103 -112
  34. package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
  35. package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
  36. package/cli/builder/bundles/users-bundle/tests/loginTest.js +122 -72
  37. package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
  38. package/cli/builder/microService/microService.js +139 -141
  39. package/cli/builder/microService/skeletons/package.json +23 -22
  40. package/cli/builder/project/project.js +228 -181
  41. package/cli/builder/project/skeletons/README.md +30 -27
  42. package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
  43. package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
  44. package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
  45. package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
  46. package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
  47. package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
  48. package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
  49. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
  50. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
  51. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
  52. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
  53. package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
  54. package/cli/builder/project/skeletons/package.json.twig +71 -0
  55. package/cli/builder/react/reactBuilder.js +59 -65
  56. package/cli/builder/sandbox/sandBoxBuilder.js +134 -136
  57. package/cli/builder/sandbox/skeletons/bootstrap/custom.scss +5 -3
  58. package/cli/builder/skeletons/app/appKernel.js +120 -2
  59. package/cli/builder/skeletons/config/config.js +1 -1
  60. package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
  61. package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +37 -12
  62. package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
  63. package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
  64. package/cli/builder/skeletons/package.json.twig +57 -0
  65. package/cli/builder/skeletons/unittest/testFile.js +44 -45
  66. package/cli/builder/vue/skeletons/vue.config.js +84 -10
  67. package/cli/builder/vue/vueBuilder.js +116 -114
  68. package/cli/generate/generate.es6 +38 -39
  69. package/cli/install/install.js +45 -58
  70. package/cli/sequelize/sequelize.js +50 -39
  71. package/cli/start.js +353 -347
  72. package/cli/tools/pm2.es6 +55 -57
  73. package/cli/tools/tools.es6 +36 -37
  74. package/cli.es6 +270 -243
  75. package/container.es6 +51 -59
  76. package/error.es6 +25 -27
  77. package/fileClass.es6 +53 -55
  78. package/finder/file.es6 +5 -4
  79. package/finder/fileResult.es6 +23 -22
  80. package/finder/finder2.es6 +46 -54
  81. package/finder.es6 +88 -97
  82. package/kernel/annotations/annotations.es6 +44 -46
  83. package/kernel/api/api.es6 +6 -8
  84. package/kernel/api/graphqlApi.es6 +21 -21
  85. package/kernel/api/jsonApi.es6 +40 -45
  86. package/kernel/api/openApi.es6 +9 -11
  87. package/kernel/api/schemas/openApiSchema.js +61 -32
  88. package/kernel/babylon.es6 +31 -38
  89. package/kernel/bundle.es6 +230 -228
  90. package/kernel/cliKernel.es6 +157 -170
  91. package/kernel/command.es6 +17 -20
  92. package/kernel/commands/nodefonyCommand.es6 +111 -58
  93. package/kernel/commands/tasks/bundlesTask.es6 +14 -19
  94. package/kernel/controllers/controller.es6 +167 -180
  95. package/kernel/fixture.es6 +4 -7
  96. package/kernel/injections/injections.es6 +97 -103
  97. package/kernel/kernel.es6 +670 -397
  98. package/kernel/kernelWatcher.es6 +64 -54
  99. package/kernel/orm/entity.es6 +10 -12
  100. package/kernel/orm/orm.es6 +65 -51
  101. package/kernel/reader.es6 +45 -47
  102. package/kernel/security/encoder.es6 +8 -6
  103. package/kernel/security/factories/factory.es6 +34 -37
  104. package/kernel/security/factories/passeportFactory.es6 +13 -14
  105. package/kernel/security/provider.es6 +11 -13
  106. package/kernel/security/providers/chainProvider.es6 +13 -28
  107. package/kernel/security/providers/memoryProvider.es6 +7 -11
  108. package/kernel/security/providers/providerManager.es6 +11 -14
  109. package/kernel/security/providers/userEntityProvider.es6 +7 -8
  110. package/kernel/security/role.es6 +3 -3
  111. package/kernel/security/secureArea.es6 +143 -152
  112. package/kernel/security/tokens/token.es6 +30 -32
  113. package/kernel/security/user.es6 +19 -19
  114. package/kernel/serviceRealTime.es6 +5 -7
  115. package/kernel/services/connectionsService.es6 +20 -22
  116. package/kernel/services/cron/cronService.es6 +14 -16
  117. package/kernel/task.es6 +20 -26
  118. package/kernel/templates.es6 +4 -5
  119. package/kernel/templating/twig.es6 +56 -47
  120. package/kernel/tests/cliTest.js +7 -11
  121. package/kernel/tests/containerTest.js +25 -37
  122. package/kernel/tests/kernelTest.js +9 -16
  123. package/nodefony.es6 +279 -256
  124. package/notificationsCenter.es6 +28 -20
  125. package/package.json +55 -55
  126. package/protocol.es6 +19 -21
  127. package/protocols/bayeux.es6 +35 -38
  128. package/protocols/jsonRpc/jsonrpc.es6 +12 -14
  129. package/result.es6 +11 -12
  130. package/service.es6 +62 -62
  131. package/syslog/pdu.es6 +99 -91
  132. package/syslog/syslog.es6 +101 -102
  133. package/watcher.es6 +21 -20
  134. package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
  135. package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
  136. package/cli/builder/project/skeletons/package.json.skeleton +0 -53
  137. package/cli/builder/sandbox/skeletons/bootstrap/awesome/font-awesome.config.js +0 -11
  138. package/cli/builder/skeletons/package.json +0 -61
@@ -1,8 +1,7 @@
1
1
  const regController = /^(.*)Controller$/;
2
2
 
3
3
  class generateController extends nodefony.Builder {
4
-
5
- constructor(cli, options = {}) {
4
+ constructor (cli, options = {}) {
6
5
  super(cli, cli.cmd, cli.args);
7
6
  this.directory = "controller";
8
7
  this.bundle = this.kernel.getBundle("app");
@@ -13,65 +12,62 @@ class generateController extends nodefony.Builder {
13
12
  directory: this.directory,
14
13
  bundle: this.bundle.name,
15
14
  controllerName: "defaultController",
16
- shortName:"default"
15
+ shortName: "default"
17
16
  }, options);
18
-
19
17
  }
20
18
 
21
- interaction( ) {
19
+ interaction () {
22
20
  return this.cli.prompt([{
23
- type: 'input',
24
- name: 'controllerName',
25
- default: (response) => {
26
- if (response.bundle === "Quit") {
27
- return Promise.reject("Quit");
28
- }
29
- return `${this.bundle.name}Controller`;
30
- },
31
- message: `Enter Controller Name : `,
32
- validate: (value, response) => {
33
- if (value) {
34
- try {
35
- this.checkName( value, response);
36
- } catch (e) {
37
- return e.message;
38
- }
39
- return true;
21
+ type: "input",
22
+ name: "controllerName",
23
+ default: (response) => {
24
+ if (response.bundle === "Quit") {
25
+ return Promise.reject("Quit");
26
+ }
27
+ return `${this.bundle.name}Controller`;
28
+ },
29
+ message: "Enter Controller Name : ",
30
+ validate: (value, response) => {
31
+ if (value) {
32
+ try {
33
+ this.checkName(value, response);
34
+ } catch (e) {
35
+ return e.message;
40
36
  }
41
- return `${value} Unauthorised Please enter a valid Controller name`;
37
+ return true;
42
38
  }
39
+ return `${value} Unauthorised Please enter a valid Controller name`;
40
+ }
43
41
  }]);
44
42
  }
45
43
 
46
- setBundle(bundle){
47
- this.bundle = bundle ;
48
- this.response.bundle = bundle.name ;
49
- //console.log(this.response)
50
- //console.log(this.bundle.bundleName)
51
- this.response.bundleName = this.bundle.bundleName ;
44
+ setBundle (bundle) {
45
+ this.bundle = bundle;
46
+ this.response.bundle = bundle.name;
47
+ // console.log(this.response)
48
+ // console.log(this.bundle.bundleName)
49
+ this.response.bundleName = this.bundle.bundleName;
52
50
  this.setLocation(path.resolve(bundle.path, "controller"));
53
51
  }
54
52
 
55
- createBuilder() {
53
+ createBuilder () {
56
54
  this.buildFront(this.response, this.bundle.path);
57
55
  return this.Front.generateController(this.response.directory);
58
56
  }
59
57
 
60
- checkName(name, response) {
61
- let res = regController.exec(name);
58
+ checkName (name, response) {
59
+ const res = regController.exec(name);
62
60
  this.shortName = null;
63
61
  if (res) {
64
62
  this.name = name;
65
63
  this.shortName = res[1];
66
- response.name = this.shortName ;
67
- response.shortName = this.shortName ;
68
- response.directory = this.shortName ;
64
+ response.name = this.shortName;
65
+ response.shortName = this.shortName;
66
+ response.directory = this.shortName;
69
67
  } else {
70
- throw new Error("Bad controller name : " + name);
68
+ throw new Error(`Bad controller name : ${name}`);
71
69
  }
72
70
  }
73
-
74
-
75
71
  }
76
72
 
77
73
  module.exports = generateController;
@@ -1,15 +1,16 @@
1
1
  class fixtureTask extends nodefony.Task {
2
-
3
- constructor(name, command) {
2
+ constructor (name, command) {
4
3
  super(name, command);
5
4
  this.bundle = command.bundle;
6
5
  }
7
6
 
8
- showHelp() {
9
- this.setHelp("users:fixtures:default",
7
+ showHelp () {
8
+ this.setHelp(
9
+ "users:fixtures:default",
10
10
  "Generate admin, anonymous and 3 common users `nodefony users:fixtures:default` "
11
11
  );
12
- this.setHelp("users:fixtures:random nb",
12
+ this.setHelp(
13
+ "users:fixtures:random nb",
13
14
  "Generate ramdom users with faker `nodefony users:fixtures:random 10` "
14
15
  );
15
16
  }
@@ -19,30 +20,28 @@ class fixtureTask extends nodefony.Task {
19
20
  const fixtures = this.bundle.getFixture("users");
20
21
  if (fixtures) {
21
22
  this.log(`LOAD FIXTURES users : ${args}`, "INFO");
22
- let inst = new fixtures(this.container);
23
+ const inst = new fixtures(this.container);
23
24
  return await inst.run(args);
24
25
  }
25
- throw new Error(`users fixtures not found `);
26
-
26
+ throw new Error("users fixtures not found ");
27
27
  } catch (e) {
28
28
  throw e;
29
29
  }
30
30
  }
31
31
 
32
- async random(args = null) {
32
+ async random (args = null) {
33
33
  try {
34
34
  const fixtures = this.bundle.getFixture("users");
35
35
  if (fixtures) {
36
36
  this.log(`RANDOM FIXTURES users : ${args}`, "INFO");
37
- let inst = new fixtures(this.container);
37
+ const inst = new fixtures(this.container);
38
38
  return await inst.run(args);
39
39
  }
40
- throw new Error(`users fixtures not found `);
40
+ throw new Error("users fixtures not found ");
41
41
  } catch (e) {
42
42
  throw e;
43
43
  }
44
44
  }
45
-
46
45
  }
47
46
 
48
47
  module.exports = fixtureTask;
@@ -1,26 +1,29 @@
1
1
  const fixtureTask = require(path.resolve(__dirname, "fixtureTask.js"));
2
2
 
3
3
  class usersCommand extends nodefony.Command {
4
- constructor(cli, bundle) {
4
+ constructor (cli, bundle) {
5
5
  super("users", cli, bundle);
6
6
  this.usersService = this.get("users");
7
7
  this.setTask("fixtures", fixtureTask);
8
8
  }
9
9
 
10
- showHelp() {
11
- this.setHelp("users:show [user]",
10
+ showHelp () {
11
+ this.setHelp(
12
+ "users:show [user]",
12
13
  "nodefony users:show admin"
13
14
  );
14
- this.setHelp("users:find [--json] username",
15
+ this.setHelp(
16
+ "users:find [--json] username",
15
17
  "nodefony --json users:find admin"
16
18
  );
17
- this.setHelp("users:findAll [--json]",
19
+ this.setHelp(
20
+ "users:findAll [--json]",
18
21
  "nodefony --json users:findAll"
19
22
  );
20
23
  super.showHelp();
21
24
  }
22
25
 
23
- async show(username) {
26
+ async show (username) {
24
27
  let obj = null;
25
28
  if (username) {
26
29
  obj = await this.find(username);
@@ -29,43 +32,40 @@ class usersCommand extends nodefony.Command {
29
32
  }
30
33
  }
31
34
 
32
- find(username) {
35
+ find (username) {
33
36
  return this.usersService.findOne(username)
34
37
  .then((res) => {
35
38
  if (this.cli.commander.opts().json) {
36
39
  return process.stdout.write(`${JSON.stringify(res)}\n`);
37
- } else {
38
- return this.display(res);
39
40
  }
40
- }).catch(e => {
41
+ return this.display(res);
42
+ })
43
+ .catch((e) => {
41
44
  if (this.cli.commander.opts().json) {
42
45
  return process.stdout.write(`${JSON.stringify({})}\n`);
43
- } else {
44
- throw e;
45
46
  }
47
+ throw e;
46
48
  });
47
49
  }
48
50
 
49
- findAll() {
51
+ findAll () {
50
52
  return this.usersService.find()
51
53
  .then((res) => {
52
54
  if (this.cli.commander.opts().json) {
53
55
  return process.stdout.write(`${JSON.stringify(res.rows)}\n`);
54
- } else {
55
- return this.display(res.rows);
56
56
  }
57
+ return this.display(res.rows);
57
58
  })
58
- .catch(e => {
59
+ .catch((e) => {
59
60
  if (this.cli.commander.opts().json) {
60
61
  return process.stdout.write(`${JSON.stringify({})}\n`);
61
- } else {
62
- throw e;
63
62
  }
63
+ throw e;
64
64
  });
65
65
  }
66
66
 
67
- display(obj) {
68
- this.cli.logger("START TABLE : " + this.cli.getEmoji("clapper"));
67
+ display (obj) {
68
+ this.cli.logger(`START TABLE : ${this.cli.getEmoji("clapper")}`);
69
69
  const type = nodefony.typeOf(obj);
70
70
  if (type === "object" || type === null) {
71
71
  if (!obj) {
@@ -74,7 +74,7 @@ class usersCommand extends nodefony.Command {
74
74
  obj = [obj];
75
75
  }
76
76
  }
77
- let options = {
77
+ const options = {
78
78
  head: [
79
79
  "username",
80
80
  "First Name",
@@ -85,7 +85,7 @@ class usersCommand extends nodefony.Command {
85
85
  "Enabled"
86
86
  ]
87
87
  };
88
- let table = this.cli.displayTable([], options);
88
+ const table = this.cli.displayTable([], options);
89
89
  for (let i = 0; i < obj.length; i++) {
90
90
  const user = obj[i];
91
91
  table.push([
@@ -99,8 +99,7 @@ class usersCommand extends nodefony.Command {
99
99
  ]);
100
100
  }
101
101
  console.log(table.toString());
102
- this.cli.logger("END TABLE : " + this.cli.getEmoji("checkered_flag"));
102
+ this.cli.logger(`END TABLE : ${this.cli.getEmoji("checkered_flag")}`);
103
103
  }
104
-
105
104
  }
106
105
  module.exports = usersCommand;
@@ -5,29 +5,18 @@
5
5
  *
6
6
  *
7
7
  */
8
- //const Mongoose = require('mongoose');
9
- const Schema = require('mongoose').Schema;
10
- const mongoosePaginate = require('mongoose-paginate-v2');
11
- const validator = require('validator');
8
+ // const Mongoose = require('mongoose');
9
+ const {Schema} = require("mongoose");
10
+ const mongoosePaginate = require("mongoose-paginate-v2");
11
+ const validator = require("validator");
12
12
 
13
13
  class userEntity extends nodefony.Entity {
14
-
15
- constructor(bundle) {
16
- /*
17
- * @param bundle instance
18
- * @param Entity name
19
- * @param orm name
20
- * @param connection name
21
- */
14
+ constructor (bundle) {
22
15
  super(bundle, "user", "mongoose", "nodefony");
23
- this.once("onConnect", (name, db) => {
24
- this.model = this.registerModel(db);
25
- this.orm.setEntity(this);
26
- });
27
16
  }
28
17
 
29
- getSchema() {
30
- //const encodePassword = this.encode.bind(this);
18
+ getSchema () {
19
+ // const encodePassword = this.encode.bind(this);
31
20
  return {
32
21
  username: {
33
22
  type: String,
@@ -65,7 +54,7 @@ class userEntity extends nodefony.Entity {
65
54
  type: String,
66
55
  unique: true,
67
56
  required: true,
68
- validate: [validator.isEmail, 'invalid email {VALUE}'],
57
+ validate: [validator.isEmail, "invalid email {VALUE}"],
69
58
  createIndexes: {
70
59
  unique: true
71
60
  }
@@ -78,7 +67,7 @@ class userEntity extends nodefony.Entity {
78
67
  if (value === "") {
79
68
  return true;
80
69
  }
81
- return validator.matches(value, /[^\w]|_|-|.|'/g);
70
+ return validator.matches(value, /[^\w]|_|-|.|'/gu);
82
71
  },
83
72
  message: "name allow alphanumeric characters {VALUE}"
84
73
  }
@@ -91,7 +80,7 @@ class userEntity extends nodefony.Entity {
91
80
  if (value === "") {
92
81
  return true;
93
82
  }
94
- return validator.matches(value, /[^\w]|_|-|.|'/g);
83
+ return validator.matches(value, /[^\w]|_|-|.|'/gu);
95
84
  },
96
85
  message: "surname allow alphanumeric characters {VALUE}"
97
86
  }
@@ -117,8 +106,8 @@ class userEntity extends nodefony.Entity {
117
106
  };
118
107
  }
119
108
 
120
- validPassword(value) {
121
- let valid = validator.isLength(value, {
109
+ validPassword (value) {
110
+ const valid = validator.isLength(value, {
122
111
  min: 4,
123
112
  max: undefined
124
113
  });
@@ -128,46 +117,46 @@ class userEntity extends nodefony.Entity {
128
117
  return value;
129
118
  }
130
119
 
131
- registerModel(db) {
132
- let mySchema = new Schema(this.getSchema(), {
120
+ registerModel (db) {
121
+ const mySchema = new Schema(this.getSchema(), {
133
122
  timestamps: {
134
- createdAt: 'createdAt',
135
- updatedAt: 'updatedAt'
123
+ createdAt: "createdAt",
124
+ updatedAt: "updatedAt"
136
125
  }
137
126
  });
138
127
  mySchema.plugin(mongoosePaginate);
139
- let entity = this;
140
- mySchema.pre('save', function (next) {
141
- if (!this.isModified('password')) {
128
+ const entity = this;
129
+ mySchema.pre("save", function (next) {
130
+ if (!this.isModified("password")) {
142
131
  return next();
143
132
  }
144
133
  entity.logger("hash password ", "DEBUG");
145
134
  entity.validPassword(this.password);
146
135
  return entity.encode(this.password)
147
- .then(hash => {
136
+ .then((hash) => {
148
137
  entity.logger(hash, "DEBUG");
149
138
  this.password = hash;
150
139
  return hash;
151
140
  })
152
- .catch(err => {
141
+ .catch((err) => {
153
142
  entity.logger(err, "ERROR");
154
143
  throw err;
155
144
  });
156
145
  });
157
- mySchema.pre('updateOne', function (next) {
158
- //const data = this.getUpdate();
159
- let password = this.get("password");
146
+ mySchema.pre("updateOne", function (next) {
147
+ // const data = this.getUpdate();
148
+ const password = this.get("password");
160
149
  if (!password) {
161
150
  return next();
162
151
  }
163
152
  entity.logger("update password hash", "DEBUG");
164
153
  entity.validPassword(password);
165
154
  return entity.encode(password)
166
- .then(hash => {
155
+ .then((hash) => {
167
156
  entity.logger(hash, "DEBUG");
168
157
  this._update.password = hash;
169
158
  })
170
- .catch(err => {
159
+ .catch((err) => {
171
160
  entity.logger(err, "ERROR");
172
161
  throw err;
173
162
  });
@@ -176,4 +165,4 @@ class userEntity extends nodefony.Entity {
176
165
  }
177
166
  }
178
167
 
179
- module.exports = userEntity;
168
+ module.exports = userEntity;
@@ -2,8 +2,9 @@ const {
2
2
  Sequelize,
3
3
  DataTypes,
4
4
  Model
5
- } = nodefony.Sequelize; //require("sequelize");
6
- const validator = require('validator');
5
+ } = nodefony.Sequelize; // require("sequelize");
6
+ const validator = require("validator");
7
+
7
8
  /*
8
9
  *
9
10
  *
@@ -12,8 +13,8 @@ const validator = require('validator');
12
13
  *
13
14
  */
14
15
  class userEntity extends nodefony.Entity {
16
+ constructor (bundle) {
15
17
 
16
- constructor(bundle) {
17
18
  /*
18
19
  * @param bundle instance
19
20
  * @param Entity name
@@ -21,7 +22,8 @@ class userEntity extends nodefony.Entity {
21
22
  * @param connection name
22
23
  */
23
24
  super(bundle, "user", "sequelize", "nodefony");
24
- /*this.orm.on("onOrmReady", ( orm ) => {
25
+
26
+ /* this.orm.on("onOrmReady", ( orm ) => {
25
27
  let session = this.orm.getEntity("session");
26
28
  if (session) {
27
29
  this.model.hasMany(session, {
@@ -35,7 +37,8 @@ class userEntity extends nodefony.Entity {
35
37
  });*/
36
38
  }
37
39
 
38
- getSchema() {
40
+ // eslint-disable-next-line max-lines-per-function
41
+ getSchema () {
39
42
  return {
40
43
  username: {
41
44
  type: DataTypes.STRING(126),
@@ -45,9 +48,10 @@ class userEntity extends nodefony.Entity {
45
48
  validate: {
46
49
  is: {
47
50
  args: /^[\w-_.]+$/,
48
- msg: `username allow alphanumeric and ( _ | - | . ) characters`
51
+ msg: "username allow alphanumeric and ( _ | - | . ) characters"
49
52
  }
50
- /*notIn: {
53
+
54
+ /* notIn: {
51
55
  args: [['admin', 'root']],
52
56
  msg: `username don't allow (admin , root) login name`
53
57
  }*/
@@ -55,13 +59,14 @@ class userEntity extends nodefony.Entity {
55
59
  },
56
60
  password: {
57
61
  type: DataTypes.STRING(256),
58
- allowNull: false,
59
- validate: {
62
+ allowNull: false
63
+
64
+ /* validate: {
60
65
  min: {
61
66
  args: [[4]],
62
- msg: `password allow 4 characters min `
67
+ msg: "password allow 4 characters min "
63
68
  }
64
- }
69
+ }*/
65
70
  },
66
71
  "2fa": {
67
72
  type: DataTypes.BOOLEAN,
@@ -86,7 +91,7 @@ class userEntity extends nodefony.Entity {
86
91
  },
87
92
  email: {
88
93
  type: DataTypes.STRING,
89
- //primaryKey: true,
94
+ // primaryKey: true,
90
95
  unique: true,
91
96
  allowNull: false,
92
97
  validate: {
@@ -101,7 +106,7 @@ class userEntity extends nodefony.Entity {
101
106
  validate: {
102
107
  is: {
103
108
  args: /^[\w-_.]*$/,
104
- msg: `name allow alphanumeric characters`
109
+ msg: "name allow alphanumeric characters"
105
110
  }
106
111
  }
107
112
  },
@@ -111,7 +116,7 @@ class userEntity extends nodefony.Entity {
111
116
  validate: {
112
117
  is: {
113
118
  args: /^[\w-_.]*$/,
114
- msg: `surname allow alphanumeric characters`
119
+ msg: "surname allow alphanumeric characters"
115
120
  }
116
121
  }
117
122
  },
@@ -122,9 +127,9 @@ class userEntity extends nodefony.Entity {
122
127
  roles: {
123
128
  type: DataTypes.JSON,
124
129
  defaultValue: ["ROLE_USER"],
125
- get(key) {
130
+ get (key) {
126
131
  let val = this.getDataValue(key);
127
- if (typeof (val) === "string") {
132
+ if (typeof val === "string") {
128
133
  val = JSON.parse(val);
129
134
  }
130
135
  return val;
@@ -145,8 +150,8 @@ class userEntity extends nodefony.Entity {
145
150
  };
146
151
  }
147
152
 
148
- validPassword(value) {
149
- let valid = validator.isLength(value, {
153
+ validPassword (value) {
154
+ const valid = validator.isLength(value, {
150
155
  min: 4,
151
156
  max: undefined
152
157
  });
@@ -156,17 +161,22 @@ class userEntity extends nodefony.Entity {
156
161
  return value;
157
162
  }
158
163
 
159
- registerModel(db) {
164
+ registerModel (db) {
160
165
  class MyModel extends Model {
161
- hasRole(name){
162
- for (let role in this.roles) {
166
+ static associate (models) {
167
+ // define association here
168
+ }
169
+
170
+ hasRole (name) {
171
+ for (const role in this.roles) {
163
172
  if (this.roles[role] === name) {
164
173
  return true;
165
174
  }
166
175
  }
167
176
  return false;
168
177
  }
169
- isGranted(role){
178
+
179
+ isGranted (role) {
170
180
  return this.hasRole(role);
171
181
  }
172
182
  }
@@ -175,12 +185,13 @@ class userEntity extends nodefony.Entity {
175
185
  modelName: this.name,
176
186
  hooks: {
177
187
  beforeCreate: (user) => {
188
+ console.log("beforeCreate", user);
178
189
  this.validPassword(user.password);
179
190
  return this.encode(user.password)
180
- .then(hash => {
191
+ .then((hash) => {
181
192
  user.password = hash;
182
193
  })
183
- .catch(err => {
194
+ .catch((err) => {
184
195
  this.logger(err, "ERROR");
185
196
  throw err;
186
197
  });
@@ -189,10 +200,10 @@ class userEntity extends nodefony.Entity {
189
200
  if ("password" in userUpate.attributes) {
190
201
  this.validPassword(userUpate.attributes.password);
191
202
  return this.encode(userUpate.attributes.password)
192
- .then(hash => {
203
+ .then((hash) => {
193
204
  userUpate.attributes.password = hash;
194
205
  })
195
- .catch(err => {
206
+ .catch((err) => {
196
207
  this.logger(err, "ERROR");
197
208
  throw err;
198
209
  });
@@ -200,19 +211,19 @@ class userEntity extends nodefony.Entity {
200
211
  }
201
212
  },
202
213
  freezeTableName: true,
203
- //add indexes
214
+ // add indexes
204
215
  indexes: [{
205
216
  unique: true,
206
- fields: ['email']
217
+ fields: ["email"]
207
218
  }]
208
219
  // add custom validations
209
- //validate: {}
220
+ // validate: {}
210
221
  });
211
222
  return MyModel;
212
223
  }
213
224
 
214
- logger(pci /*, sequelize*/ ) {
215
- const msgid = "Entity " + this.name;
225
+ logger (pci /* , sequelize*/) {
226
+ const msgid = `Entity ${this.name}`;
216
227
  return super.logger(pci, "DEBUG", msgid);
217
228
  }
218
229
  }