aloux-iam 0.0.102 → 0.0.104
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/index.js +2 -0
- package/lib/controllers/history.js +71 -0
- package/lib/middleware.js +6 -8
- package/lib/models/History.js +14 -0
- package/lib/router.js +10 -7
- package/lib/swagger.yaml +49 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const IAMrouter = require("./lib/router");
|
|
2
2
|
const IAMauth = require("./lib/middleware");
|
|
3
3
|
const awsAloux = require("./lib/controllers/operationsAWS");
|
|
4
|
+
const historyAloux = require("./lib/controllers/history");
|
|
4
5
|
const awsBQ = require("./lib/services/bigQuery");
|
|
5
6
|
const YAML = require("yamljs");
|
|
6
7
|
const path = require("path");
|
|
@@ -33,4 +34,5 @@ module.exports = {
|
|
|
33
34
|
|
|
34
35
|
AlouxAWS: awsAloux,
|
|
35
36
|
AlouxBQ: awsBQ,
|
|
37
|
+
AlouxHistory: historyAloux,
|
|
36
38
|
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const History = require("../models/History");
|
|
2
|
+
const self = module.exports;
|
|
3
|
+
|
|
4
|
+
self.create = async (data) => {
|
|
5
|
+
try {
|
|
6
|
+
const history = new History({
|
|
7
|
+
method: data.originalMethod,
|
|
8
|
+
path: data.route.path,
|
|
9
|
+
payload: data.body,
|
|
10
|
+
createdAt: Date.now(),
|
|
11
|
+
});
|
|
12
|
+
const newHistory = await history.save();
|
|
13
|
+
return newHistory;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
self.response = async (_history, response, _createdBy) => {
|
|
20
|
+
try {
|
|
21
|
+
if (_createdBy) {
|
|
22
|
+
await History.updateOne(
|
|
23
|
+
{ _id: _history },
|
|
24
|
+
{ response: response, _createdBy: _createdBy }
|
|
25
|
+
);
|
|
26
|
+
} else {
|
|
27
|
+
await History.updateOne({ _id: _history }, { response: response });
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return error;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
self.retrieve = async (req, res) => {
|
|
36
|
+
try {
|
|
37
|
+
const query = {};
|
|
38
|
+
const response = { items: [], count: 0 };
|
|
39
|
+
|
|
40
|
+
if (req.body?.filter?.method) {
|
|
41
|
+
query = { method: req.body.filter.method };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
response.count = await History.countDocuments(query);
|
|
45
|
+
response.items = await History.find(query)
|
|
46
|
+
.populate({ path: "_createdBy", select: { name: 1, lastName: 1 } })
|
|
47
|
+
.sort({ createdAt: -1 })
|
|
48
|
+
.skip((req.body.config.page - 1) * req.body.config.itemsPerPage)
|
|
49
|
+
.limit(req.body.config.itemsPerPage)
|
|
50
|
+
.lean();
|
|
51
|
+
|
|
52
|
+
res.status(200).send(response);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
res.status(400).send(error);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
self.detail = async (req, res) => {
|
|
59
|
+
try {
|
|
60
|
+
const history = await History.findOne({ _id: req.params.HISTORY_ID });
|
|
61
|
+
if (!history) {
|
|
62
|
+
return res.status(404).send({
|
|
63
|
+
error: "No se encontró el elemento",
|
|
64
|
+
suggestion: "Verifica que el id del registro sea correcto",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
res.status(200).send(history);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
res.status(400).send(error);
|
|
70
|
+
}
|
|
71
|
+
};
|
package/lib/middleware.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const jwt = require("jsonwebtoken");
|
|
2
2
|
const User = require("./models/User");
|
|
3
3
|
const Permission = require("./models/Permission");
|
|
4
|
+
const historyController = require("./controllers/history");
|
|
4
5
|
|
|
5
6
|
const getAccess = (user, resource) => {
|
|
6
7
|
for (let i in user._functions) {
|
|
@@ -21,14 +22,10 @@ const getAccess = (user, resource) => {
|
|
|
21
22
|
|
|
22
23
|
const auth = async (req, res, next) => {
|
|
23
24
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
req.originalMethod +
|
|
29
|
-
"\t" +
|
|
30
|
-
req.route.path
|
|
31
|
-
);
|
|
25
|
+
let newHistory;
|
|
26
|
+
if (process.env.HISTORY === "true") {
|
|
27
|
+
//Guardar registro en la colección del Historial
|
|
28
|
+
newHistory = await historyController.create(req);
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
let token =
|
|
@@ -126,6 +123,7 @@ const auth = async (req, res, next) => {
|
|
|
126
123
|
|
|
127
124
|
req.user = user;
|
|
128
125
|
req.token = token;
|
|
126
|
+
req.history = newHistory._id.toString();
|
|
129
127
|
next();
|
|
130
128
|
} catch (error) {
|
|
131
129
|
let obj = error;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const ObjectId = mongoose.Schema.Types.ObjectId;
|
|
3
|
+
|
|
4
|
+
const historySchema = mongoose.Schema({
|
|
5
|
+
method: { type: String, default: false },
|
|
6
|
+
path: { type: String, default: true },
|
|
7
|
+
payload: { type: Object, default: {} }, // Guarda cualquier estructura JSON
|
|
8
|
+
response: { type: Object, default: {} }, // Guarda cualquier estructura JSON
|
|
9
|
+
_createdBy: { type: ObjectId, required: false, ref: "User" },
|
|
10
|
+
createdAt: { type: Number, required: true },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const History = mongoose.model("History", historySchema);
|
|
14
|
+
module.exports = History;
|
package/lib/router.js
CHANGED
|
@@ -7,6 +7,7 @@ const user = require('./controllers/user')
|
|
|
7
7
|
const menu = require('./controllers/menu')
|
|
8
8
|
const permission = require('./controllers/permission')
|
|
9
9
|
const functions = require('./controllers/functions')
|
|
10
|
+
const history = require('./controllers/history.js')
|
|
10
11
|
|
|
11
12
|
// User / user self (no auth)
|
|
12
13
|
router.post('/iam/auth/email', auth.email)
|
|
@@ -39,9 +40,8 @@ router.put('/iam/user/password/:USER_ID', middleware, user.updatepassw
|
|
|
39
40
|
router.delete('/iam/user/:USER_ID', middleware, user.delete)
|
|
40
41
|
router.get('/iam/user/count/all', middleware, user.count)
|
|
41
42
|
|
|
42
|
-
|
|
43
43
|
// IAM / Function
|
|
44
|
-
router.post('/iam/functions', middleware, functions.create)
|
|
44
|
+
router.post('/iam/functions', middleware, functions.create)
|
|
45
45
|
router.patch('/iam/functions/:FUNCTION_ID', middleware, functions.update)
|
|
46
46
|
router.put('/iam/functions/:FUNCTION_ID/status', middleware, functions.status)
|
|
47
47
|
router.get('/iam/functions', middleware, functions.retrieve)
|
|
@@ -49,9 +49,8 @@ router.get('/iam/functions/:FUNCTION_ID', middleware, functions.get)
|
|
|
49
49
|
router.delete('/iam/functions/:FUNCTION_ID', middleware, functions.delete)
|
|
50
50
|
router.get('/iam/functions/count/all', middleware, functions.count)
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
// IAM / Permission
|
|
54
|
-
router.post('/iam/permission', middleware, permission.create)
|
|
53
|
+
router.post('/iam/permission', middleware, permission.create)
|
|
55
54
|
router.patch('/iam/permission/:PERMISSION_ID', middleware, permission.update)
|
|
56
55
|
router.put('/iam/permission/:PERMISSION_ID/status', middleware, permission.status)
|
|
57
56
|
router.get('/iam/permission', middleware, permission.retrieve)
|
|
@@ -59,9 +58,8 @@ router.get('/iam/permission/:PERMISSION_ID', middleware, permission.get)
|
|
|
59
58
|
router.delete('/iam/permission/:PERMISSION_ID', middleware, permission.delete)
|
|
60
59
|
router.get('/iam/permission/count/all', middleware, permission.count)
|
|
61
60
|
|
|
62
|
-
|
|
63
61
|
// IAM / Menu
|
|
64
|
-
router.post('/iam/menu', middleware, menu.create)
|
|
62
|
+
router.post('/iam/menu', middleware, menu.create)
|
|
65
63
|
router.patch('/iam/menu/:MENU_ID', middleware, menu.update)
|
|
66
64
|
router.put('/iam/menu/:MENU_ID/status', middleware, menu.status)
|
|
67
65
|
router.get('/iam/menu', middleware, menu.retrieve)
|
|
@@ -70,7 +68,12 @@ router.delete('/iam/menu/:MENU_ID', middleware, menu.delete)
|
|
|
70
68
|
router.post('/iam/menu/order', middleware, menu.order)
|
|
71
69
|
router.get('/iam/menu/count/all', middleware, menu.count)
|
|
72
70
|
|
|
71
|
+
|
|
72
|
+
// IAM / History
|
|
73
|
+
router.post('/iam/history', middleware, history.retrieve)
|
|
74
|
+
router.get('/iam/history/:HISTORY_ID', middleware, history.detail)
|
|
75
|
+
|
|
73
76
|
// Utilities
|
|
74
|
-
router.patch('/iam/add/time/:TOKEN',
|
|
77
|
+
router.patch('/iam/add/time/:TOKEN', user.addTimeToken)
|
|
75
78
|
|
|
76
79
|
module.exports = router
|
package/lib/swagger.yaml
CHANGED
|
@@ -1178,4 +1178,52 @@ paths:
|
|
|
1178
1178
|
example: 54
|
|
1179
1179
|
responses:
|
|
1180
1180
|
'200': # status code
|
|
1181
|
-
description: Retorna el resultado de la respuesta
|
|
1181
|
+
description: Retorna el resultado de la respuesta
|
|
1182
|
+
/iam/history:
|
|
1183
|
+
post:
|
|
1184
|
+
summary: Obtener todo el historial paginado
|
|
1185
|
+
tags:
|
|
1186
|
+
- History
|
|
1187
|
+
description: Ordena los elementos de menú
|
|
1188
|
+
security:
|
|
1189
|
+
- bearerAuth: []
|
|
1190
|
+
requestBody:
|
|
1191
|
+
content:
|
|
1192
|
+
'application/json':
|
|
1193
|
+
schema:
|
|
1194
|
+
properties:
|
|
1195
|
+
filter:
|
|
1196
|
+
type: object
|
|
1197
|
+
properties:
|
|
1198
|
+
method:
|
|
1199
|
+
enum: [ GET, POST, PUT, PATCH, DELETE]
|
|
1200
|
+
config:
|
|
1201
|
+
type: object
|
|
1202
|
+
properties:
|
|
1203
|
+
page:
|
|
1204
|
+
type: number
|
|
1205
|
+
example: 1
|
|
1206
|
+
itemsPerPage:
|
|
1207
|
+
type: number
|
|
1208
|
+
example: 10
|
|
1209
|
+
responses:
|
|
1210
|
+
'200': # status code
|
|
1211
|
+
description: Retorna el resultado de la respuesta
|
|
1212
|
+
/iam/history/{HISTORY_ID}:
|
|
1213
|
+
get:
|
|
1214
|
+
parameters:
|
|
1215
|
+
- name: HISTORY_ID
|
|
1216
|
+
in: path
|
|
1217
|
+
description: ID de un registro de historial
|
|
1218
|
+
required: true
|
|
1219
|
+
schema:
|
|
1220
|
+
type: string
|
|
1221
|
+
format: ObjectId
|
|
1222
|
+
tags:
|
|
1223
|
+
- History
|
|
1224
|
+
description: Detalle de u registro de historial
|
|
1225
|
+
security:
|
|
1226
|
+
- bearerAuth: []
|
|
1227
|
+
responses:
|
|
1228
|
+
'200': # status code
|
|
1229
|
+
description: Retorna un objeto
|