aloux-iam 0.0.105 → 0.0.107
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/lib/controllers/history.js +7 -4
- package/lib/middleware.js +10 -3
- package/lib/models/History.js +2 -1
- package/package.json +1 -1
|
@@ -16,15 +16,18 @@ self.create = async (data) => {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
self.response = async (_history, response, _createdBy) => {
|
|
19
|
+
self.response = async (_history, response, _createdBy, permission) => {
|
|
20
20
|
try {
|
|
21
21
|
if (_createdBy) {
|
|
22
22
|
await History.updateOne(
|
|
23
23
|
{ _id: _history },
|
|
24
|
-
{ response: response, _createdBy: _createdBy }
|
|
24
|
+
{ response: response, _createdBy: _createdBy, permission: permission }
|
|
25
25
|
);
|
|
26
26
|
} else {
|
|
27
|
-
await History.updateOne(
|
|
27
|
+
await History.updateOne(
|
|
28
|
+
{ _id: _history },
|
|
29
|
+
{ response: response, permission: permission }
|
|
30
|
+
);
|
|
28
31
|
}
|
|
29
32
|
return true;
|
|
30
33
|
} catch (error) {
|
|
@@ -34,7 +37,7 @@ self.response = async (_history, response, _createdBy) => {
|
|
|
34
37
|
|
|
35
38
|
self.retrieve = async (req, res) => {
|
|
36
39
|
try {
|
|
37
|
-
|
|
40
|
+
let query = {};
|
|
38
41
|
const response = { items: [], count: 0 };
|
|
39
42
|
|
|
40
43
|
if (req.body?.filter?.method) {
|
package/lib/middleware.js
CHANGED
|
@@ -24,8 +24,15 @@ const auth = async (req, res, next) => {
|
|
|
24
24
|
try {
|
|
25
25
|
let newHistory;
|
|
26
26
|
if (process.env.HISTORY === "true") {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const endpoints = process.env.HISTORY_ENDPOINTS.split(",");
|
|
28
|
+
const urlToCheck = req.route.path;
|
|
29
|
+
const exists = endpoints.some((endpoint) =>
|
|
30
|
+
new RegExp(`^${endpoint}(/|\\?|$)`).test(urlToCheck)
|
|
31
|
+
);
|
|
32
|
+
if (exists) {
|
|
33
|
+
req.history = newHistory._id.toString();
|
|
34
|
+
newHistory = await historyController.create(req);
|
|
35
|
+
}
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
let token =
|
|
@@ -123,7 +130,7 @@ const auth = async (req, res, next) => {
|
|
|
123
130
|
|
|
124
131
|
req.user = user;
|
|
125
132
|
req.token = token;
|
|
126
|
-
req.
|
|
133
|
+
req.permission = resource ? resource.description : "Recurso indefinido";
|
|
127
134
|
next();
|
|
128
135
|
} catch (error) {
|
|
129
136
|
let obj = error;
|
package/lib/models/History.js
CHANGED
|
@@ -3,7 +3,8 @@ const ObjectId = mongoose.Schema.Types.ObjectId;
|
|
|
3
3
|
|
|
4
4
|
const historySchema = mongoose.Schema({
|
|
5
5
|
method: { type: String, default: false },
|
|
6
|
-
path: { type: String
|
|
6
|
+
path: { type: String },
|
|
7
|
+
permission: { type: String },
|
|
7
8
|
payload: { type: Object, default: {} }, // Guarda cualquier estructura JSON
|
|
8
9
|
response: { type: Object, default: {} }, // Guarda cualquier estructura JSON
|
|
9
10
|
_createdBy: { type: ObjectId, required: false, ref: "User" },
|