-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (70 loc) · 2.3 KB
/
index.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
const { Console } = require('console');
const express = require('express');
const { response } = require('express');
app = express();
request = require('request')
// Settings
app.set('appName','TorreTechnicalTest');
app.set('port',3000)
app.set('view engine','ejs');
path = require('path');
app.use(express.static(path.join(__dirname, "/public")));
cookieParser = require('cookie-parser'),
cookieSession = require('cookie-session');
app.use(cookieParser());
app.use(cookieSession({secret: "I'm a secret"}));
app.get('/', (peticion, respuesta)=>{
peticion.session.visitas || (peticion.session.visitas = 0);
let n = peticion.session.visitas++;
console.log(`Cantidad Visitas ${n}`)
respuesta.sendFile(`${__dirname}/index.html`)
});
app.get('/photo',(req, res)=>{
// MIDDLEWARES
app.use(express.json());
// ROUTES
let data;
username = req.query.userName
request.get('https://torre.bio/api/bios/' + username, function(error, body){
res.json(body);
data=body;
});
});
//ROUTES
app.get('/offer', (req, res)=>{
// MIDDLEWARES
app.use(express.json());
let offer;
request.get('https://torre.co/api/opportunities/ed8YxErX', function(error,body){
res.json(body);
offer=body;
});
});
app.get('/compare', (req, res)=>{
// MIDDLEWARES
app.use(express.json());
username = req.query.userName
offerId = req.query.offerId
request.get('https://torre.bio/api/bios/'+username, function(error, body){
user=JSON.parse(body.body);
request.get('https://torre.co/api/opportunities/'+offerId, function(error,body){
offer=JSON.parse(body.body);
user_strengths = []
user.strengths.forEach(item => {
user_strengths.push(item.name)
});
offer_strengths = []
offer.strengths.forEach(item => {
offer_strengths.push(item.name)
});
// Source: https://medium.com/@alvaro.saburido/set-theory-for-arrays-in-es6-eb2f20a61848
res.json({
'interception': offer_strengths.filter(x => user_strengths.includes(x)),
'difference': offer_strengths.filter(x => !user_strengths.includes(x))
})
});
});
})
app.listen(process.env.PORT || 3000, () =>{
console.log('I´m working right! Yeah')
});