-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·91 lines (73 loc) · 3.18 KB
/
app.js
File metadata and controls
executable file
·91 lines (73 loc) · 3.18 KB
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
const express = require('express');
require("dotenv").config();
const cors = require('cors');
const mongoose = require("mongoose");
const url = 'mongodb://18.144.156.140:27017';
const adminRouter = require('./routes/admin');
const firebaseTokenRouter = require('./routes/firebaseToken');
const usersRouter = require('./routes/user');
const gameRouter = require('./routes/game')
const transactionRoute = require('./routes/transaction')
const indexRouter = require('./routes/index')
const pawapayRouter = require('./routes/pawapaycalls');
const affiliateRouter = require('./routes/affiliate');
// const mongoserverurl = "mongodb+srv://tatami:t%40tami_op%230900@mongodbserverlessinstan.d4rxyeo.mongodb.net/user";
const mongoserverurl = "mongodb+srv://vuksamonju:8wYrQ0P3mC6iDaEj@cluster0.lgszp.mongodb.net/tatami";
const mongolocalurl = 'mongodb://localhost:27017/user'
const app = express();
const notification = require("./controllers/notification");
// Enable CORS for all routes
app.use(cors());
// Connect to database
try {
mongoose.connect(
mongoserverurl, {
useUnifiedTopology: true,
useNewUrlParser: true
});
console.log("connected to db");
} catch (error) {
console.log('error in connection')
console.log("error" + JSON.stringify(error))
}
process.on('unhandledRejection', error => {
//console.log('unhandledRejection', error.message);
});
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use('/users', usersRouter);
app.use('/game', gameRouter);
app.use('/transaction', transactionRoute)
app.use('/index', indexRouter)
app.use('/pawapayapi', pawapayRouter)
app.use('/admin', adminRouter)
app.use("/firebase", firebaseTokenRouter)
app.use("/referral", affiliateRouter)
// notification.getExistingUserWhoHaveNotPlacedAnySingleBetLastThreeDaysToSendNotificationAndSms();
notification.sendRandomNotification();
// const XAFTransfer = require("./models/XAFTransfer");
// // Define a new route handler for getting unique receiver user IDs
// app.get('/uniqueReceiverUserIds/:senderUserId', async (req, res) => {
// const senderUserId = req.params.senderUserId;
// try {
// // Query the database for XAF transfers with the given senderUserId
// const transfers = await XAFTransfer.find({ senderUserId });
// // Extract receiver user IDs from transfer documents
// const receiverUserIds = transfers.map(transfer => transfer.receiverUserId);
// console.log("receiverUserIds", receiverUserIds);
// // Remove duplicates from the array
// const uniqueReceiverUserIds = [...new Set(receiverUserIds)];
// console.log("uniqueReceiverUserIds", uniqueReceiverUserIds);
// // Update balance and bonus of users with the unique receiver user IDs
// await Promise.all(uniqueReceiverUserIds.map(async userId => {
// // Assuming userId is the _id field in ObjectId format
// await User.updateOne({ _id: userId }, { $set: { balance: 0, bonus: 0 } });
// }));
// // Send unique receiver user IDs as a response
// res.json(uniqueReceiverUserIds);
// } catch (error) {
// console.error("Error retrieving XAF transfers:", error);
// res.status(500).json({ error: "Internal server error" });
// }
// });
module.exports = app;