@modular-rest/server 1.6.3 → 1.6.4
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/package.json +1 -1
- package/src/helper/data_insertion.js +58 -35
package/package.json
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
const DataProvider = require(
|
|
1
|
+
const DataProvider = require("../services/data_provider/service");
|
|
2
2
|
|
|
3
3
|
function createPermissions() {
|
|
4
|
-
let model = DataProvider.getCollection(
|
|
5
|
-
|
|
6
|
-
return new Promise(async (done, reject) => {
|
|
4
|
+
let model = DataProvider.getCollection("cms", "permission");
|
|
7
5
|
|
|
6
|
+
return new Promise(async (done, reject) => {
|
|
8
7
|
// create customer permission
|
|
9
|
-
let isAnonymousExisted = await model
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
let isAnonymousExisted = await model
|
|
9
|
+
.countDocuments({ title: "anonymous" })
|
|
10
|
+
.exec()
|
|
11
|
+
.catch(reject);
|
|
12
|
+
let isCoustomerExisted = await model
|
|
13
|
+
.countDocuments({ title: "customer" })
|
|
14
|
+
.exec()
|
|
15
|
+
.catch(reject);
|
|
16
|
+
let isAdministratorExisted = await model
|
|
17
|
+
.countDocuments({ title: "administrator" })
|
|
18
|
+
.exec()
|
|
19
|
+
.catch(reject);
|
|
12
20
|
|
|
13
21
|
if (!isAnonymousExisted) {
|
|
14
22
|
await new model({
|
|
15
23
|
anonymous_access: true,
|
|
16
24
|
isAnonymous: true,
|
|
17
|
-
title:
|
|
18
|
-
})
|
|
25
|
+
title: "anonymous",
|
|
26
|
+
})
|
|
27
|
+
.save()
|
|
28
|
+
.catch(reject);
|
|
19
29
|
}
|
|
20
30
|
|
|
21
31
|
if (!isCoustomerExisted) {
|
|
@@ -25,8 +35,10 @@ function createPermissions() {
|
|
|
25
35
|
upload_file_access: true,
|
|
26
36
|
remove_file_access: true,
|
|
27
37
|
isDefault: true,
|
|
28
|
-
title:
|
|
29
|
-
})
|
|
38
|
+
title: "customer",
|
|
39
|
+
})
|
|
40
|
+
.save()
|
|
41
|
+
.catch(reject);
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
if (!isAdministratorExisted) {
|
|
@@ -36,50 +48,61 @@ function createPermissions() {
|
|
|
36
48
|
anonymous_access: true,
|
|
37
49
|
upload_file_access: true,
|
|
38
50
|
remove_file_access: true,
|
|
39
|
-
title:
|
|
40
|
-
})
|
|
51
|
+
title: "administrator",
|
|
52
|
+
})
|
|
53
|
+
.save()
|
|
54
|
+
.catch(reject);
|
|
41
55
|
}
|
|
42
56
|
|
|
43
57
|
done();
|
|
44
58
|
});
|
|
45
|
-
|
|
46
59
|
}
|
|
47
60
|
|
|
48
|
-
function createAdminUser({ email, password }) {
|
|
49
|
-
let permissionModel = DataProvider.getCollection(
|
|
50
|
-
let authModel = DataProvider.getCollection(
|
|
61
|
+
async function createAdminUser({ email, password }) {
|
|
62
|
+
let permissionModel = DataProvider.getCollection("cms", "permission");
|
|
63
|
+
let authModel = DataProvider.getCollection("cms", "auth");
|
|
51
64
|
|
|
52
|
-
|
|
53
|
-
let isAnonymousExisted = await authModel
|
|
54
|
-
|
|
65
|
+
try {
|
|
66
|
+
let isAnonymousExisted = await authModel
|
|
67
|
+
.countDocuments({ type: "anonymous" })
|
|
68
|
+
.exec();
|
|
55
69
|
|
|
56
|
-
let
|
|
57
|
-
|
|
70
|
+
let isAdministratorExisted = await authModel
|
|
71
|
+
.countDocuments({ type: "user", email: email })
|
|
72
|
+
.exec();
|
|
58
73
|
|
|
59
|
-
|
|
74
|
+
let anonymousPermission = await permissionModel
|
|
75
|
+
.findOne({ title: "anonymous" })
|
|
76
|
+
.exec();
|
|
77
|
+
|
|
78
|
+
let administratorPermission = await permissionModel
|
|
79
|
+
.findOne({ title: "administrator" })
|
|
80
|
+
.exec();
|
|
81
|
+
|
|
82
|
+
if (isAnonymousExisted == 0) {
|
|
60
83
|
await new authModel({
|
|
61
84
|
permission: anonymousPermission._id,
|
|
62
|
-
email:
|
|
63
|
-
phone:
|
|
64
|
-
password:
|
|
65
|
-
type:
|
|
66
|
-
}).save()
|
|
85
|
+
email: "",
|
|
86
|
+
phone: "",
|
|
87
|
+
password: "",
|
|
88
|
+
type: "anonymous",
|
|
89
|
+
}).save();
|
|
67
90
|
}
|
|
68
91
|
|
|
69
|
-
if (
|
|
92
|
+
if (isAdministratorExisted == 0) {
|
|
70
93
|
await new authModel({
|
|
71
94
|
permission: administratorPermission._id,
|
|
72
95
|
email: email,
|
|
73
96
|
password: password,
|
|
74
|
-
type:
|
|
75
|
-
}).save()
|
|
97
|
+
type: "user",
|
|
98
|
+
}).save();
|
|
76
99
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return Promise.reject(e);
|
|
102
|
+
}
|
|
80
103
|
}
|
|
81
104
|
|
|
82
105
|
module.exports = {
|
|
83
106
|
createPermissions,
|
|
84
107
|
createAdminUser,
|
|
85
|
-
};
|
|
108
|
+
};
|