nodefony 7.0.0-beta.2 → 7.0.0-beta.21
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 +534 -8028
- package/README.md +33 -30
- 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 +25 -30
- 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 +4 -3
- 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 -75
- package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
- 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 +13 -15
- 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 -36
- 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 +27 -25
- package/cli/builder/bundles/users-bundle/pnpm-lock.yaml +4262 -0
- package/cli/builder/bundles/users-bundle/readme.md +7 -7
- package/cli/builder/bundles/users-bundle/services/usersService.js +97 -102
- 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 +119 -70
- 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 +33 -30
- 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 +70 -0
- package/cli/builder/react/reactBuilder.js +59 -65
- package/cli/builder/sandbox/sandBoxBuilder.js +132 -134
- package/cli/builder/skeletons/app/appKernel.js +120 -2
- package/cli/builder/skeletons/config/config.js +1 -1
- package/cli/builder/skeletons/config/nodefony/framework-bundle.js +2 -1
- package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
- package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +38 -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 +280 -228
- 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 +252 -220
- 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 +476 -384
- package/kernel/kernelWatcher.es6 +64 -54
- package/kernel/orm/entity.es6 +10 -12
- package/kernel/orm/orm.es6 +68 -48
- 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 -149
- 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 +40 -40
- 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 -52
- package/cli/builder/skeletons/package.json +0 -61
|
@@ -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,5 @@
|
|
|
1
1
|
module.exports = class users extends nodefony.Service {
|
|
2
|
-
|
|
3
|
-
constructor(container) {
|
|
2
|
+
constructor (container) {
|
|
4
3
|
super("users", container);
|
|
5
4
|
this.orm = this.kernel.getORM();
|
|
6
5
|
this.ormName = this.orm.name;
|
|
@@ -13,11 +12,11 @@ module.exports = class users extends nodefony.Service {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
initialize() {
|
|
15
|
+
initialize () {
|
|
17
16
|
this.entity = this.orm.getEntity("user");
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
getSchemaAttributes() {
|
|
19
|
+
getSchemaAttributes () {
|
|
21
20
|
switch (this.ormName) {
|
|
22
21
|
case "sequelize":
|
|
23
22
|
return this.entity.rawAttributes;
|
|
@@ -26,11 +25,11 @@ module.exports = class users extends nodefony.Service {
|
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
checkSchema(query) {
|
|
28
|
+
checkSchema (query) {
|
|
30
29
|
try {
|
|
31
30
|
if (query) {
|
|
32
31
|
const attr = this.getSchemaAttributes();
|
|
33
|
-
for (
|
|
32
|
+
for (const ele in query) {
|
|
34
33
|
if (ele in attr) {
|
|
35
34
|
continue;
|
|
36
35
|
}
|
|
@@ -42,7 +41,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
async sanitizeError(error, transaction = null) {
|
|
44
|
+
async sanitizeError (error, transaction = null) {
|
|
46
45
|
this.log(error, "ERROR");
|
|
47
46
|
if (transaction && !transaction.finished) {
|
|
48
47
|
switch (this.ormName) {
|
|
@@ -62,31 +61,31 @@ module.exports = class users extends nodefony.Service {
|
|
|
62
61
|
return error;
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
checkAuthorisation(action, user = null, query = null) {
|
|
64
|
+
checkAuthorisation (action, user = null, query = null) {
|
|
66
65
|
if (!user) {
|
|
67
|
-
throw new nodefony.authorizationError(
|
|
66
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
68
67
|
}
|
|
69
|
-
|
|
68
|
+
const obj = {
|
|
70
69
|
isAdmin: user.hasRole("ROLE_ADMIN"),
|
|
71
70
|
isUser: user.hasRole("ROLE_USER"),
|
|
72
|
-
query
|
|
73
|
-
}
|
|
71
|
+
query
|
|
72
|
+
};
|
|
74
73
|
switch (action) {
|
|
75
74
|
case "update":
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
if (!obj.isAdmin) {
|
|
76
|
+
if (query.where) {
|
|
77
|
+
if (user.username !== query.where.username) {
|
|
78
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
80
82
|
}
|
|
81
|
-
}else{
|
|
82
|
-
throw new nodefony.authorizationError('User not authorized', 403)
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
break;
|
|
84
|
+
break;
|
|
86
85
|
case "insert":
|
|
87
86
|
case "delete":
|
|
88
87
|
if (!obj.isAdmin) {
|
|
89
|
-
throw new nodefony.authorizationError(
|
|
88
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
90
89
|
}
|
|
91
90
|
break;
|
|
92
91
|
case "search":
|
|
@@ -95,7 +94,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
95
94
|
if (obj.isUser) {
|
|
96
95
|
|
|
97
96
|
} else {
|
|
98
|
-
throw new nodefony.authorizationError(
|
|
97
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
99
98
|
}
|
|
100
99
|
} else {
|
|
101
100
|
|
|
@@ -106,29 +105,29 @@ module.exports = class users extends nodefony.Service {
|
|
|
106
105
|
case "findOne":
|
|
107
106
|
if (!obj.isAdmin) {
|
|
108
107
|
if (!obj.isUser) {
|
|
109
|
-
throw new nodefony.authorizationError(
|
|
108
|
+
throw new nodefony.authorizationError("User not authorized", 403);
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
break;
|
|
113
112
|
default:
|
|
114
|
-
throw new nodefony.authorizationError(
|
|
113
|
+
throw new nodefony.authorizationError("Action not authorized", 403);
|
|
115
114
|
}
|
|
116
|
-
return obj
|
|
115
|
+
return obj;
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
async find(query = {}, options = {}, user) {
|
|
118
|
+
async find (query = {}, options = {}, user) {
|
|
120
119
|
try {
|
|
121
|
-
const auth = this.checkAuthorisation("find", user, query)
|
|
120
|
+
const auth = this.checkAuthorisation("find", user, query);
|
|
122
121
|
switch (this.ormName) {
|
|
123
122
|
case "mongoose":
|
|
124
123
|
if (options.limit || options.offset || options.page) {
|
|
125
124
|
return this.entity.paginate(auth.query, {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
page: options.page,
|
|
126
|
+
limit: options.limit,
|
|
127
|
+
offset: options.offset
|
|
128
|
+
})
|
|
130
129
|
.then((res) => {
|
|
131
|
-
|
|
130
|
+
const tab = [];
|
|
132
131
|
if (!res) {
|
|
133
132
|
return {
|
|
134
133
|
page: options.page,
|
|
@@ -136,7 +135,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
136
135
|
offset: options.offset,
|
|
137
136
|
total: tab.length,
|
|
138
137
|
rows: tab
|
|
139
|
-
}
|
|
138
|
+
};
|
|
140
139
|
}
|
|
141
140
|
return {
|
|
142
141
|
page: res.page,
|
|
@@ -150,15 +149,15 @@ module.exports = class users extends nodefony.Service {
|
|
|
150
149
|
prevPage: res.prevPage,
|
|
151
150
|
nextPage: res.nextPage,
|
|
152
151
|
rows: res.docs
|
|
153
|
-
}
|
|
152
|
+
};
|
|
154
153
|
})
|
|
155
|
-
.catch(async e => {
|
|
154
|
+
.catch(async (e) => {
|
|
156
155
|
throw await this.sanitizeError(e);
|
|
157
156
|
});
|
|
158
157
|
}
|
|
159
158
|
return this.entity.find(auth.query, options)
|
|
160
159
|
.then((res) => {
|
|
161
|
-
|
|
160
|
+
const tab = [];
|
|
162
161
|
if (!res) {
|
|
163
162
|
return {
|
|
164
163
|
total: tab.length,
|
|
@@ -170,15 +169,15 @@ module.exports = class users extends nodefony.Service {
|
|
|
170
169
|
rows: res
|
|
171
170
|
};
|
|
172
171
|
})
|
|
173
|
-
.catch(async e => {
|
|
172
|
+
.catch(async (e) => {
|
|
174
173
|
throw await this.sanitizeError(e);
|
|
175
174
|
});
|
|
176
175
|
case "sequelize":
|
|
177
|
-
//query = nodefony.extend(query, options);
|
|
176
|
+
// query = nodefony.extend(query, options);
|
|
178
177
|
if (query.limit || query.offset) {
|
|
179
178
|
return this.entity.findAndCountAll(auth.query)
|
|
180
179
|
.then((res) => {
|
|
181
|
-
|
|
180
|
+
const tab = [];
|
|
182
181
|
if (!res) {
|
|
183
182
|
return {
|
|
184
183
|
page: query.page,
|
|
@@ -189,7 +188,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
189
188
|
};
|
|
190
189
|
}
|
|
191
190
|
res.rows.map((el) => {
|
|
192
|
-
|
|
191
|
+
const userS = el.get({
|
|
193
192
|
plain: true
|
|
194
193
|
});
|
|
195
194
|
tab.push(userS);
|
|
@@ -202,13 +201,13 @@ module.exports = class users extends nodefony.Service {
|
|
|
202
201
|
rows: tab
|
|
203
202
|
};
|
|
204
203
|
})
|
|
205
|
-
.catch(async e => {
|
|
204
|
+
.catch(async (e) => {
|
|
206
205
|
throw await this.sanitizeError(e);
|
|
207
206
|
});
|
|
208
207
|
}
|
|
209
208
|
return this.entity.findAll(auth.query)
|
|
210
209
|
.then((res) => {
|
|
211
|
-
|
|
210
|
+
const tab = [];
|
|
212
211
|
if (!res) {
|
|
213
212
|
return {
|
|
214
213
|
total: tab.length,
|
|
@@ -216,7 +215,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
216
215
|
};
|
|
217
216
|
}
|
|
218
217
|
res.map((el) => {
|
|
219
|
-
|
|
218
|
+
const userS = el.get({
|
|
220
219
|
plain: true
|
|
221
220
|
});
|
|
222
221
|
tab.push(userS);
|
|
@@ -226,7 +225,7 @@ module.exports = class users extends nodefony.Service {
|
|
|
226
225
|
rows: tab
|
|
227
226
|
};
|
|
228
227
|
})
|
|
229
|
-
.catch(async e => {
|
|
228
|
+
.catch(async (e) => {
|
|
230
229
|
throw await this.sanitizeError(e);
|
|
231
230
|
});
|
|
232
231
|
}
|
|
@@ -235,29 +234,29 @@ module.exports = class users extends nodefony.Service {
|
|
|
235
234
|
}
|
|
236
235
|
}
|
|
237
236
|
|
|
238
|
-
async findOne(username, user) {
|
|
237
|
+
async findOne (username, user) {
|
|
239
238
|
try {
|
|
240
239
|
switch (this.ormName) {
|
|
241
240
|
case "mongoose":
|
|
242
241
|
return this.entity.findOne({
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
.catch(async e => {
|
|
242
|
+
username
|
|
243
|
+
})
|
|
244
|
+
.catch(async (e) => {
|
|
246
245
|
throw await this.sanitizeError(e);
|
|
247
246
|
});
|
|
248
247
|
case "sequelize":
|
|
249
248
|
return this.entity.findOne({
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
where: {
|
|
250
|
+
username
|
|
251
|
+
}
|
|
252
|
+
})
|
|
254
253
|
.then((user) => {
|
|
255
254
|
if (!user) {
|
|
256
255
|
throw new nodefony.Error(`Username ${username} not found`, 404);
|
|
257
256
|
}
|
|
258
257
|
return user;
|
|
259
258
|
})
|
|
260
|
-
.catch(async e => {
|
|
259
|
+
.catch(async (e) => {
|
|
261
260
|
throw await this.sanitizeError(e);
|
|
262
261
|
});
|
|
263
262
|
}
|
|
@@ -266,8 +265,8 @@ module.exports = class users extends nodefony.Service {
|
|
|
266
265
|
}
|
|
267
266
|
}
|
|
268
267
|
|
|
269
|
-
async update(userentity, value, user, transac = null) {
|
|
270
|
-
let transaction = transac
|
|
268
|
+
async update (userentity, value, user, transac = null) {
|
|
269
|
+
let transaction = transac;
|
|
271
270
|
if (!transac) {
|
|
272
271
|
transaction = await this.orm.startTransaction("user");
|
|
273
272
|
}
|
|
@@ -276,12 +275,11 @@ module.exports = class users extends nodefony.Service {
|
|
|
276
275
|
try {
|
|
277
276
|
return userentity.updateOne(value, {
|
|
278
277
|
// session: transaction
|
|
279
|
-
|
|
280
|
-
.then(async (user) =>
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
.catch(async e => {
|
|
278
|
+
})
|
|
279
|
+
.then(async (user) =>
|
|
280
|
+
// await transaction.commitTransaction();
|
|
281
|
+
user)
|
|
282
|
+
.catch(async (e) => {
|
|
285
283
|
throw await this.sanitizeError(e, transaction);
|
|
286
284
|
});
|
|
287
285
|
} catch (e) {
|
|
@@ -294,17 +292,16 @@ module.exports = class users extends nodefony.Service {
|
|
|
294
292
|
username
|
|
295
293
|
} = userentity;
|
|
296
294
|
return this.entity.update(value, {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
})
|
|
295
|
+
where: {
|
|
296
|
+
username
|
|
297
|
+
},
|
|
298
|
+
transaction
|
|
299
|
+
})
|
|
303
300
|
.then(async (user) => {
|
|
304
301
|
await transaction.commit();
|
|
305
302
|
return user;
|
|
306
303
|
})
|
|
307
|
-
.catch(async e => {
|
|
304
|
+
.catch(async (e) => {
|
|
308
305
|
throw await this.sanitizeError(e, transaction);
|
|
309
306
|
});
|
|
310
307
|
} catch (e) {
|
|
@@ -313,8 +310,8 @@ module.exports = class users extends nodefony.Service {
|
|
|
313
310
|
}
|
|
314
311
|
}
|
|
315
312
|
|
|
316
|
-
async create(query, user, transac = null) {
|
|
317
|
-
let transaction = transac
|
|
313
|
+
async create (query, user, transac = null) {
|
|
314
|
+
let transaction = transac;
|
|
318
315
|
if (!transac) {
|
|
319
316
|
transaction = await this.orm.startTransaction("user");
|
|
320
317
|
}
|
|
@@ -322,13 +319,13 @@ module.exports = class users extends nodefony.Service {
|
|
|
322
319
|
case "sequelize":
|
|
323
320
|
try {
|
|
324
321
|
return this.entity.create(query, {
|
|
325
|
-
|
|
326
|
-
|
|
322
|
+
transaction
|
|
323
|
+
})
|
|
327
324
|
.then(async (user) => {
|
|
328
325
|
await transaction.commit();
|
|
329
326
|
return user;
|
|
330
327
|
})
|
|
331
|
-
.catch(async e => {
|
|
328
|
+
.catch(async (e) => {
|
|
332
329
|
throw await this.sanitizeError(e, transaction);
|
|
333
330
|
});
|
|
334
331
|
} catch (e) {
|
|
@@ -338,13 +335,12 @@ module.exports = class users extends nodefony.Service {
|
|
|
338
335
|
case "mongoose":
|
|
339
336
|
try {
|
|
340
337
|
return this.entity.create([query], {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
.then(async (myuser) =>
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
.catch(async e => {
|
|
338
|
+
// session: transaction
|
|
339
|
+
})
|
|
340
|
+
.then(async (myuser) =>
|
|
341
|
+
// await transaction.commitTransaction();
|
|
342
|
+
myuser[0] || myuser)
|
|
343
|
+
.catch(async (e) => {
|
|
348
344
|
throw await this.sanitizeError(e, transaction);
|
|
349
345
|
});
|
|
350
346
|
} catch (e) {
|
|
@@ -353,8 +349,8 @@ module.exports = class users extends nodefony.Service {
|
|
|
353
349
|
}
|
|
354
350
|
}
|
|
355
351
|
|
|
356
|
-
async delete(username, user, transac = null) {
|
|
357
|
-
let transaction = transac
|
|
352
|
+
async delete (username, user, transac = null) {
|
|
353
|
+
let transaction = transac;
|
|
358
354
|
if (!transac) {
|
|
359
355
|
transaction = await this.orm.startTransaction("user");
|
|
360
356
|
}
|
|
@@ -362,25 +358,24 @@ module.exports = class users extends nodefony.Service {
|
|
|
362
358
|
case "mongoose":
|
|
363
359
|
try {
|
|
364
360
|
return this.entity.findOne({
|
|
365
|
-
|
|
366
|
-
|
|
361
|
+
username
|
|
362
|
+
})
|
|
367
363
|
.then((user) => {
|
|
368
364
|
if (!user) {
|
|
369
365
|
throw new nodefony.Error(`User ${username} not found`);
|
|
370
366
|
}
|
|
371
367
|
return user.remove({
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
.then(async (user) =>
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
.catch(async e => {
|
|
368
|
+
force: true
|
|
369
|
+
// session: transaction
|
|
370
|
+
})
|
|
371
|
+
.then(async (user) =>
|
|
372
|
+
// await transaction.commitTransaction();
|
|
373
|
+
user)
|
|
374
|
+
.catch(async (e) => {
|
|
380
375
|
throw await this.sanitizeError(e, transaction);
|
|
381
376
|
});
|
|
382
377
|
})
|
|
383
|
-
.catch(async e => {
|
|
378
|
+
.catch(async (e) => {
|
|
384
379
|
throw await this.sanitizeError(e, transaction);
|
|
385
380
|
});
|
|
386
381
|
} catch (e) {
|
|
@@ -390,26 +385,26 @@ module.exports = class users extends nodefony.Service {
|
|
|
390
385
|
case "sequelize":
|
|
391
386
|
try {
|
|
392
387
|
return this.entity.findOne({
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
388
|
+
where: {
|
|
389
|
+
username
|
|
390
|
+
}
|
|
391
|
+
})
|
|
397
392
|
.then((user) => {
|
|
398
393
|
if (!user) {
|
|
399
394
|
throw new nodefony.Error(`User ${username} not found`);
|
|
400
395
|
}
|
|
401
396
|
return user.destroy({
|
|
402
|
-
|
|
403
|
-
|
|
397
|
+
transaction
|
|
398
|
+
})
|
|
404
399
|
.then(async (user) => {
|
|
405
400
|
await transaction.commit();
|
|
406
401
|
return user;
|
|
407
402
|
})
|
|
408
|
-
.catch(async e => {
|
|
403
|
+
.catch(async (e) => {
|
|
409
404
|
throw await this.sanitizeError(e, transaction);
|
|
410
405
|
});
|
|
411
406
|
})
|
|
412
|
-
.catch(async e => {
|
|
407
|
+
.catch(async (e) => {
|
|
413
408
|
throw await this.sanitizeError(e, transaction);
|
|
414
409
|
});
|
|
415
410
|
} catch (e) {
|
|
@@ -417,4 +412,4 @@ module.exports = class users extends nodefony.Service {
|
|
|
417
412
|
}
|
|
418
413
|
}
|
|
419
414
|
}
|
|
420
|
-
}
|
|
415
|
+
};
|
|
@@ -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
|
+
});
|