sysone-api-mapper 1.0.2 → 1.0.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/index.js +3 -0
- package/package.json +5 -1
- package/src/mapper/mapper.js +69 -0
- package/src/mapper/modules/policy/index.js +37 -0
- package/src/public/index.html +15 -0
- package/src/public/index.js +9 -0
- package/src/server.js +7 -3
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sysone-api-mapper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "To make it easy for you to get started with GitLab, here's a list of recommended next steps.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,5 +35,9 @@
|
|
|
35
35
|
"type": "git",
|
|
36
36
|
"url": "git+https://gitlab.sysone.com/sysone-cloud-ready/sales-platform/api-mapper/-/tree/develop?ref_type=heads"
|
|
37
37
|
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": "^18.0.0",
|
|
40
|
+
"react-dom": "^18.0.0"
|
|
41
|
+
},
|
|
38
42
|
"private": false
|
|
39
43
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { axiosInstance } from "sysone-api-mapper";
|
|
2
|
+
import { getInsureds_CNP } from "./modules/policy";
|
|
3
|
+
|
|
4
|
+
export const apiMapper = async (endpointCode, tenant, routeParams, params = null) => {
|
|
5
|
+
try {
|
|
6
|
+
const configData = tenantsConfig[endpointCode]
|
|
7
|
+
const endpointData = configData[tenant] ?? configData.default
|
|
8
|
+
|
|
9
|
+
const url = getUrl(endpointData.url, routeParams);
|
|
10
|
+
let response;
|
|
11
|
+
switch (endpointData.method) {
|
|
12
|
+
case methods.GET:
|
|
13
|
+
response = await axiosInstance.get(url, { params });
|
|
14
|
+
return endpointData.responseMapper(response.data);
|
|
15
|
+
case methods.POST:
|
|
16
|
+
// aca podria ejecutarse requestMapper
|
|
17
|
+
response = await axiosInstance.post(url, params);
|
|
18
|
+
return endpointData.responseMapper(response.data);
|
|
19
|
+
case methods.PUT:
|
|
20
|
+
// aca podria ejecutarse requestMapper
|
|
21
|
+
response = await axiosInstance.put(url, params);
|
|
22
|
+
return endpointData.responseMapper(response.data);
|
|
23
|
+
case methods.DELETE:
|
|
24
|
+
response = await axiosInstance.delete(url, params);
|
|
25
|
+
return endpointData.responseMapper(response.data);
|
|
26
|
+
default:
|
|
27
|
+
response = null;
|
|
28
|
+
throw new Error(
|
|
29
|
+
"Request error: Method not allowed. Only use GET, POST, PUT, DELETE"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
} catch (e) {
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getUrl = (serviceUrl, routeParams) => {
|
|
38
|
+
if (!routeParams) return serviceUrl;
|
|
39
|
+
return serviceUrl.replace(/{(\d+)}/g, function (match, routeParamNumber) {
|
|
40
|
+
return routeParams[routeParamNumber]
|
|
41
|
+
? routeParams[routeParamNumber]
|
|
42
|
+
: match;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const methods = {
|
|
47
|
+
GET: "GET",
|
|
48
|
+
POST: "POST",
|
|
49
|
+
PUT: "PUT",
|
|
50
|
+
DELETE: "DELETE",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const tenantsConfig = {
|
|
55
|
+
GET_INSUREDS: {
|
|
56
|
+
default: {
|
|
57
|
+
url: 'policy-life/v1/policies/{0}/insureds',
|
|
58
|
+
method: methods.GET,
|
|
59
|
+
requestMapper: null,
|
|
60
|
+
responseMapper: (response) => (response),
|
|
61
|
+
},
|
|
62
|
+
cnp: {
|
|
63
|
+
url: 'policy/v1/policy/{0}/{1}/policy-insured',
|
|
64
|
+
method: methods.GET,
|
|
65
|
+
requestMapper: null,
|
|
66
|
+
responseMapper: (response) => { getInsureds_CNP(response) },
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const getInsureds_CNP = async (response) => {
|
|
2
|
+
const objectMapped = {
|
|
3
|
+
total: response.insureds.length,
|
|
4
|
+
totalActive: null,
|
|
5
|
+
values: response.insureds.map((i) => ({
|
|
6
|
+
code: i.code,
|
|
7
|
+
number: i.id,
|
|
8
|
+
firstName: i.firstName || i.name,
|
|
9
|
+
lastName: i.lastName,
|
|
10
|
+
type: {
|
|
11
|
+
code: i.role.code === "T" ? "OWNER" : "ADHERENT",
|
|
12
|
+
name: i.role.code === "T" ? "Titular" : "Adherente"
|
|
13
|
+
},
|
|
14
|
+
status: {
|
|
15
|
+
code: "ACTIVE",
|
|
16
|
+
name: "Activo"
|
|
17
|
+
},
|
|
18
|
+
insuredAmount: i.insuredAmount,
|
|
19
|
+
inclusionDate: i.entranceDate,
|
|
20
|
+
exclusionDate: i.cancellationDate,
|
|
21
|
+
identification: {
|
|
22
|
+
value: i.identification.number,
|
|
23
|
+
type: {
|
|
24
|
+
name: i.identification.type.name,
|
|
25
|
+
code: i.identification.type.code
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return objectMapped
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
getInsureds_CNP
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Mi Package NPM</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root">
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
<script type="module" src="index.js"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
package/src/server.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const express = require("express");
|
|
2
2
|
const cors = require("cors");
|
|
3
3
|
require("dotenv").config();
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const ReactDOM = require("react-dom")
|
|
6
|
+
|
|
4
7
|
|
|
5
8
|
const app = express();
|
|
6
9
|
const port = process.env.PORT || 3000;
|
|
@@ -10,9 +13,10 @@ app.use(cors());
|
|
|
10
13
|
app.use(express.json());
|
|
11
14
|
|
|
12
15
|
// Ruta raíz
|
|
13
|
-
app.get("
|
|
14
|
-
res.
|
|
15
|
-
})
|
|
16
|
+
app.get("*", (req, res) => {
|
|
17
|
+
res.sendFile(path.join(__dirname, "public", "index.html"));
|
|
18
|
+
})
|
|
19
|
+
|
|
16
20
|
|
|
17
21
|
// Iniciar el servidor
|
|
18
22
|
app.listen(port, () => {
|