-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
104 lines (87 loc) · 2.91 KB
/
server.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
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');
const db = require('./config/db');
const port = process.env.PORT || 3000;
const app = express();
var cors = require('cors');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
MongoClient.connect( db.url , (err, database) => {
if (err) return console.log(err);
database = database.db(db.DB_NAME);
require('./app/routes') (app, database);
console.log("connected to mongo")
});
require('./app/routes') (app, {});
app.listen(port, () =>{
console.log('we are live on ' + port);
});
app.get("/bid",(req,res)=>{
app.use(cors());
console.log(req.query);
MongoClient.connect(db.url, (err,database) => {
if (err){
console.log(err);
res.send("failed");
}
var dbo = database.db(db.DB_NAME);
require('./app/routes') (app, database);
dbo.collection("ipl").findOneAndUpdate(
{"name": req.query.name},
{ $inc: {"current_bid" : 500000} },
);
dbo.collection("ipl").findOneAndUpdate(
{"name": req.query.name},
{ $set: {"team_bidding" : req.query.team_name} },
);
console.log(req.query.team_name);
});
res.send("success");
});
app.get('/send', (req,res) => {
app.use(cors());
MongoClient.connect(db.url, (err,database) => {
if (err){
console.log(err);
res.send("failed");
}
var dbo = database.db(db.DB_NAME);
require('./app/routes') (app,database);
dbo.collection('ipl').find({}).toArray(function(err, result){
if (err){
console.log(err);
res.send("failed");
}
res.send(result);
})
})
})
app.get('/populate', (req, res) => {
app.use(cors());
MongoClient.connect(db.url, (err,database) => {
if (err){
console.log(err);
res.send("failed");
}
var dbo = database.db(db.DB_NAME);
require('./app/routes') (app, database);
var item = {"name": req.query.name,
"nationality": req.query.nationality,
"current_bid": parseInt(req.query.current_bid),
"base_price": req.query.base_price,
"bowler": req.query.bowler,
"batting": req.query.batting,
"wk" : req.query.wk,
"team_bidding": "null",
"image": req.query.image}
dbo.collection("ipl").insertOne(item, (err, res) => {
if (err){
console.log(err);
res.send("failed");
}
console.log("amazing");
});
});
res.send("success");
})