Mongo issues?

This commit is contained in:
nannal 2020-02-15 16:59:27 +02:00
parent 5e95cb54bd
commit 6d84c0d11d
5 changed files with 65 additions and 6 deletions

View File

@ -1,5 +1,6 @@
# Embezzle # Embezzle
A "Simple" game about resource gathering and betraying A "Simple" game about resource gathering and betraying
## Goal ## Goal
Sneak as much money into your "charity" as possible, try to catch other members of the board stealing funds away into their own coffers. Sneak as much money into your "charity" as possible, try to catch other members of the board stealing funds away into their own coffers.

View File

@ -1,18 +1,33 @@
const express = require('express') const express = require('express')
const bodyParser = require('body-parser');
const app = express() const app = express()
app.use(bodyParser.json());
const lobby = require("./lobby.js")
//top level //top level
//get game list //get game list
app.get('/gamelist', function (req, res) {
res.send(lobby.list())
})
//get game details //get game details
app.get('/gamedetails', function (req, res) {
let obj=JSON.parse(req.body)
res.send(lobby.details(obj.gameID))
})
//post register player //post register player
app.post('/playerregister', function (req, res) {
let obj=req.body
res.send(lobby.register(obj.name))
})
//get an empty game made //get an empty game made
app.post('/gamemake', function (req, res) {
let obj=JSON.parse(req.body)
res.send(lobby.register(obj.name,obj.seats,obj.ownerID))
})
//start a game
//gamelevel //gamelevel (??)
// get this game players // get this game players
@ -26,5 +41,7 @@ const app = express()
// get winner // get winner
// get round status
console.log("Up")
app.listen(3000) app.listen(3000)

32
lobby.js Normal file
View File

@ -0,0 +1,32 @@
var mongo = require("./mongoHelp.js")
const uuidv4 = require('uuid/v4');
var lobby={
list: () => {
mongo.get("embezzle","gamelist",{}).then(result => {
return (result)
})
},
details: (gameID) => {
mongo.get("embezzle","gamelist",{"gameID":gameID}).then(result => {
return (result)
})
},
register: (name) => {
id=uuidv4()
console.log({"_id":id,"name":name})
mongo.put("embezzle","players",{"_id":id,"name":name})
return(id)
},
make: (name,seats,ownerID) => {
gameID=uuidv4()
mongo.put("embezzle","gamelist",{"gameID":gameID,"ownerID":ownerID,"name":name,"seats":seats, "status":"lobby"})
return(gameID)
},
start: (ownerID, gameID) => {
mongo.update("embezzle","gamelist",{"gameID":gameID,"ownerID":ownerID}, {"status":"Playing"})
return(gameID)
},
}
module.exports = lobby

View File

@ -34,3 +34,11 @@ function deleteOne(db, collection, object) {
} }
exports.deleteOne = deleteOne exports.deleteOne = deleteOne
function update(db, collection, search,update) {
const client = new MongoClient(url, {useUnifiedTopology:true})
client.connect()
client.db(db).collection(collection).update(search,update).then((value) =>{client.close();return value})
}
exports.update = update

View File

@ -13,6 +13,7 @@
"author": "nannal", "author": "nannal",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1", "express": "^4.17.1",
"mongodb": "^3.5.3", "mongodb": "^3.5.3",
"uuid": "^3.4.0" "uuid": "^3.4.0"