diff --git a/backend/app.js b/backend/app.js deleted file mode 100755 index 9b61f34..0000000 --- a/backend/app.js +++ /dev/null @@ -1,784 +0,0 @@ -const express = require('express'); -const mongoose = require('mongoose'); -const bcrypt = require('bcrypt'); -const jwt = require('jsonwebtoken'); - -const check_auth = require('./check_auth'); - -const app = express(); - -mongoose - .connect( - "mongodb://localhost:27017/myapp" - // "mongodb://ladder:YnwLdH8guBV9EOam@cluster0-shard-00-00-cvuiq.mongodb.net:27017,cluster0-shard-00-01-cvuiq.mongodb.net:27017,cluster0-shard-00-02-cvuiq.mongodb.net:27017/myLadder?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority" - ) - .then(() => { - console.log("Connected to database!"); - }) - .catch(error => { - console.log(error); - }); - -app.use(express.json()); - -const Player = require('./models/player'); -const Match = require('./models/match'); - - -app.get((req, res, next) =>{ - res.setHeader('Access-Control-Allow-Origin', '*'); - res.setHeader( - "Access-Control-Allow-Headers", - "Origin, X-Requested-With, Content-Type, Accept, authorization" - ); - res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, DELETE, OPTIONS'); - res.setHeader("Access-Control-Allow-Headers", "*"); - next(); -}) - -app.all('*', function (req, res, next) { - res.header("Access-Control-Allow-Origin", "*"); - res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, authorization"); - res.header('Access-Control-Allow-Methods', 'GET, POST, PATCH, DELETE, OPTIONS'); - next(); -}); - -// Ladder Table -function predicateBy(prop) { - return (a, b) => { - if (a[prop] > b[prop]) { - return -1; - } else if (a[prop] < b[prop]) { - return 1; - } - return 0; - }; -} - -// removing error -app.get('/api/table', (req, res, next) => { - res.status(200); -}); - -// Getting Ladder Sports -app.post('/api/table/sports', (req, res, next) => { - Player.findOne({_id: req.body.id}).then(data => { - sport = ''; - if (data){ - sport = data.preferred; - } - res.status(200).json(sport); - }); -}); - -// Squash Data -app.get('/api/table/squash', (req, res, next) => { - const squashData = []; - Player.find({ preferred: { $regex: "squash" } }).then(documents => { - for (let i = 0; i < documents.length; i++) { - squashData.push({ - id: documents[i]["_id"], - rank: null, - username: documents[i]["name"], - points: documents[i]["squash_score"], - category: documents[i]["category"], - matchPlayed: documents[i]["match_played_squash"], - matchWon: documents[i]["match_won_squash"] - }); - } - squashData.sort(predicateBy("points")); - - for (let i = 0; i < squashData.length; i++) { - squashData[i].rank = i + 1; - } - res.status(200).json(squashData); - }); -}); - -// Table Tennis Data -app.get('/api/table/tt', (req, res, next) => { - const ttData = []; - Player.find({ preferred: { $regex: "tt" } }).then(documents => { - for (let i = 0; i < documents.length; i++) { - ttData.push({ - id: documents[i]["_id"], - rank: null, - username: documents[i]["name"], - points: documents[i]["tt_score"], - category: documents[i]["category"], - matchPlayed: documents[i]["match_played_tt"], - matchWon: documents[i]["match_won_tt"] - }); - } - ttData.sort(predicateBy("points")); - - for (let i = 0; i < ttData.length; i++) { - ttData[i].rank = i + 1; - } - res.status(200).json(ttData); - }); -}); - -// Lawn Tennis Data -app.get('/api/table/tennis', (req, res, next) => { - const tennisData = []; - Player.find({ preferred: { $regex: "tennis" } }).then(documents => { - for (let i = 0; i < documents.length; i++) { - tennisData.push({ - id: documents[i]["_id"], - rank: null, - username: documents[i]["name"], - points: documents[i]["tennis_score"], - category: documents[i]["category"], - matchPlayed: documents[i]["match_played_tennis"], - matchWon: documents[i]["match_won_tennis"] - }); - } - tennisData.sort(predicateBy("points")); - - for (let i = 0; i < tennisData.length; i++) { - tennisData[i].rank = i + 1; - } - res.status(200).json(tennisData); - }); -}); - -// Badminton Data -app.get('/api/table/badminton', (req, res, next) => { - - const badmintonData = []; - Player.find({ preferred: { $regex: "badminton" } }).then(documents => { - for (let i = 0; i < documents.length; i++) { - badmintonData.push({ - id: documents[i]["_id"], - rank: null, - username: documents[i]["name"], - points: documents[i]["baddy_score"], - category: documents[i]["category"], - matchPlayed: documents[i]["match_played_baddy"], - matchWon: documents[i]["match_won_baddy"] - }); - } - badmintonData.sort(predicateBy("points")); - - for (let i = 0; i < badmintonData.length; i++) { - badmintonData[i].rank = i + 1; - } - res.status(200).json(badmintonData); - }); -}); - -// Add a challenge -app.post('/api/challenge/addMatch', (req, res, next) => { - const match = new Match({ - p1_id: req.body.p1_id, - p1_name: req.body.p1_name, - p2_id: req.body.p2_id, - p2_name: req.body.p2_name, - sport: req.body.sport, - message: req.body.message, - date: req.body.date, - time: req.body.time, - set_score: "", - match_score: "", - winner_1: false, - winner_2: false, - confirm_1: false, - confirm_2: false, - report_secy: false, - rejected: false - }); - match.save().then((data) => { - res.status(200).json(data); - }).catch((error) => { - console.log(error); - }); -}); - -// Notifications -app.post("/api/notification/challengesN", (req, res, next) => { - Match.find({ - $or: [ - { - $and: [ - { p1_id: req.body.id }, - { accepted: false }, - { rejected: false } - ] - }, - { - $and: [ - { p2_id: req.body.id }, - { ok: false }, - { $or: [ - { accepted: true }, - { rejected: true } - ] - } - ] - } - ] - }).then(documents => { - length = documents.length; - res.status(200).json(length); - }); -}); - -app.post("/api/notification/challengesP", (req, res, next) => { - Match.find({ - $and: [ - { $or: [{ p1_id: req.body.id }, { p2_id: req.body.id }] }, - { $or: [{ accepted: true }, { rejected: true }] }, - { $and: [{ confirm_1: false }, { confirm_2: false }] } - ] - }).then(documents => { - length = documents.length; - res.status(200).json(length); - }); -}); - -app.post("/api/notification/challengesC", (req, res, next) => { - Match.find({ - $or: [ - { - $and: [ - { p1_id: req.body.id }, - { confirm_2: true }, - { confirm_1: false } - ] - }, - { - $and: [ - { p2_id: req.body.id }, - { confirm_1: true }, - { confirm_2: false } - ] - } - ] - }).then(documents => { - length = documents.length; - res.status(200).json(length); - }); -}); - -// Display Challenges -app.post('/api/challenge/challengesR', (req, res, next) => { - Match.find( { p1_id: req.body.id } ) - .then(documents => { - documents = documents.filter(document_s => document_s.rejected == false && document_s.accepted == false); - res.status(200).json(documents); - }); -}); - -app.post("/api/challenge/challengesS", (req, res, next) => { - Match.find({ p2_id: req.body.id }).then(documents => { - documents = documents.filter(document_s => document_s.ok == false); - res.status(200).json(documents); - }); -}); - -// Deleting Sent Challenge -app.delete("/api/challenge/removechallengeS/:id", (req, res, next) => { - Match.deleteOne({ _id: req.params.id }).then(result => { - console.log(result); - res.status(200).json({ message: "Match deleted!" }); - }); -}); - -// Accepting Received Challenge -app.post("/api/challenge/accept", (req, res, next) => { - Match.updateOne({ _id: req.body.id }, { accepted: true }).then(result => { - res.status(200).json(result); - }); -}); - - -// Rejecting Received Challenge -app.get("/api/challenge/removechallengeR/:id", (req, res, next) => { - Match.updateOne({ _id: req.params.id }, { rejected: true }).then(result => { - console.log(result); - res.status(200).json({ message: "Match rejected!" }); - }); -}); - -// Acknowleding Accepted Challenge -app.post("/api/challenge/acknowledge/", (req, res, next) => { - Match.updateOne({ _id: req.body.id }, { ok: true }).then(result => { - res.status(200).json(result); - }); -}); - -// Getting Previous Matches -app.post("/api/previous", (req, res, next) => { - Match.find({$and: [{$or: [ { p1_id : req.body.id }, {p2_id : req.body.id} ] }, {accepted: true} ] }) - .then(documents => { - res.status(200).json(documents); - }); -}); - -// Update Score -app.post('/api/previous/updateScore', (req, res, next) => { - Match.findOne({_id: req.body.matchId}) - .then(match => { - if (match.p1_id == req.body.id) { - Match.updateOne( - { _id: req.body.matchId }, - { - match_score: req.body.matchScore, - set_score: req.body.setScore, - confirm_1: true - } - ).then(result => { - res.status(200).json(result); - }); - } - else { - Match.updateOne( - { _id: req.body.matchId }, - { - match_score: req.body.matchScore, - set_score: req.body.setScore, - confirm_2: true - } - ).then(result => { - res.status(200).json(result); - }); - } - }); -}); - -// Checking if player setting score is Player 1 -app.post("/api/isPlayer1", (req, res, next) => { - Match.findOne({$and: [{p1_id: req.body.id}, {_id: req.body.matchId}]}) - .then(documents => { - if (length){ - res.status(200).json(false); - return; - } - res.status(200).json(true); - }) -}); - - -// Display Confirmations -app.post('/api/confirmations/', (req, res, next) => { - Match.find({ - $or: [ - { - $and: [ - { p2_id: req.body.id }, - { confirm_1: true }, - { confirm_2: false } - ] - }, - { - $and: [ - { p1_id: req.body.id }, - { confirm_1: false }, - { confirm_2: true } - ] - } - ] - }).then(documents => { - res.status(200).json(documents); - }); -}); - -// Rejecting Final Confirmation -app.post("/api/confirmations/finalReject", (req, res, next) => { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_1: false, confirm_2: false, set_score: "", match_score: "" } - ).then(data => {}); -}); - -// Accepting Final Confirmation and Deciding Winner -app.post('/api/confirmations/finalResult/', (req, res, next) => { - Match.findOne({_id: req.body.matchId}) - .then(match => { - const score = match.match_score.split('-').map(Number); - if (score[0] > score[1]){ - if (match.p1_id == req.body.id) { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_1: true, winner_1: true } - ).then(documents => { - if (documents.nModified == 0) { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_1: true, winner_1: true } - ).then(docs => { - res.status(200).json(docs); - }); - } - res.status(200).json(documents); - }); - } - else { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_2: true, winner_1: true } - ).then(documents => { - if (documents.nModified == 0) { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_2: true, winner_1: true } - ).then(docs => { - res.status(200).json(docs); - }); - } - res.status(200).json(documents); - }); - } - } - else if (score[0] < score[1]) { - if (match.p1_id == req.body.id) { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_1: true, winner_2: true } - ).then(documents => { - if (documents.nModified == 0) { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_1: true, winner_2: true } - ).then(docs => { - res.status(200).json(docs); - }); - } - res.status(200).json(documents); - }); - } else { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_2: true, winner_2: true } - ).then(documents => { - if (documents.nModified == 0) { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_2: true, winner_2: true } - ).then(docs => { - res.status(200).json(docs); - }); - } - res.status(200).json(documents); - }); - } - } - else { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_2: true, winner_2: true, winner_1: true } - ).then(documents => { - if (documents.nModified == 0) { - Match.updateOne( - { _id: req.body.matchId }, - { confirm_1: true, winner_2: true, winner_1: true } - ).then(docs => { - res.status(200).json(docs); - }); - } - res.status(200).json(documents); - }); - } - }); - -}); - -// Algo Bitch -app.post("/api/algo", (req, res, next) => { - Match.findOne({_id: req.body.matchId}) - .then((documents) => { - const p1 = documents.p1_id; - const p2 = documents.p2_id; - var p1Rate = 0; - var p2Rate = 0; - var p1MatchesPlayed = 0; - var p1MatchesWon = 0; - var p2MatchesPlayed = 0; - var p2MatchesWon = 0; - var p1RateNew = 0; - var p2RateNew = 0; - const p1Set = Number(documents.match_score.split('-')[0]); - const p2Set = Number(documents.match_score.split("-")[1]); - const p1SetScore = []; - const p2SetScore = []; - var p1TotalPoints = 0; - var p2TotalPoints = 0; - const ds = Math.abs(p1Set - p2Set); - for (const dataSet of documents.set_score.split(' ')) { - p1TotalPoints = p1TotalPoints + Number(dataSet.split("-")[0]); - p2TotalPoints = p2TotalPoints + Number(dataSet.split("-")[1]); - p1SetScore.push(Number(dataSet.split('-')[0])); - p2SetScore.push(Number(dataSet.split("-")[1])); - } - const totalPoints = p1TotalPoints + p2TotalPoints; - Player.findOne({ _id: p1 }).then(score1 => { - switch (documents.sport) { - case "squash": - p1Rate = score1.squash_score; - console.log('first'); - console.log(p1Rate); - p1MatchesPlayed = score1.match_played_squash; - p1MatchesWon = score1.match_won_squash; - break; - case "tt": - p1Rate = score1.tt_score; - p1MatchesPlayed = score1.match_played_tt; - p1MatchesWon = score1.match_won_tt; - break; - case "tennis": - p1Rate = score1.tennis_score; - p1MatchesPlayed = score1.match_played_tennis; - p1MatchesWon = score1.match_won_tennis; - break; - case "badminton": - p1Rate = score1.baddy_score; - p1MatchesPlayed = score1.match_played_baddy; - p1MatchesWon = score1.match_won_baddy; - break; - } - Player.findOne({ _id: p2 }).then(score2 => { - switch (documents.sport) { - case "squash": - p2Rate = score2.squash_score; - p2MatchesPlayed = score2.match_played_squash; - p2MatchesWon = score2.match_won_squash; - break; - case "tt": - p2Rate = score2.tt_score; - p2MatchesPlayed = score2.match_played_tt; - p2MatchesWon = score2.match_won_tt; - break; - case "tennis": - p2Rate = score2.tennis_score; - p2MatchesPlayed = score2.match_played_tennis; - p2MatchesWon = score2.match_won_tennis; - break; - case "badminton": - p2Rate = score2.baddy_score; - p2MatchesPlayed = score2.match_played_baddy; - p2MatchesWon = score2.match_won_baddy; - break; - } - p1MatchesPlayed = p1MatchesPlayed + 1; - p2MatchesPlayed = p2MatchesPlayed + 1; - if (p1Set > p2Set) { - p1MatchesWon = p1MatchesWon + 1; - p1RateNew = - p1Rate + - Math.round( - 9 + - 0.05 * (p2Rate - p1Rate) + - ds - - 4 * (p2TotalPoints / totalPoints) - ); - p2RateNew = - p2Rate - - Math.round( - 9 + - 0.05 * (p2Rate - p1Rate) + - ds - - 4 * (p2TotalPoints / totalPoints) - ); - } else { - p2MatchesWon = p2MatchesWon + 1; - p1RateNew = - p1Rate - - Math.round( - 9 + - 0.05 * (p1Rate - p2Rate) + - ds - - 4 * (p1TotalPoints / totalPoints) - ); - p2RateNew = - p2Rate + - Math.round( - 9 + - 0.05 * (p1Rate - p2Rate) + - ds - - 4 * (p1TotalPoints / totalPoints) - ); - } - switch (documents.sport) { - case "squash": - Player.updateOne( - { _id: p1 }, - { - squash_score: p1RateNew, - match_played_squash: p1MatchesPlayed, - match_won_squash: p1MatchesWon - } - ).then(); - Player.updateOne( - { _id: p2 }, - { - squash_score: p2RateNew, - match_played_squash: p2MatchesPlayed, - match_won_squash: p2MatchesWon - } - ).then(); - break; - case "tt": - Player.updateOne( - { _id: p1 }, - { - tt_score: p1RateNew, - match_played_tt: p1MatchesPlayed, - match_won_tt: p1MatchesWon - } - ).then(); - Player.updateOne( - { _id: p2 }, - { - tt_score: p2RateNew, - match_played_tt: p2MatchesPlayed, - match_won_tt: p2MatchesWon - } - ).then(); - break; - case "tennis": - Player.updateOne( - { _id: p1 }, - { - tennis_score: p1RateNew, - match_played_tennis: p1MatchesPlayed, - match_won_tennis: p1MatchesWon - } - ).then(); - Player.updateOne( - { _id: p2 }, - { - tennis_score: p2RateNew, - match_played_tennis: p2MatchesPlayed, - match_won_tennis: p2MatchesWon - } - ).then(); - break; - case "badminton": - Player.updateOne( - { _id: p1 }, - { - tt_score: p1RateNew, - match_played_tt: p1MatchesPlayed, - match_won_tt: p1MatchesWon - } - ).then(); - Player.updateOne( - { _id: p2 }, - { - tt_score: p2RateNew, - match_played_tt: p2MatchesPlayed, - match_won_tt: p2MatchesWon - } - ).then(); - break; - } - res.status(200).json(documents.sports); - }); - }); - }); -}); - - -// User signup -app.post('/api/signup', (req, res, next) => { - bcrypt.hash(req.body.password, 10) - .then(hash => { - const player = new Player({ - name: req.body.name, - roll: req.body.roll, - hostel: req.body.hostel, - gender: req.body.gender, - category: req.body.category, - preferred: req.body.preferred, - contact: req.body.contact, - password: hash - }); - player.save() - .then(result => { - res.status(201).json({ - result: result - }); - }) - .catch(err => { - res.status(500).json({ - error: err - }); - }); - }); -}); - -// User Login -app.post("/api/login", (req, res, next) => { - let fetchedPlayer; - Player.findOne({roll: req.body.roll}) - .then(player => { - if (!player) { - return res.status(401).json({ - messgae: 'Auth failed!' - }); - } - fetchedPlayer = player; - return bcrypt.compare(req.body.password, player.password); - }) - .then(result => { - if (!result) { - return res.status(401).json({ - messgae: "Auth failed!" - }); - } - const token = jwt.sign( - { roll: fetchedPlayer.roll, playerId: fetchedPlayer._id }, - 'harsh_is_god_he_is_invincible' - ); - res.status(200).json({ - token: token, - id: fetchedPlayer._id, - name: fetchedPlayer.name, - sport: fetchedPlayer.preferred - }) - }) - .catch(err => { - console.log(err); - }); -}); - -// Get Profile -app.post('/api/profile', (req, res, next) => { - Player.findOne({_id: req.body.id}) - .then((documents) => { - const player = { - id: documents._id, - name: documents.name, - roll: documents.roll, - hostel: documents.hostel, - gender: documents.gender, - category: documents.category, - preferred: documents.preferred, - contact: documents.contact, - squash_score: documents.squash_score, - tennis_score: documents.tennis_score, - baddy_score: documents.baddy_score, - tt_score: documents.tt_score, - match_played_squash: documents.match_played_squash, - match_played_tennis: documents.match_played_tennis, - match_played_baddy: documents.match_played_baddy, - match_played_tt: documents.match_played_tt, - match_won_squash: documents.match_won_squash, - match_won_tennis: documents.match_won_tennis, - match_won_baddy: documents.match_won_baddy, - match_won_tt: documents.match_won_tt - }; - res.status(200).json(player); - }); -}); - -// Update Profile -app.post('/api/profile/update', (req, res, next) => { - Player.updateOne({_id: req.body.id}, {'name': req.body.name, 'hostel': req.body.hostel, 'gender': req.body.gender, 'preferred': req.body.preferred, 'contact': req.body.contact} ) - .then((result) => { - res.status(200).json(result); - }); -}); - -module.exports = app; diff --git a/backend/check_auth.js b/backend/check_auth.js deleted file mode 100755 index cd82c9a..0000000 --- a/backend/check_auth.js +++ /dev/null @@ -1,11 +0,0 @@ -const jwt = require("jsonwebtoken"); - -module.exports = (req, res, next) => { - try { - const token = req.headers.authorization.split(" ")[1]; - jwt.verify(token, process.env.JWT_KEY); - next(); - } catch (error) { - res.status(401).json({ message: "Auth failed!" }); - } -}; diff --git a/backend/models/match.js b/backend/models/match.js deleted file mode 100755 index a77981b..0000000 --- a/backend/models/match.js +++ /dev/null @@ -1,84 +0,0 @@ -const mongoose = require('mongoose'); - -const matchSchema = mongoose.Schema({ - p1_id: { - type: String, - required: true - }, - p1_name: { - type: String, - required: true - }, - p2_id: { - type: String, - required: true - }, - p2_name: { - type: String, - required: true - }, - sport: { - type: String, - required: true - }, - message: { - type: String, - required: true - }, - date: { - type: String, - required: true - }, - time: { - type: String, - required: true - }, - set_score: { - type: String - }, - match_score: { - type: String - }, - winner_1: { - type: Boolean, - required: true, - default: false - }, - winner_2: { - type: Boolean, - required: true, - default: false - }, - confirm_1: { - type: Boolean, - required: true, - default: false - }, - confirm_2: { - type: Boolean, - required: true, - default: false - }, - report_secy: { - type: Boolean, - required: true, - default: false - }, - rejected: { - type: Boolean, - required: true, - default: false - }, - accepted: { - type: Boolean, - required: true, - default: false - }, - ok: { - type: Boolean, - required: true, - default: false - } -}); - -module.exports = mongoose.model('Match', matchSchema); diff --git a/backend/models/player.js b/backend/models/player.js deleted file mode 100755 index 2077157..0000000 --- a/backend/models/player.js +++ /dev/null @@ -1,102 +0,0 @@ -const mongoose = require('mongoose'); -const uniqueValidator = require('mongoose-unique-validator'); - -const playerSchema = mongoose.Schema({ - name: { - type: String, - required: true - }, - roll: { - type: String, - required: true, - unique: true - }, - hostel: { - type: String, - required: true - }, - gender: { - type: String, - required: true - }, - category: { - type: String, - required: true - }, - preferred: { - type: String, - required: true - }, - contact: { - type: Number, - required: true - }, - password: { - type: String, - required: true - }, - squash_score: { - type: Number, - required: true, - default: 100 - }, - tennis_score: { - type: Number, - required: true, - default: 100 - }, - baddy_score: { - type: Number, - required: true, - default: 100 - }, - tt_score: { - type: Number, - required: true, - default: 100 - }, - match_played_squash: { - type: Number, - required: true, - default: 0 - }, - match_won_squash: { - type: Number, - required: true, - default: 0 - }, - match_played_baddy: { - type: Number, - required: true, - default: 0 - }, - match_won_baddy: { - type: Number, - required: true, - default: 0 - }, - match_played_tennis: { - type: Number, - required: true, - default: 0 - }, - match_won_tennis: { - type: Number, - required: true, - default: 0 - }, - match_played_tt: { - type: Number, - required: true, - default: 0 - }, - match_won_tt: { - type: Number, - required: true, - default: 0 - } -}); - -playerSchema.plugin(uniqueValidator); - -module.exports = mongoose.model('Player', playerSchema); diff --git a/backend/package.json b/backend/package.json deleted file mode 100755 index 171e09f..0000000 --- a/backend/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "ladder-ranking", - "version": "0.0.0", - "private": true, - "dependencies": { - "bcryptjs": "^2.4.3", - "express": "^4.17.1", - "hammerjs": "^2.0.8", - "jsonwebtoken": "^8.5.1", - "lodash": "^4.17.15", - "mongoose": "^5.6.9", - "mongoose-unique-validator": "^2.0.3", - "rxjs": "~6.4.0", - "tslib": "^1.9.0", - "zone.js": "~0.9.1" - } -} diff --git a/backend/server.js b/backend/server.js deleted file mode 100755 index 2e3e027..0000000 --- a/backend/server.js +++ /dev/null @@ -1,52 +0,0 @@ -const app = require("./app"); -const debug = require("debug")("node-angular"); -const http = require("http"); - -const normalizePort = val => { - var port = parseInt(val, 10); - - if (isNaN(port)) { - // named pipe - return val; - } - - if (port >= 0) { - // port number - return port; - } - - return false; -}; - -const onError = error => { - if (error.syscall !== "listen") { - throw error; - } - const bind = typeof port === "string" ? "pipe " + port : "port " + port; - switch (error.code) { - case "EACCES": - console.error(bind + " requires elevated privileges"); - process.exit(1); - break; - case "EADDRINUSE": - console.error(bind + " is already in use"); - process.exit(1); - break; - default: - throw error; - } -}; - -const onListening = () => { - const addr = server.address(); - const bind = typeof port === "string" ? "pipe " + port : "port " + port; - debug("Listening on " + bind); -}; - -const port = normalizePort(process.env.PORT || "3000"); -app.set("port", port); - -const server = http.createServer(app); -server.on("error", onError); -server.on("listening", onListening); -server.listen(port); diff --git a/backend/site.js b/backend/site.js deleted file mode 100644 index 28fe2cd..0000000 --- a/backend/site.js +++ /dev/null @@ -1,25 +0,0 @@ -"use strict"; -const express = require("express"); - -const _port = 4100; -const _app_folder = "dist/ladder-ranking"; - -const app = express(); - -// ---- SERVE STATIC FILES ---- // -app.get("*.*", express.static(_app_folder, { maxAge: "1y" })); - -// ---- SERVE APLICATION PATHS ---- // -app.all("*", function(req, res) { - res.status(200).sendFile(`/`, { root: _app_folder }); -}); - -// ---- START UP THE NODE SERVER ---- -app.listen(_port, function() { - console.log( - "Node Express server for " + - app.name + - " listening on http://localhost:" + - _port - ); -}); diff --git a/src/app/app.service.ts b/src/app/app.service.ts index fed678c..5d92145 100644 --- a/src/app/app.service.ts +++ b/src/app/app.service.ts @@ -69,26 +69,17 @@ export class LadderService { // Notifications getNumber(id: string) { - const myId = { id }; - this.http.post(BackendURLNotifications + 'challenges/', myId) + this.http.get(BackendURLNotifications + 'challenges/' + id) .subscribe((notification) => { this.challengesN = Number(notification[0]); this.challengesP = Number(notification[1]); this.challengesC = Number(notification[2]); // tslint:disable: triple-equals - if (this.challengesN > this.challengesNOld && this.challengesNOld != undefined) { - this.myNotifi('New Challenge', 'You got a new challenge!', '/challenges'); - } this.challengesUpdatesN.next(this.challengesN); - this.challengesNOld = this.challengesN; this.challengesUpdatesP.next(this.challengesP); - if (this.challengesC > this.challengesCOld && this.challengesCOld != undefined) { - this.myNotifi('Confirm Result', 'You got a new confirmation!', '/confirmation/confirm'); - } this.challengesUpdatesC.next(this.challengesC); - this.challengesCOld = this.challengesC; }); } @@ -343,25 +334,4 @@ export class LadderService { this.snackBar.open(message, action, { duration: 2000 }); } -// Notifications Bitches!!! - myNotifi(title: string, body: string, link: string) { - const options = new PushNotificationOptions(); - options.body = body; - - this.notifications.create(title, options).subscribe((notif) => { - if (notif.event.type === 'show') { - setTimeout(() => { - notif.notification.close(); - }, 10000); - } - if (notif.event.type === 'click') { - this.router.navigate([link]); - notif.notification.close(); - } - }, - (err) => { - console.log(err); - }); - } - } diff --git a/src/app/auth/auth.service.ts b/src/app/auth/auth.service.ts index 327450e..0a62294 100644 --- a/src/app/auth/auth.service.ts +++ b/src/app/auth/auth.service.ts @@ -71,7 +71,6 @@ export class AuthService { this.saveAuthData(token); this.openSnackBar('Successfully logged in!', 'OK'); this.router.navigate(['/']); - this.ladderService.getNumber(response.id); } }, error => { this.authStatusListener.next(false);