node-fetch
parent
da33f2ed43
commit
41c2ceb675
|
@ -1,4 +1,5 @@
|
|||
const aiFeedbackOnReport = async (req, res) => {
|
||||
const fetch = require('node-fetch');
|
||||
const url = process.env.AI_API_ENDOINT;
|
||||
const api_key = process.env.AI_API_KEY;
|
||||
const payload = {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const aiFeedbackOnReport = async (req, res) => {
|
||||
const fetch = require('node-fetch');
|
||||
const url = process.env.AI_API_ENDOINT;
|
||||
const api_key = process.env.AI_API_KEY;
|
||||
const payload = {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const aiFollowupQuestion = async (req, res) => {
|
||||
|
||||
const { MongoClient } = require('mongodb');
|
||||
// const fetch = require('node-fetch');
|
||||
const fetch = require('node-fetch');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const url = process.env.MONGODB_URL;
|
||||
const dbName = process.env.MONGO_DB_NAME;
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
const getGameScore = (req, res) => {
|
||||
const { MongoClient, ObjectId } = require('mongodb');
|
||||
const { userId, gameName, gameID } = req.body;
|
||||
const url = process.env.MONGODB_URL;
|
||||
const dbName = process.env.MONGO_DB_NAME;
|
||||
let db;
|
||||
|
||||
// Connect to MongoDB
|
||||
MongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }, (err, client) => {
|
||||
if (err) {
|
||||
console.error('Failed to connect to the database');
|
||||
throw err;
|
||||
}
|
||||
console.log('Connected to Database2',dbName);
|
||||
db = client.db(dbName);
|
||||
databasesList = client.db().iimttnewdb().listDatabases();
|
||||
console.log("Databases:");
|
||||
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
db.collection('gameData').findOne({ userId: userId, gameName: gameName, gameID: gameID }, (err, gameData) => {
|
||||
if (err) {
|
||||
console.error('Error fetching game data:', err);
|
||||
return res.status(500).json({ message: 'Internal Server Error' });
|
||||
}
|
||||
|
||||
if (gameData) {
|
||||
res.json({
|
||||
score: gameData.score.toString(),
|
||||
gameTime: gameData.gameTime.toFixed(2).toString()
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({ message: 'Game data not found' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = getGameScore;
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
const getGameScore = (req, res) => {
|
||||
const { MongoClient } = require('mongodb');
|
||||
|
||||
// Connection URI to your MongoDB instance
|
||||
const url = process.env.MONGODB_URL;
|
||||
const dbName = 'test';
|
||||
|
||||
// Create a new MongoClient
|
||||
const client = new MongoClient(url, { useNewUrlParser: true, useUnifiedTopology: true });
|
||||
let db;
|
||||
MongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true })
|
||||
.then(client => {
|
||||
console.log('Connected to Database',dbName);
|
||||
db = client.db(dbName);
|
||||
})
|
||||
.catch(error => console.error(error));
|
||||
// Function to list all databases
|
||||
async function listDatabases() {
|
||||
try {
|
||||
const { userId, gameName, gameID } = req.body;
|
||||
const gameData = await db.collection('gameData').findOne({
|
||||
userId: userId,
|
||||
gameName: gameName,
|
||||
gameID: gameID
|
||||
});
|
||||
|
||||
if (gameData) {
|
||||
res.json({
|
||||
score: gameData.score.toString(),
|
||||
gameTime: gameData.gameTime.toFixed(2).toString()
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({ message: 'Game data not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Internal Server Error' });
|
||||
console.error(error);
|
||||
} finally {
|
||||
// Ensure that the client will close when you finish
|
||||
await client.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Call the function
|
||||
listDatabases();
|
||||
|
||||
};
|
||||
|
||||
module.exports = getGameScore;
|
||||
|
Loading…
Reference in New Issue