Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
David Golodetsky committed May 3, 2020
1 parent 40ded6a commit 64a9f98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions routes/games.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
const express = require('express')
const Game = require('../models/game');
const router = express.Router();
const mongodb = require('mongodb')

async function getGames() {
const client = await mongodb.MongoClient.connect('mongodb+srv://davidGo1995:secret123#[email protected]/test?retryWrites=true&w=majority',
{ useNewUrlParser: true })
return client.db('Cluster0').collection('games')
}

router.get('/', async (req, res) => {
user = req.query.user
// user = req.query.user
try {
const games = await Game.find();
const userGames = games.filter(game => game.user === user)
res.json(userGames);
const games = await getGames();
// const userGames = games.filter(game => game.user === user)
res.send(await games.find({}).toArray())
} catch (err) {
res.status(500).json({ message: err.message });
}
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require('dotenv').config();
const express = require('express');
const app = express();
const path = require('path');
const cors = require('cors');
const mongoose = require('mongoose');
const games = require('./routes/games');
Expand All @@ -12,6 +11,7 @@ const PORT = process.env.PORT || 3000

mongoose.connect(process.env.DATABASE_URL, { useNewUrlParser: true, useFindAndModify: false, useUnifiedTopology: true });
const db = mongoose.connection;

db.on('error', (error) => console.error(error));
db.once('open', () => console.log('Connected to database!'));

Expand Down

0 comments on commit 64a9f98

Please sign in to comment.