generated from alkemyTech/base-ong-client-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
107 lines (93 loc) · 2.62 KB
/
App.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
const express = require('express');
const bodyParser = require('body-parser');
const { fetchData, postData } = require("./src/service/apiService");
const path = require('path');
const app = express();
const port = 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static('public'));
app.get('/login', (req, res) => {
res.sendFile(path.join( __dirname , 'public' , 'login.html'));
});
app.get('/plazoFijo', (req, res) => {
res.sendFile(path.join( __dirname , 'public/plazoFijo' , 'plazoFijo.html'));
});
app.get('/cargarSaldo', (req, res) => {
res.sendFile(path.join( __dirname , 'public/cargarSaldo' , 'cargarSaldo.html'));
});
app.get('/accountback', async (req, res) => {
try {
const request = req.query
console.log("TOKEEEEEEEENNNNNN: "+request.token)
const responce = await fetchData("/accounts", request.token)
res.json(responce)
}catch (e){
console.log(e)
}
})
app.post("/loginback", async (req, res) => {
try{
const data = req.body;
const response = await postData("auth/login",{
email: data.email,
password: data.password
});
res.json(response);
} catch(error){
if(error.response.status === 403){
res.status(403).json({error: "Error 403"});
} else {
console.log(error)
}
}
});
app.post("/registerback", async (req, res) => {
try{
const data = req.body;
const response = await postData("auth/register",{
firstName : data.firstName,
lastName : data.lastName,
email : data.email,
password : data.password
});
res.json(response);
} catch(error){
if(error.response.status === 403){
res.status(403).json({error: "Error 403"});
} else {
console.log(error)
}
}
});
app.get('/transactionback',async (req, res) => {
try {
const request = req.query
console.log("TOKEEEEEEEENNNNNN: "+request.token)
const responce = await fetchData("/accounts/balance", request.token)
res.json(responce)
}catch (e) {
console.log(e)
}
});
app.post('/depositback',async (req, res) => {
try {
const request = req.body
console.log(request)
const response = await postData("/transactions/deposit", {
accountId : request.accountId,
amount: request.amount,
description: request.description
} )
console.log(response)
res.json(response)
}catch (e) {
console.log(e)
}
});
app.get('/', (req, res) => {
res.sendFile(path.join( __dirname , 'public' , 'home.html'));
});
app.listen(port, () => {
console.log(`Servidor corriendo en http://localhost:${port}`);
});