@dynamatix/gb-schemas 0.21.2 → 0.21.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
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
+
import mongooseEncryption from "../utils/encryption.middleware";
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
+
const permissionSchema = new mongoose.Schema({
|
|
4
5
|
name: { type: String, required: true },
|
|
5
6
|
controllerName: { type: String, required: true },
|
|
6
7
|
methodName: { type: String, required: true }
|
|
@@ -8,6 +9,7 @@ const PermissionSchema = new mongoose.Schema({
|
|
|
8
9
|
timestamps: true
|
|
9
10
|
});
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
permissionSchema.plugin(mongooseEncryption);
|
|
13
|
+
const PermissionModel = mongoose.model('Permission', permissionSchema);
|
|
12
14
|
|
|
13
15
|
export default PermissionModel;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
+
import mongooseEncryption from "../utils/encryption.middleware";
|
|
2
3
|
|
|
3
4
|
const RoleGroupSchema = new mongoose.Schema({
|
|
4
5
|
groupId: { type: Number, required: true },
|
|
@@ -12,5 +13,6 @@ const RoleGroupSchema = new mongoose.Schema({
|
|
|
12
13
|
timestamps: true
|
|
13
14
|
});
|
|
14
15
|
|
|
16
|
+
RoleGroupSchema.plugin(mongooseEncryption);
|
|
15
17
|
const RoleGroupModel = mongoose.model('RoleGroup', RoleGroupSchema);
|
|
16
18
|
export default RoleGroupModel;
|
package/users/role.model.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
+
import mongooseEncryption from "../utils/encryption.middleware";
|
|
2
3
|
|
|
3
4
|
const RoleSchema = new mongoose.Schema({
|
|
4
5
|
roleId: { type: Number, required: true },
|
|
@@ -11,7 +12,7 @@ const RoleSchema = new mongoose.Schema({
|
|
|
11
12
|
timestamps: true
|
|
12
13
|
});
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
RoleSchema.plugin(mongooseEncryption);
|
|
15
16
|
const RoleModel = mongoose.model('Role', RoleSchema);
|
|
16
17
|
|
|
17
18
|
export default RoleModel;
|
|
@@ -23,6 +23,30 @@ export default function mongooseEncryption(schema, options) {
|
|
|
23
23
|
next();
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
// Encrypt before bulkWrite operations
|
|
27
|
+
schema.pre("bulkWrite", function (operations, next) {
|
|
28
|
+
operations.forEach(operation => {
|
|
29
|
+
if (operation.insertOne && operation.insertOne.document) {
|
|
30
|
+
operation.insertOne.document = encryptObject(operation.insertOne.document, collectionName);
|
|
31
|
+
} else if (operation.updateOne && operation.updateOne.update) {
|
|
32
|
+
operation.updateOne.update = encryptObject(operation.updateOne.update, collectionName);
|
|
33
|
+
} else if (operation.updateMany && operation.updateMany.update) {
|
|
34
|
+
operation.updateMany.update = encryptObject(operation.updateMany.update, collectionName);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
next();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Decrypt after bulkWrite operations
|
|
41
|
+
schema.post("bulkWrite", function (result) {
|
|
42
|
+
result.result.insertedDocs.forEach(doc => {
|
|
43
|
+
doc.set(decryptObject(doc.toObject(), collectionName)); // Decrypt document fields
|
|
44
|
+
});
|
|
45
|
+
result.result.modifiedDocs.forEach(doc => {
|
|
46
|
+
doc.set(decryptObject(doc.toObject(), collectionName)); // Decrypt document fields
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
26
50
|
// Encrypt before creating a document
|
|
27
51
|
schema.pre("create", function (next) {
|
|
28
52
|
// Encrypt only the fields before saving to the database
|