notherbase-fs 1.2.13 → 1.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/inventory.js +58 -55
- package/controllers/pages.js +0 -1
- package/controllers/the-front.js +1 -1
- package/package.json +1 -1
- package/test/test-index.js +3 -1
- package/test/views/index.ejs +6 -0
- package/views/head.ejs +0 -1
- package/views/inventory.ejs +8 -3
package/controllers/inventory.js
CHANGED
|
@@ -29,73 +29,76 @@ router.get("/", async function(req, res) {
|
|
|
29
29
|
router.post("/", async function(req, res) {
|
|
30
30
|
if (connectionSuccess) {
|
|
31
31
|
try {
|
|
32
|
-
if (req.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let holding = false;
|
|
36
|
-
|
|
37
|
-
for (let j = 0; j < foundInventory.items.length; j++) {
|
|
38
|
-
if (foundInventory.items[j].item._id.equals(req.body.change.item)) {
|
|
39
|
-
holding = true;
|
|
40
|
-
|
|
41
|
-
if (foundInventory.items[j].amount >= -Math.floor(req.body.change.amount)) {
|
|
42
|
-
foundInventory.items[j].amount += Math.floor(req.body.change.amount);
|
|
43
|
-
|
|
44
|
-
if (foundInventory.items[j].amount === 0) {
|
|
45
|
-
let itemToEmpty = foundInventory.items[j].item._id;
|
|
46
|
-
|
|
47
|
-
foundInventory.items.splice(j, 1);
|
|
48
|
-
await foundInventory.save();
|
|
32
|
+
if (req.body.item && req.body.amount) {
|
|
33
|
+
if (req.session.currentUser) {
|
|
34
|
+
let foundInventory = await inventory.findOne({user: req.session.currentUser}).populate("items.item");
|
|
49
35
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
let holding = false;
|
|
37
|
+
|
|
38
|
+
for (let j = 0; j < foundInventory.items.length; j++) {
|
|
39
|
+
if (foundInventory.items[j].item._id.equals(req.body.item)) {
|
|
40
|
+
holding = true;
|
|
41
|
+
|
|
42
|
+
if (foundInventory.items[j].amount >= -Math.floor(req.body.amount)) {
|
|
43
|
+
foundInventory.items[j].amount += Math.floor(req.body.amount);
|
|
44
|
+
|
|
45
|
+
if (foundInventory.items[j].amount === 0) {
|
|
46
|
+
let itemToEmpty = foundInventory.items[j].item._id;
|
|
47
|
+
|
|
48
|
+
foundInventory.items.splice(j, 1);
|
|
49
|
+
await foundInventory.save();
|
|
50
|
+
|
|
51
|
+
res.status(200).send({
|
|
52
|
+
item: itemToEmpty,
|
|
53
|
+
amount: 0
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
await foundInventory.save();
|
|
58
|
+
|
|
59
|
+
res.status(200).send(foundInventory.items[j]);
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
else {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
console.log("subtract from too few", req.change);
|
|
64
|
+
res.status(304).send(
|
|
65
|
+
`Unable to remove ${req.body.amount} ${req.body.item}
|
|
66
|
+
from inventory because the inventory has only ${foundInventory.items[j].amount}.`
|
|
67
|
+
);
|
|
61
68
|
}
|
|
69
|
+
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!holding) {
|
|
75
|
+
if (req.body.amount > 0) {
|
|
76
|
+
foundInventory.items.push({
|
|
77
|
+
item: req.body.item,
|
|
78
|
+
amount: req.body.amount
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await foundInventory.save();
|
|
82
|
+
|
|
83
|
+
await inventory.populate(foundInventory, "items.item");
|
|
84
|
+
|
|
85
|
+
res.status(200).send(foundInventory.items[foundInventory.items.length - 1]);
|
|
62
86
|
}
|
|
63
87
|
else {
|
|
64
|
-
console.log("subtract from
|
|
88
|
+
console.log("subtract from none", req.body);
|
|
65
89
|
res.status(304).send(
|
|
66
|
-
`Unable to remove ${req.body.
|
|
67
|
-
from inventory because the inventory has
|
|
90
|
+
`Unable to remove ${req.body.amount} ${req.body.item}
|
|
91
|
+
from inventory because the inventory has none.`
|
|
68
92
|
);
|
|
69
93
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
res.status(401).send("User not logged in!");
|
|
73
98
|
}
|
|
74
|
-
|
|
75
|
-
if (!holding) {
|
|
76
|
-
if (req.body.change.amount > 0) {
|
|
77
|
-
foundInventory.items.push({
|
|
78
|
-
item: req.body.change.item,
|
|
79
|
-
amount: req.body.change.amount
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
await foundInventory.save();
|
|
83
|
-
|
|
84
|
-
await inventory.populate(foundInventory, "items.item");
|
|
85
|
-
|
|
86
|
-
res.status(200).send(foundInventory.items[foundInventory.items.length - 1]);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
console.log("subtract from none", req.body.change);
|
|
90
|
-
res.status(304).send(
|
|
91
|
-
`Unable to remove ${req.body.change.amount} ${req.body.change.item}
|
|
92
|
-
from inventory because the inventory has none.`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
99
|
}
|
|
97
100
|
else {
|
|
98
|
-
res.status(
|
|
101
|
+
res.status(400).send("Check input!");
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
catch(err) {
|
package/controllers/pages.js
CHANGED
package/controllers/the-front.js
CHANGED
package/package.json
CHANGED
package/test/test-index.js
CHANGED
package/test/views/index.ejs
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Welcome to The Front.
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
+
<button onclick="addGold()">Gold</button>
|
|
6
|
+
|
|
5
7
|
<hr>
|
|
6
8
|
|
|
7
9
|
<h3>Register Account</h3>
|
|
@@ -144,4 +146,8 @@
|
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
});
|
|
149
|
+
|
|
150
|
+
let addGold = function addGold(params) {
|
|
151
|
+
playerInventory.change(itemIDs[0], 2);
|
|
152
|
+
}
|
|
147
153
|
</script>
|
package/views/head.ejs
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
<title><%= siteTitle %></title>
|
|
6
6
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
7
7
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
|
8
|
-
|
|
9
8
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
10
9
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
11
10
|
<!-- 'Roboto Condensed', sans-serif; -->
|
package/views/inventory.ejs
CHANGED
|
@@ -38,8 +38,13 @@
|
|
|
38
38
|
setInterval(this.update, this.updateCooldown);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
async change(
|
|
42
|
-
|
|
41
|
+
async change(itemID, amount) {
|
|
42
|
+
let change = {
|
|
43
|
+
item: itemID,
|
|
44
|
+
amount: amount
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await $.post("/inventory", change, (data, status) => {
|
|
43
48
|
if (status === "success") {
|
|
44
49
|
let holding = false;
|
|
45
50
|
|
|
@@ -52,7 +57,7 @@
|
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
if (!holding && data.amount > 0) {
|
|
60
|
+
if (!holding && data.amount > 0 && data.item) {
|
|
56
61
|
this.items.push(data);
|
|
57
62
|
}
|
|
58
63
|
|