Skip to content

Commit

Permalink
reset game after 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Naman Dureja authored and Naman Dureja committed Jan 12, 2022
1 parent 3230a18 commit bce76da
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 20 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require("express");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const accessCode = require("./middleware/accessCode.js");
const db = require("./db")
const {callBack} = require("./db");
require("dotenv").config();

const app = express();
Expand All @@ -21,7 +21,7 @@ app.get("/",(_,res) => res.redirect("/vip"));

const isProduction = process.env.NODE_ENV == "production";
if (!process.env.PORT) process.env.PORT = isProduction ? 80 : 3000;
db(() => {
callBack(() => {
app.listen(process.env.PORT, () => {
console.log(`server is listening on port ${process.env.PORT}`);
});
Expand Down
6 changes: 0 additions & 6 deletions data/games.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@
"game_no": 6,
"name": "Squid Game",
"description": "The game is played by drawing a square, a triangle and two circles on the ground (the same shapes seen throughout the whole series) and has two teams trying to invade each other’s space. The tricky part is: you can’t touch any lines and must hop on one foot on most areas. Of course, players will try their best to make you fall along the way."
},
{
"uuid": "9ecb1ba7-1ae3-4a32-81c1-bc767cfbb023",
"game_no": 7,
"name": "Ended",
"description": "The games have ended"
}
]
}
24 changes: 20 additions & 4 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ const User = require("./models/User.js");
const Player = require("./models/Player.js");
const Game = require("./models/Game.js");
const Worker = require("./models/Worker.js");
const res = require("express/lib/response");

const initDatabase = async () => {
const initDatabase = async (callback) => {
console.log("initializing database...");

let admin = new User({
_id: "frontman",
password: crypto.createHash('sha256').update(process.env.FRONTMAN_PASS).digest('hex'),
isFrontman: true
});
await admin.save();

let vip = new User({
_id: "vipvip",
password: crypto.createHash('sha256').update(process.env.VIP_PASS).digest('hex'),
walletAddress: process.env.VIP_WALLET
})
await vip.save();
const players = require("./data/players.json")
for (let i = 0; i < players.rows.length; i++) {
let firstName = players.rows[i].name.split(" ")[0];
Expand Down Expand Up @@ -43,13 +49,23 @@ const initDatabase = async () => {
}

console.log("done");

}

const resetDatabase = (callback)=>{
mongoose.connection.db.dropDatabase().then(()=>{
callback();
});
};


module.exports = callback => {
module.exports.callBack = callback => {
mongoose.connect(process.env.NODE_ENV == "production" ? process.env.DB_URL : "mongodb://localhost:27017/ojingeo", async () => {
let admin = await User.findOne({ _id: "frontman" });
if (!admin) await initDatabase();
callback();
});
}
}

module.exports.reset = resetDatabase;
module.exports.init = initDatabase;
1 change: 0 additions & 1 deletion middleware/accessCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ module.exports = (req, res, next) => {
} else {
res.render("accessCode");
}

}
1 change: 0 additions & 1 deletion public/css/profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ textarea:focus, input:focus, select:focus{
display: flex;
margin-top: 80px;
align-items: center;
display: none;
justify-content: center;
flex-direction: column;
}
Expand Down
10 changes: 8 additions & 2 deletions routes/frontman.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Game = require("../models/Game");
const fs = require("fs");
const User = require("../models/User");
const { createTransaction } = require("../helpers/bitcoinHelper")

const {reset,init} = require('../db')
const router = express.Router();

router.use("/", isLoggedIn);
Expand Down Expand Up @@ -168,7 +168,13 @@ router.get("/games/next", async (req, res) => {
if (nextGame) {
nextGame.isCurrentGame = true;
await nextGame.save();
}
} else{
reset(async ()=>{
await init();
res.redirect('/');
});
return;
}

// process bets
for (let user of users) {
Expand Down
6 changes: 3 additions & 3 deletions views/accessCode.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Access Denied</title>
<title>Access Port</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Oxygen:wght@300;400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../css/access.css">
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/access.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/parallax/3.1.0/parallax.min.js"></script>
<!-- CSS only -->

Expand Down
2 changes: 1 addition & 1 deletion views/vipGames.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<a href="/vip/games" class="nav active">Games</a>
</div>
<div class="user-log " onclick="openProfile()">
<img src="./user-2-red.png">
<img src="./user-2.png">
&nbsp; Profile
</div>
</nav>
Expand Down

0 comments on commit bce76da

Please sign in to comment.