-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
91 lines (82 loc) · 3.33 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
const express = require('express');
const app = express();
const mongoose = require('mongoose')
const subroutes=require('./routes/Subscription')
const touristingroutes=require('./routes/Touristing')
const amenityroutes=require('./routes/Amenities')
const cron = require('node-cron');
const homeroutes=require('./routes/Home')
const mongoDB='mongodb://viluexasasaddsad:dasd8as9DsdaASDADsas9d@75.119.139.19:27913/viluex';
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
//Get the default connection
var db = mongoose.connection;
//Bind connection to error event (to get notification of connection errors)
db.on('open', () => {
console.log('database connected')
})
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use('/touristing',touristingroutes)
app.use('/subscription',subroutes)
app.use('/link',require('./routes/links'))
app.use('/category',require('./routes/category'))
app.use('/report',require('./routes/reqports'))
app.use('/amenity',amenityroutes)
app.use('/home',homeroutes)
const link=require('./schema/links')
const cat=require('./schema/category')
app.get('/home',(req,res)=>{
link.find()
.sort({ratings:-1})
.limit(3)
.exec((er,tr)=>{
if(err) res.json(error(er))
else{
cat.find()
.exec((Er,info)=>{
if(Er) res.json(error(Er))
else{
link.find()
.sort({created_date:-1})
.limit(3)
.exec((Err,Doc)=>{
if(Err) res.json(error(Err))
else{
link.find({
geometry: {
$nearSphere: {
$geometry: {
type: 'Point',
coordinates: [longitude, latitude], //longitude and latitude
},
$minDistance: 0,
$maxDistance: 10 * 1000,
},
},
})
.exec((err,doc)=>{
if(err) res.json(error(err))
else res.jsonp(success({toprated:tr,categories:info,newly_added:Doc,nearby:doc}))
})
}
})
}
})
}
})
})
cron.schedule('* * * * *', function() {
console.log('har minute pe check karo isSubscribed true wali listing ko or agr expiryddate braber ho ya choti ho aj ki date se toh usse isSubscribed false karde');
var date=new Date();
link.updateMany({$and:[{expiry_date:{$lte:date}},{isSubscribed:true}]} ,{isSubscribed:false,selectedsubscription:null,expiry_date:null},{new:true},(err,doc)=>{
if(err){
console.log({message:"Failed",err})
}
else{
console.log("removed subscription",doc)
}
})
});
const PORT = process.env.PORT || 4004
app.listen(PORT, () => { console.log(`Server started at port ${PORT}`) })