-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·131 lines (116 loc) · 2.58 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var express = require('express');
var ejs = require('ejs');
var path = require('path')
var Bank = require('./models/Bank');
var Card = require('./models/Card');
var app = express();
app.set('view engine', 'ejs');
app.set('port', (process.env.PORT || 5000));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res){
res.render('deals');
});
app.get('/demo', function(req, res){
res.render('index');
});
//app.get('/posts', function(req, res){
// res.render('posts');
//});
app.get('/signup', function(req, res){
res.render('signup');
});
// app.get('/dvds', function(req, res){
// Dvd.findAll({
// where: {
// title: {
// like: '%' + req.query.title + '%'
// },
// award: req.query.award
// }
// }).then(function(results){
// res.render('dvds', {
// dvds: results,
// input: req.query.title
// });
// })
// });
app.get('/getBanks', function(req, res){
Bank.findAll().then(function(results){
res.render('banks', {
banks: results
});
})
});
// Card.belongsTo(Bank, {foreignKey: 'bank_id', targetKey: 'id'})
app.get('/getCards', function(req, res){
Card.findAll({
// include: [{
// model: Bank,
// as: 'banks'
// }],
where: {
bank_id: {
like: '%' + req.query.bank_id + '%'
},
// 'banks.bank_id': req.query.bank_id
}
}).then(function(results){
res.render('cards', {
cards: results,
bank_id: req.query.bank_id
});
})
});
app.get('/addBanks', function(req, res){
Bank.create({
bank_name: req.query.add_bank_name
// req.query.add_bank_name
}).then(function(results){
res.render('cards', {
cards: results,
});
})
});
app.get('/addCards', function(req, res){
Card.create({
bank_id: req.query.bank_id,
card_name: req.query.add_card_name,
card_offer: req.query.add_card_offer,
card_design: req.query.add_card_design
// req.query.add_bank_name
}).then(function(){
Card.findAll({
where: {
bank_id: req.query.bank_id
}
}).then(function(results){
res.render('cards', {
cards: results,
bank_id: req.query.bank_id
});
})
})
});
app.get('/getCardDetail', function(req, res){
CardDetail.findAll({
// include: [{
// model: Bank,
// as: 'banks'
// }],
where: {
bank_id: {
like: '%' + req.query.bank_id + '%'
},
// 'banks.bank_id': req.query.bank_id
}
}).then(function(results){
res.render('cards', {
cards: results,
bank_id: req.query.bank_id
});
})
});
app.listen(process.env.PORT || 5000, function(){
console.log('Newbie Card Demo Ver.');
console.log('Listening to 5000');
});