Skip to content

Commit

Permalink
update player route
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Feb 6, 2020
1 parent 491872d commit 261e15e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Database {
this.$players = db.collection('player');
this.$guilds = db.collection('guild');

this.$inventory = db.collection('inventory');
this.$collectibles = db.collection('collectibles');
this.$achievements = db.collection('achievements');

resolve();

} catch(e) {
Expand Down
33 changes: 31 additions & 2 deletions src/routes/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,39 @@ exports.route = (app) => {

const player = await DB.$players
.findOne(
{ name: req.query.name },
{ fields: { name: 1, profession: 1, 'level.__current': 1, 'level.maximum': 1, ascensionLevel: 1, map: 1 } }
{ name: req.query.name, banned: { $ne: true } },
{ fields: {
name: 1,
title: 1,
profession: 1,
'level.__current': 1,
'level.maximum': 1,
ascensionLevel: 1,
map: 1,
createdAt: 1,
gender: 1,
xp: 1,
gold: 1,
loggedIn: 1,
stats: 1
}
}
);

if(!player) return res.json(null);

const [inventory, collectibles, statistics, achievements] = await Promise.all([
DB.$inventory.findOne({ owner: req.query.name }),
DB.$collectibles.findOne({ owner: req.query.name }),
DB.$statistics.findOne({ owner: req.query.name }),
DB.$achievements.findOne({ owner: req.query.name })
]);

player.inventory = inventory;
player.collectibles = collectibles;
player.statistics = statistics;
player.achievements = achievements;

res.json(player);

});
Expand Down

0 comments on commit 261e15e

Please sign in to comment.