-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenCRX.js
158 lines (136 loc) · 3.91 KB
/
OpenCRX.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const axios = require('axios').default;
const baseUrl = 'https://sepp-crm.inf.h-brs.de/opencrx-rest-CRX';
const credentials = { username:'guest', password:'guest'};
const config = {
headers: {
'Accept': 'application/json'
},
auth: credentials,
};
function Sales(name, totalAmount, totalTaxAmount, totalAmountIncludingTax, contractNumber){
return{
name:name,
totalAmount:totalAmount,
totalTaxAmount: totalTaxAmount,
totalAmountIncludingTax: totalAmountIncludingTax,
contractNumber:contractNumber
}
}
function Product(name, descr, nr){
return{
name:name,
description:descr,
productNumber: nr
}
}
function Person(fullname, department, jobtitle, income){
return {
fullName: fullname,
department: department,
jobTitle: jobtitle,
annualIncome: income
}
}
function Company(fullName, accRating){
return {
fullName: fullName,
accountRating: mapRating(accRating)
}
}
function mapRating(number){
switch(number){
case 1:
return "excellent";
case 2:
return "very good";
case 3:
return "good";
default:
return "no rating";
}
}
let objekte = null;
let products = null;
let sales = null;
let rep = null;
const contacts = axios.get(`${baseUrl}/org.opencrx.kernel.account1/provider/CRX/segment/Standard/account`, config)
.then(function(value){
objekte = value.data.objects;
})
.catch(function(error){
console.log(error);
});
const produkte = axios.get(`${baseUrl}/org.opencrx.kernel.product1/provider/CRX/segment/Standard/product`, config)
.then(function(value){
products = value.data.objects;
})
.catch(function(error){
console.log(error);
});
const soldproducts = axios.get(`${baseUrl}/org.opencrx.kernel.contract1/provider/CRX/segment/Standard/salesOrder`, config)
.then(function(value){
sales = value.data.objects;
})
.catch(function(error){
console.log(error);
});
function getRep(url){
const representative = axios.get(url, config)
.then(function(value){
rep = value.data;
//console.log(rep[0])
})
.catch(function(error){
console.log(error);
})
console.log(rep)
//console.log(rep[0].fullName)
//console.log(rep.fullName)
}
const getAllProducts = () => {
console.log("Get all products");
let liste = [];
for(let i in products){
let p = new Product(products[i].name, products[i].description, products[i].productNumber);
liste[i] = p;
}
return liste;
}
const getAllSales = () => {
console.log("Get all sales");
let liste = [];
for(let i in sales){
let s = new Sales(sales[i].name, sales[i].totalAmount, sales[i].totalTaxAmount, sales[i].totalAmountIncludingTax, sales[i].contractNumber);
liste[i] = s;
console.log(getRep(sales[i].salesRep['@href']));
//console.log(sales[i].salesRep['@href']);
}
return liste;
}
const getAllCustomers = () => {
console.log("Get all customers from OpenCRX");
let liste = []
for (let o in objekte) {
if (objekte[o].hasOwnProperty("jobTitle")) {
let p = new Person(objekte[o].fullName, objekte[o].department, objekte[o].jobTitle, objekte[o].annualIncomeCurrency)
console.log(p)
liste[o] = p;
}
}
return liste;
}
const getAllCompanies = () => {
let liste = []
for (let o in objekte) {
if (objekte[o].hasOwnProperty("industry")) {
let p = new Company(objekte[o].fullName, objekte[o].accountRating);
console.log(p)
liste[o] = p;
}
}
return liste;
}
exports.getAllCustomers = getAllCustomers;
exports.getAllCompanies = getAllCompanies;
exports.getAllProducts = getAllProducts;
exports.getAllSales = getAllSales;