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.
- package/CHANGELOG.md +375 -8505
- package/README.md +30 -27
- package/autoloader.es6 +46 -48
- package/builder.es6 +66 -76
- package/cli/builder/bundles/bundle.js +57 -63
- package/cli/builder/bundles/controller.js +34 -38
- package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
- package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
- package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +27 -38
- package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
- package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
- package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
- package/cli/builder/bundles/users-bundle/Resources/config/config.js +13 -6
- package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
- package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -77
- package/cli/builder/bundles/users-bundle/Resources/js/users.js +3 -0
- package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
- package/cli/builder/bundles/users-bundle/Resources/scss/custom.scss +6 -4
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
- package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +12 -14
- package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
- package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
- package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -35
- package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
- package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
- package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
- package/cli/builder/bundles/users-bundle/package.json +29 -27
- package/cli/builder/bundles/users-bundle/readme.md +7 -7
- package/cli/builder/bundles/users-bundle/services/usersService.js +103 -112
- package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
- package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
- package/cli/builder/bundles/users-bundle/tests/loginTest.js +122 -72
- package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
- package/cli/builder/microService/microService.js +139 -141
- package/cli/builder/microService/skeletons/package.json +23 -22
- package/cli/builder/project/project.js +228 -181
- package/cli/builder/project/skeletons/README.md +30 -27
- package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
- package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
- package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
- package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
- package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
- package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
- package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
- package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
- package/cli/builder/project/skeletons/package.json.twig +71 -0
- package/cli/builder/react/reactBuilder.js +59 -65
- package/cli/builder/sandbox/sandBoxBuilder.js +134 -136
- package/cli/builder/sandbox/skeletons/bootstrap/custom.scss +5 -3
- package/cli/builder/skeletons/app/appKernel.js +120 -2
- package/cli/builder/skeletons/config/config.js +1 -1
- package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
- package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +37 -12
- package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
- package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
- package/cli/builder/skeletons/package.json.twig +57 -0
- package/cli/builder/skeletons/unittest/testFile.js +44 -45
- package/cli/builder/vue/skeletons/vue.config.js +84 -10
- package/cli/builder/vue/vueBuilder.js +116 -114
- package/cli/generate/generate.es6 +38 -39
- package/cli/install/install.js +45 -58
- package/cli/sequelize/sequelize.js +50 -39
- package/cli/start.js +353 -347
- package/cli/tools/pm2.es6 +55 -57
- package/cli/tools/tools.es6 +36 -37
- package/cli.es6 +270 -243
- package/container.es6 +51 -59
- package/error.es6 +25 -27
- package/fileClass.es6 +53 -55
- package/finder/file.es6 +5 -4
- package/finder/fileResult.es6 +23 -22
- package/finder/finder2.es6 +46 -54
- package/finder.es6 +88 -97
- package/kernel/annotations/annotations.es6 +44 -46
- package/kernel/api/api.es6 +6 -8
- package/kernel/api/graphqlApi.es6 +21 -21
- package/kernel/api/jsonApi.es6 +40 -45
- package/kernel/api/openApi.es6 +9 -11
- package/kernel/api/schemas/openApiSchema.js +61 -32
- package/kernel/babylon.es6 +31 -38
- package/kernel/bundle.es6 +230 -228
- package/kernel/cliKernel.es6 +157 -170
- package/kernel/command.es6 +17 -20
- package/kernel/commands/nodefonyCommand.es6 +111 -58
- package/kernel/commands/tasks/bundlesTask.es6 +14 -19
- package/kernel/controllers/controller.es6 +167 -180
- package/kernel/fixture.es6 +4 -7
- package/kernel/injections/injections.es6 +97 -103
- package/kernel/kernel.es6 +670 -397
- package/kernel/kernelWatcher.es6 +64 -54
- package/kernel/orm/entity.es6 +10 -12
- package/kernel/orm/orm.es6 +65 -51
- package/kernel/reader.es6 +45 -47
- package/kernel/security/encoder.es6 +8 -6
- package/kernel/security/factories/factory.es6 +34 -37
- package/kernel/security/factories/passeportFactory.es6 +13 -14
- package/kernel/security/provider.es6 +11 -13
- package/kernel/security/providers/chainProvider.es6 +13 -28
- package/kernel/security/providers/memoryProvider.es6 +7 -11
- package/kernel/security/providers/providerManager.es6 +11 -14
- package/kernel/security/providers/userEntityProvider.es6 +7 -8
- package/kernel/security/role.es6 +3 -3
- package/kernel/security/secureArea.es6 +143 -152
- package/kernel/security/tokens/token.es6 +30 -32
- package/kernel/security/user.es6 +19 -19
- package/kernel/serviceRealTime.es6 +5 -7
- package/kernel/services/connectionsService.es6 +20 -22
- package/kernel/services/cron/cronService.es6 +14 -16
- package/kernel/task.es6 +20 -26
- package/kernel/templates.es6 +4 -5
- package/kernel/templating/twig.es6 +56 -47
- package/kernel/tests/cliTest.js +7 -11
- package/kernel/tests/containerTest.js +25 -37
- package/kernel/tests/kernelTest.js +9 -16
- package/nodefony.es6 +279 -256
- package/notificationsCenter.es6 +28 -20
- package/package.json +55 -55
- package/protocol.es6 +19 -21
- package/protocols/bayeux.es6 +35 -38
- package/protocols/jsonRpc/jsonrpc.es6 +12 -14
- package/result.es6 +11 -12
- package/service.es6 +62 -62
- package/syslog/pdu.es6 +99 -91
- package/syslog/syslog.es6 +101 -102
- package/watcher.es6 +21 -20
- package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
- package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
- package/cli/builder/project/skeletons/package.json.skeleton +0 -53
- package/cli/builder/sandbox/skeletons/bootstrap/awesome/font-awesome.config.js +0 -11
- package/cli/builder/skeletons/package.json +0 -61
|
@@ -16,39 +16,41 @@
|
|
|
16
16
|
],
|
|
17
17
|
"repository": {},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
19
|
+
"@withshepherd/faker": "5.5.5",
|
|
20
|
+
"mongoose-paginate-v2": "1.8.1",
|
|
21
|
+
"validator": "13.12.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@babel/core": "7.24.5",
|
|
20
25
|
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
21
26
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
22
|
-
"@babel/preset-env": "
|
|
23
|
-
"@babel/preset-react": "7.
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
+
"@babel/preset-env": "7.24.5",
|
|
28
|
+
"@babel/preset-react": "7.24.1",
|
|
29
|
+
"@fortawesome/fontawesome-free": "6.5.2",
|
|
30
|
+
"@mapbox/node-pre-gyp": "1.0.11",
|
|
31
|
+
"@popperjs/core": "2.11.8",
|
|
32
|
+
"babel-loader": "9.1.3",
|
|
27
33
|
"babel-register": "^6.26.0",
|
|
28
|
-
"bootstrap": "
|
|
34
|
+
"bootstrap": "5.3.3",
|
|
35
|
+
"buffer": "6.0.3",
|
|
29
36
|
"clean-webpack-plugin": "^4.0.0",
|
|
30
37
|
"css-hot-loader": "^1.4.4",
|
|
31
|
-
"css-loader": "
|
|
32
|
-
"expose-loader": "
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"sass": "
|
|
40
|
-
"
|
|
41
|
-
"
|
|
38
|
+
"css-loader": "7.1.1",
|
|
39
|
+
"expose-loader": "5.0.0",
|
|
40
|
+
"html-webpack-plugin": "5.6.0",
|
|
41
|
+
"imports-loader": "5.0.0",
|
|
42
|
+
"jquery": "3.7.1",
|
|
43
|
+
"mini-css-extract-plugin": "2.9.0",
|
|
44
|
+
"node-gyp": "10.1.0",
|
|
45
|
+
"sass": "1.77.2",
|
|
46
|
+
"sass-loader": "14.2.1",
|
|
47
|
+
"sequelize-cli": "6.6.2",
|
|
48
|
+
"stream": "0.0.2",
|
|
49
|
+
"style-loader": "3.3.4",
|
|
42
50
|
"svg-inline-loader": "^0.8.2",
|
|
43
|
-
"terser-webpack-plugin": "5.3.
|
|
44
|
-
"webpack": "5.
|
|
45
|
-
"webpack-merge": "
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@mapbox/node-pre-gyp": "1.0.10",
|
|
49
|
-
"node-gyp": "^9.2.0",
|
|
50
|
-
"sequelize-cli": "^6.5.1",
|
|
51
|
-
"stream": "0.0.2"
|
|
51
|
+
"terser-webpack-plugin": "5.3.10",
|
|
52
|
+
"webpack": "5.91.0",
|
|
53
|
+
"webpack-merge": "5.10.0"
|
|
52
54
|
},
|
|
53
55
|
"license": "CECILL-B",
|
|
54
56
|
"readmeFilename": "README.md",
|
|
@@ -282,10 +282,10 @@ curl -k -X POST --data "refreshToken=refreshToken" https://localhost:5152/jwt/t
|
|
|
282
282
|
```bash
|
|
283
283
|
$ nodefony -h
|
|
284
284
|
|
|
285
|
-
users :
|
|
286
|
-
users:show [user] nodefony users:show admin
|
|
287
|
-
users:find [--json] username nodefony --json users:find admin
|
|
288
|
-
users:findAll [--json] nodefony --json users:findAll
|
|
285
|
+
users :
|
|
286
|
+
users:show [user] nodefony users:show admin
|
|
287
|
+
users:find [--json] username nodefony --json users:find admin
|
|
288
|
+
users:findAll [--json] nodefony --json users:findAll
|
|
289
289
|
|
|
290
290
|
$ nodefony users:show
|
|
291
291
|
|
|
@@ -319,7 +319,7 @@ Thu Dec 05 2019 10:45:22 INFO nodefony : END TABLE : 🏁
|
|
|
319
319
|
|
|
320
320
|
$ nodefony unitest:list:all
|
|
321
321
|
|
|
322
|
-
_ _ _ _ _ _
|
|
322
|
+
_ _ _ _ _ _
|
|
323
323
|
_ _ _ __ (_) | |_ ___ ___ | |_ | | (_) ___ | |_
|
|
324
324
|
| | | | | '_ \ | | | __| / _ \ / __| | __| | | | | / __| | __|
|
|
325
325
|
| |_| | | | | | | | | |_ | __/ \__ \ | |_ | | | | \__ \ | |_
|
|
@@ -333,8 +333,8 @@ Thu Dec 05 2019 10:55:21 INFO COMMAND unitest TASK list : ‣ usersTest.j
|
|
|
333
333
|
|
|
334
334
|
$ nodefony unitest:launch:bundle users
|
|
335
335
|
|
|
336
|
-
_ _ _ _ _
|
|
337
|
-
_ _ _ __ (_) | |_ ___ ___ | |_ | | __ _ _ _ _ __ ___ | |__
|
|
336
|
+
_ _ _ _ _
|
|
337
|
+
_ _ _ __ (_) | |_ ___ ___ | |_ | | __ _ _ _ _ __ ___ | |__
|
|
338
338
|
| | | | | '_ \ | | | __| / _ \ / __| | __| | | / _` | | | | | | '_ \ / __| | '_ \
|
|
339
339
|
| |_| | | | | | | | | |_ | __/ \__ \ | |_ | | | (_| | | |_| | | | | | | (__ | | | |
|
|
340
340
|
\__,_| |_| |_| |_| \__| \___| |___/ \__| |_| \__,_| \__,_| |_| |_| \___| |_| |_|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
/* eslint-disable consistent-return */
|
|
2
|
+
/* eslint-disable default-case */
|
|
3
|
+
/* eslint-disable max-lines-per-function */
|
|
1
4
|
module.exports = class users extends nodefony.Service {
|
|
2
|
-
|
|
3
|
-
constructor(container) {
|
|
5
|
+
constructor (container) {
|
|
4
6
|
super("users", container);
|
|
5
7
|
this.orm = this.kernel.getORM();
|
|
6
8
|
this.ormName = this.orm.name;
|
|
@@ -13,11 +15,11 @@ module.exports = class users extends nodefony.Service {
|
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
initialize() {
|
|
18
|
+
initialize () {
|
|
17
19
|
this.entity = this.orm.getEntity("user");
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
getSchemaAttributes() {
|
|
22
|
+
getSchemaAttributes () {
|
|
21
23
|
switch (this.ormName) {
|
|
22
24
|
case "sequelize":
|
|
23
25
|
return this.entity.rawAttributes;
|
|
@@ -26,11 +28,11 @@ module.exports = class users extends nodefony.Service {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
checkSchema(query) {
|
|
31
|
+
checkSchema (query) {
|
|
30
32
|
try {
|
|
31
33
|
if (query) {
|
|
32
34
|
const attr = this.getSchemaAttributes();
|
|
33
|
-
for (
|
|
35
|
+
for (const ele in query) {
|
|
34
36
|
if (ele in attr) {
|
|
35
37
|
continue;
|
|
36
38
|
}
|
|
@@ -42,7 +44,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
async sanitizeError(error, transaction = null) {
|
|
47
|
+
async sanitizeError (error, transaction = null) {
|
|
46
48
|
this.log(error, "ERROR");
|
|
47
49
|
if (transaction && !transaction.finished) {
|
|
48
50
|
switch (this.ormName) {
|
|
@@ -62,43 +64,39 @@ module.exports = class users extends nodefony.Service {
|
|
|
62
64
|
return error;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
checkAuthorisation(action, user = null, query = null) {
|
|
67
|
+
checkAuthorisation (action, user = null, query = null) {
|
|
66
68
|
if (!user) {
|
|
67
|
-
throw new nodefony.authorizationError(
|
|
69
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
68
70
|
}
|
|
69
|
-
|
|
71
|
+
const obj = {
|
|
70
72
|
isAdmin: user.hasRole("ROLE_ADMIN"),
|
|
71
73
|
isUser: user.hasRole("ROLE_USER"),
|
|
72
|
-
query
|
|
73
|
-
}
|
|
74
|
+
query
|
|
75
|
+
};
|
|
74
76
|
switch (action) {
|
|
75
77
|
case "update":
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
if (!obj.isAdmin) {
|
|
79
|
+
if (query.where) {
|
|
80
|
+
if (user.username !== query.where.username) {
|
|
81
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
80
85
|
}
|
|
81
|
-
}else{
|
|
82
|
-
throw new nodefony.authorizationError('User not authorized', 403)
|
|
83
86
|
}
|
|
84
|
-
|
|
85
|
-
break;
|
|
87
|
+
break;
|
|
86
88
|
case "insert":
|
|
87
89
|
case "delete":
|
|
88
90
|
if (!obj.isAdmin) {
|
|
89
|
-
throw new nodefony.authorizationError(
|
|
91
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
90
92
|
}
|
|
91
93
|
break;
|
|
92
94
|
case "search":
|
|
93
95
|
case "list":
|
|
94
96
|
if (!obj.isAdmin) {
|
|
95
|
-
if (obj.isUser) {
|
|
96
|
-
|
|
97
|
-
} else {
|
|
98
|
-
throw new nodefony.authorizationError('User not authorized', 403)
|
|
97
|
+
if (!obj.isUser) {
|
|
98
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
99
99
|
}
|
|
100
|
-
} else {
|
|
101
|
-
|
|
102
100
|
}
|
|
103
101
|
break;
|
|
104
102
|
case "find":
|
|
@@ -106,29 +104,29 @@ module.exports = class users extends nodefony.Service {
|
|
|
106
104
|
case "findOne":
|
|
107
105
|
if (!obj.isAdmin) {
|
|
108
106
|
if (!obj.isUser) {
|
|
109
|
-
throw new nodefony.authorizationError(
|
|
107
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
110
|
break;
|
|
113
111
|
default:
|
|
114
|
-
throw new nodefony.authorizationError(
|
|
112
|
+
throw new nodefony.authorizationError("Action not authorized", 403);
|
|
115
113
|
}
|
|
116
|
-
return obj
|
|
114
|
+
return obj;
|
|
117
115
|
}
|
|
118
116
|
|
|
119
|
-
async find(query = {}, options = {}, user) {
|
|
117
|
+
async find (query = {}, options = {}, user) {
|
|
120
118
|
try {
|
|
121
|
-
const auth = this.checkAuthorisation("find", user, query)
|
|
119
|
+
const auth = this.checkAuthorisation("find", user, query);
|
|
122
120
|
switch (this.ormName) {
|
|
123
121
|
case "mongoose":
|
|
124
122
|
if (options.limit || options.offset || options.page) {
|
|
125
123
|
return this.entity.paginate(auth.query, {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
page: options.page,
|
|
125
|
+
limit: options.limit,
|
|
126
|
+
offset: options.offset
|
|
127
|
+
})
|
|
130
128
|
.then((res) => {
|
|
131
|
-
|
|
129
|
+
const tab = [];
|
|
132
130
|
if (!res) {
|
|
133
131
|
return {
|
|
134
132
|
page: options.page,
|
|
@@ -136,7 +134,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
136
134
|
offset: options.offset,
|
|
137
135
|
total: tab.length,
|
|
138
136
|
rows: tab
|
|
139
|
-
}
|
|
137
|
+
};
|
|
140
138
|
}
|
|
141
139
|
return {
|
|
142
140
|
page: res.page,
|
|
@@ -150,15 +148,15 @@ module.exports = class users extends nodefony.Service {
|
|
|
150
148
|
prevPage: res.prevPage,
|
|
151
149
|
nextPage: res.nextPage,
|
|
152
150
|
rows: res.docs
|
|
153
|
-
}
|
|
151
|
+
};
|
|
154
152
|
})
|
|
155
|
-
.catch(async e => {
|
|
153
|
+
.catch(async (e) => {
|
|
156
154
|
throw await this.sanitizeError(e);
|
|
157
155
|
});
|
|
158
156
|
}
|
|
159
157
|
return this.entity.find(auth.query, options)
|
|
160
158
|
.then((res) => {
|
|
161
|
-
|
|
159
|
+
const tab = [];
|
|
162
160
|
if (!res) {
|
|
163
161
|
return {
|
|
164
162
|
total: tab.length,
|
|
@@ -170,15 +168,15 @@ module.exports = class users extends nodefony.Service {
|
|
|
170
168
|
rows: res
|
|
171
169
|
};
|
|
172
170
|
})
|
|
173
|
-
.catch(async e => {
|
|
171
|
+
.catch(async (e) => {
|
|
174
172
|
throw await this.sanitizeError(e);
|
|
175
173
|
});
|
|
176
174
|
case "sequelize":
|
|
177
|
-
//query = nodefony.extend(query, options);
|
|
175
|
+
// query = nodefony.extend(query, options);
|
|
178
176
|
if (query.limit || query.offset) {
|
|
179
177
|
return this.entity.findAndCountAll(auth.query)
|
|
180
178
|
.then((res) => {
|
|
181
|
-
|
|
179
|
+
const tab = [];
|
|
182
180
|
if (!res) {
|
|
183
181
|
return {
|
|
184
182
|
page: query.page,
|
|
@@ -189,7 +187,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
189
187
|
};
|
|
190
188
|
}
|
|
191
189
|
res.rows.map((el) => {
|
|
192
|
-
|
|
190
|
+
const userS = el.get({
|
|
193
191
|
plain: true
|
|
194
192
|
});
|
|
195
193
|
tab.push(userS);
|
|
@@ -202,13 +200,13 @@ module.exports = class users extends nodefony.Service {
|
|
|
202
200
|
rows: tab
|
|
203
201
|
};
|
|
204
202
|
})
|
|
205
|
-
.catch(async e => {
|
|
203
|
+
.catch(async (e) => {
|
|
206
204
|
throw await this.sanitizeError(e);
|
|
207
205
|
});
|
|
208
206
|
}
|
|
209
207
|
return this.entity.findAll(auth.query)
|
|
210
208
|
.then((res) => {
|
|
211
|
-
|
|
209
|
+
const tab = [];
|
|
212
210
|
if (!res) {
|
|
213
211
|
return {
|
|
214
212
|
total: tab.length,
|
|
@@ -216,7 +214,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
216
214
|
};
|
|
217
215
|
}
|
|
218
216
|
res.map((el) => {
|
|
219
|
-
|
|
217
|
+
const userS = el.get({
|
|
220
218
|
plain: true
|
|
221
219
|
});
|
|
222
220
|
tab.push(userS);
|
|
@@ -226,7 +224,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
226
224
|
rows: tab
|
|
227
225
|
};
|
|
228
226
|
})
|
|
229
|
-
.catch(async e => {
|
|
227
|
+
.catch(async (e) => {
|
|
230
228
|
throw await this.sanitizeError(e);
|
|
231
229
|
});
|
|
232
230
|
}
|
|
@@ -235,29 +233,29 @@ module.exports = class users extends nodefony.Service {
|
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
235
|
|
|
238
|
-
async findOne(username, user) {
|
|
236
|
+
async findOne (username, user) {
|
|
239
237
|
try {
|
|
240
238
|
switch (this.ormName) {
|
|
241
239
|
case "mongoose":
|
|
242
240
|
return this.entity.findOne({
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
.catch(async e => {
|
|
241
|
+
username
|
|
242
|
+
})
|
|
243
|
+
.catch(async (e) => {
|
|
246
244
|
throw await this.sanitizeError(e);
|
|
247
245
|
});
|
|
248
246
|
case "sequelize":
|
|
249
247
|
return this.entity.findOne({
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
248
|
+
where: {
|
|
249
|
+
username
|
|
250
|
+
}
|
|
251
|
+
})
|
|
254
252
|
.then((user) => {
|
|
255
253
|
if (!user) {
|
|
256
254
|
throw new nodefony.Error(`Username ${username} not found`, 404);
|
|
257
255
|
}
|
|
258
256
|
return user;
|
|
259
257
|
})
|
|
260
|
-
.catch(async e => {
|
|
258
|
+
.catch(async (e) => {
|
|
261
259
|
throw await this.sanitizeError(e);
|
|
262
260
|
});
|
|
263
261
|
}
|
|
@@ -266,8 +264,8 @@ module.exports = class users extends nodefony.Service {
|
|
|
266
264
|
}
|
|
267
265
|
}
|
|
268
266
|
|
|
269
|
-
async update(userentity, value, user, transac = null) {
|
|
270
|
-
let transaction = transac
|
|
267
|
+
async update (userentity, value, user, transac = null) {
|
|
268
|
+
let transaction = transac;
|
|
271
269
|
if (!transac) {
|
|
272
270
|
transaction = await this.orm.startTransaction("user");
|
|
273
271
|
}
|
|
@@ -276,35 +274,32 @@ module.exports = class users extends nodefony.Service {
|
|
|
276
274
|
try {
|
|
277
275
|
return userentity.updateOne(value, {
|
|
278
276
|
// session: transaction
|
|
279
|
-
|
|
280
|
-
.then(async (user) =>
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
.catch(async e => {
|
|
277
|
+
})
|
|
278
|
+
.then(async (user) =>
|
|
279
|
+
// await transaction.commitTransaction();
|
|
280
|
+
user)
|
|
281
|
+
.catch(async (e) => {
|
|
285
282
|
throw await this.sanitizeError(e, transaction);
|
|
286
283
|
});
|
|
287
284
|
} catch (e) {
|
|
288
285
|
throw await this.sanitizeError(e, transaction);
|
|
289
|
-
} finally {}
|
|
290
|
-
break;
|
|
286
|
+
} finally { }
|
|
291
287
|
case "sequelize":
|
|
292
288
|
try {
|
|
293
289
|
const {
|
|
294
290
|
username
|
|
295
291
|
} = userentity;
|
|
296
292
|
return this.entity.update(value, {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
})
|
|
293
|
+
where: {
|
|
294
|
+
username
|
|
295
|
+
},
|
|
296
|
+
transaction
|
|
297
|
+
})
|
|
303
298
|
.then(async (user) => {
|
|
304
299
|
await transaction.commit();
|
|
305
300
|
return user;
|
|
306
301
|
})
|
|
307
|
-
.catch(async e => {
|
|
302
|
+
.catch(async (e) => {
|
|
308
303
|
throw await this.sanitizeError(e, transaction);
|
|
309
304
|
});
|
|
310
305
|
} catch (e) {
|
|
@@ -313,8 +308,8 @@ module.exports = class users extends nodefony.Service {
|
|
|
313
308
|
}
|
|
314
309
|
}
|
|
315
310
|
|
|
316
|
-
async create(query, user, transac = null) {
|
|
317
|
-
let transaction = transac
|
|
311
|
+
async create (query, user, transac = null) {
|
|
312
|
+
let transaction = transac;
|
|
318
313
|
if (!transac) {
|
|
319
314
|
transaction = await this.orm.startTransaction("user");
|
|
320
315
|
}
|
|
@@ -322,29 +317,27 @@ module.exports = class users extends nodefony.Service {
|
|
|
322
317
|
case "sequelize":
|
|
323
318
|
try {
|
|
324
319
|
return this.entity.create(query, {
|
|
325
|
-
|
|
326
|
-
|
|
320
|
+
transaction
|
|
321
|
+
})
|
|
327
322
|
.then(async (user) => {
|
|
328
323
|
await transaction.commit();
|
|
329
324
|
return user;
|
|
330
325
|
})
|
|
331
|
-
.catch(async e => {
|
|
326
|
+
.catch(async (e) => {
|
|
332
327
|
throw await this.sanitizeError(e, transaction);
|
|
333
328
|
});
|
|
334
329
|
} catch (e) {
|
|
335
330
|
throw await this.sanitizeError(e, transaction);
|
|
336
331
|
}
|
|
337
|
-
break;
|
|
338
332
|
case "mongoose":
|
|
339
333
|
try {
|
|
340
334
|
return this.entity.create([query], {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
.then(async (myuser) =>
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
.catch(async e => {
|
|
335
|
+
// session: transaction
|
|
336
|
+
})
|
|
337
|
+
.then(async (myuser) =>
|
|
338
|
+
// await transaction.commitTransaction();
|
|
339
|
+
myuser[0] || myuser)
|
|
340
|
+
.catch(async (e) => {
|
|
348
341
|
throw await this.sanitizeError(e, transaction);
|
|
349
342
|
});
|
|
350
343
|
} catch (e) {
|
|
@@ -353,8 +346,8 @@ module.exports = class users extends nodefony.Service {
|
|
|
353
346
|
}
|
|
354
347
|
}
|
|
355
348
|
|
|
356
|
-
async delete(username, user, transac = null) {
|
|
357
|
-
let transaction = transac
|
|
349
|
+
async delete (username, user, transac = null) {
|
|
350
|
+
let transaction = transac;
|
|
358
351
|
if (!transac) {
|
|
359
352
|
transaction = await this.orm.startTransaction("user");
|
|
360
353
|
}
|
|
@@ -362,54 +355,52 @@ module.exports = class users extends nodefony.Service {
|
|
|
362
355
|
case "mongoose":
|
|
363
356
|
try {
|
|
364
357
|
return this.entity.findOne({
|
|
365
|
-
|
|
366
|
-
|
|
358
|
+
username
|
|
359
|
+
})
|
|
367
360
|
.then((user) => {
|
|
368
361
|
if (!user) {
|
|
369
362
|
throw new nodefony.Error(`User ${username} not found`);
|
|
370
363
|
}
|
|
371
|
-
return user.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
.then(async (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
.catch(async e => {
|
|
364
|
+
return user.deleteOne({
|
|
365
|
+
force: true
|
|
366
|
+
// session: transaction
|
|
367
|
+
})
|
|
368
|
+
.then(async (state) =>
|
|
369
|
+
// await transaction.commitTransaction();
|
|
370
|
+
({username}))
|
|
371
|
+
.catch(async (e) => {
|
|
380
372
|
throw await this.sanitizeError(e, transaction);
|
|
381
373
|
});
|
|
382
374
|
})
|
|
383
|
-
.catch(async e => {
|
|
375
|
+
.catch(async (e) => {
|
|
384
376
|
throw await this.sanitizeError(e, transaction);
|
|
385
377
|
});
|
|
386
378
|
} catch (e) {
|
|
387
379
|
throw await this.sanitizeError(e, transaction);
|
|
388
380
|
}
|
|
389
|
-
break;
|
|
390
381
|
case "sequelize":
|
|
391
382
|
try {
|
|
392
383
|
return this.entity.findOne({
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
384
|
+
where: {
|
|
385
|
+
username
|
|
386
|
+
}
|
|
387
|
+
})
|
|
397
388
|
.then((user) => {
|
|
398
389
|
if (!user) {
|
|
399
390
|
throw new nodefony.Error(`User ${username} not found`);
|
|
400
391
|
}
|
|
401
392
|
return user.destroy({
|
|
402
|
-
|
|
403
|
-
|
|
393
|
+
transaction
|
|
394
|
+
})
|
|
404
395
|
.then(async (user) => {
|
|
405
396
|
await transaction.commit();
|
|
406
397
|
return user;
|
|
407
398
|
})
|
|
408
|
-
.catch(async e => {
|
|
399
|
+
.catch(async (e) => {
|
|
409
400
|
throw await this.sanitizeError(e, transaction);
|
|
410
401
|
});
|
|
411
402
|
})
|
|
412
|
-
.catch(async e => {
|
|
403
|
+
.catch(async (e) => {
|
|
413
404
|
throw await this.sanitizeError(e, transaction);
|
|
414
405
|
});
|
|
415
406
|
} catch (e) {
|
|
@@ -417,4 +408,4 @@ module.exports = class users extends nodefony.Service {
|
|
|
417
408
|
}
|
|
418
409
|
}
|
|
419
410
|
}
|
|
420
|
-
}
|
|
411
|
+
};
|
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
module.exports = nodefony.registerProvider("userProvider", () => {
|
|
2
|
-
|
|
3
2
|
const Provider = class userProvider extends nodefony.userEntityProvider {
|
|
4
|
-
|
|
5
|
-
constructor(name, manager, config) {
|
|
3
|
+
constructor (name, manager, config) {
|
|
6
4
|
super(name, manager, config);
|
|
7
5
|
this.property = {};
|
|
8
6
|
}
|
|
9
7
|
|
|
10
|
-
loadUserByUsername(username) {
|
|
8
|
+
loadUserByUsername (username) {
|
|
11
9
|
this.property[this.userProperty] = username;
|
|
12
10
|
if (!this.userEntity) {
|
|
13
11
|
this.userEntity = this.getEntity();
|
|
14
12
|
}
|
|
15
13
|
return this.userEntity.findOne(this.property)
|
|
16
14
|
.then((user) => {
|
|
17
|
-
//throw user;
|
|
15
|
+
// throw user;
|
|
18
16
|
if (user) {
|
|
19
17
|
return this.refreshUser(user);
|
|
20
18
|
}
|
|
21
19
|
throw new nodefony.Error(`User : ${username} not Found`, 404);
|
|
22
|
-
})
|
|
20
|
+
})
|
|
21
|
+
.catch((error) => {
|
|
23
22
|
throw error;
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
async refreshUser(user) {
|
|
26
|
+
async refreshUser (user) {
|
|
28
27
|
const serialize = await user.populate();
|
|
29
28
|
return new nodefony.User(
|
|
30
29
|
serialize.username,
|
|
@@ -43,7 +42,6 @@ module.exports = nodefony.registerProvider("userProvider", () => {
|
|
|
43
42
|
serialize.image
|
|
44
43
|
);
|
|
45
44
|
}
|
|
46
|
-
|
|
47
45
|
};
|
|
48
46
|
return Provider;
|
|
49
47
|
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
module.exports = nodefony.registerProvider("userProvider", () => {
|
|
2
|
-
|
|
3
2
|
const Provider = class userProvider extends nodefony.userEntityProvider {
|
|
4
|
-
|
|
5
|
-
constructor(name, manager, config) {
|
|
3
|
+
constructor (name, manager, config) {
|
|
6
4
|
super(name, manager, config);
|
|
7
5
|
this.property = {};
|
|
8
6
|
}
|
|
9
7
|
|
|
10
|
-
loadUserByUsername(username) {
|
|
8
|
+
loadUserByUsername (username) {
|
|
11
9
|
this.property[this.userProperty] = username;
|
|
12
10
|
if (!this.userEntity) {
|
|
13
11
|
this.userEntity = this.getEntity();
|
|
@@ -19,13 +17,14 @@ module.exports = nodefony.registerProvider("userProvider", () => {
|
|
|
19
17
|
return this.refreshUser(user);
|
|
20
18
|
}
|
|
21
19
|
throw new nodefony.Error(`User : ${username} not Found`, 404);
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
})
|
|
21
|
+
.catch((error) => {
|
|
22
|
+
throw error;
|
|
23
|
+
});
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
refreshUser(user) {
|
|
28
|
-
|
|
26
|
+
refreshUser (user) {
|
|
27
|
+
const serialize = user.get();
|
|
29
28
|
return new nodefony.User(
|
|
30
29
|
serialize.username,
|
|
31
30
|
serialize.password,
|
|
@@ -46,4 +45,4 @@ module.exports = nodefony.registerProvider("userProvider", () => {
|
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
return Provider;
|
|
49
|
-
});
|
|
48
|
+
});
|