notherbase-fs 3.4.1 → 3.4.3
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/spirit-world.js +34 -1
- package/models/spirit.js +1 -4
- package/package.json +1 -1
- package/public/js/base.js +16 -0
- package/test/the-front/add-gold.js +7 -1
- package/test/the-front/index.ejs +4 -2
|
@@ -20,6 +20,7 @@ export default class SpiritWorld {
|
|
|
20
20
|
this.user = new User();
|
|
21
21
|
|
|
22
22
|
this.router.post("/loadAll", this.loadAll);
|
|
23
|
+
this.router.post("/load", this.load);
|
|
23
24
|
this.router.post("/serve", this.serve);
|
|
24
25
|
this.router.use("/user", this.user.router);
|
|
25
26
|
|
|
@@ -99,7 +100,7 @@ export default class SpiritWorld {
|
|
|
99
100
|
// if the scope is local, the parent is the user's id
|
|
100
101
|
if (req.body.scope === "local") {
|
|
101
102
|
let user = await req.db.Spirit.recallOne("user", null, { email: req.session.currentUser });
|
|
102
|
-
if (user?.
|
|
103
|
+
if (user?.memory?._id) parent = user.memory._id;
|
|
103
104
|
else {
|
|
104
105
|
fail(res, "User had no id on load()");
|
|
105
106
|
return;
|
|
@@ -116,6 +117,38 @@ export default class SpiritWorld {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
/**
|
|
121
|
+
* This API route requests a spirit of a kind from the database.
|
|
122
|
+
* @param {Object} req
|
|
123
|
+
* @param {Object} res
|
|
124
|
+
* @returns {Object} The requested spirit.
|
|
125
|
+
*/
|
|
126
|
+
load = async (req, res) => {
|
|
127
|
+
try {
|
|
128
|
+
let parent = null;
|
|
129
|
+
let data = req.body.data ? req.body.data : {};
|
|
130
|
+
let id = req.body.id ? req.body.id : null;
|
|
131
|
+
|
|
132
|
+
// if the scope is local, the parent is the user's id
|
|
133
|
+
if (req.body.scope === "local") {
|
|
134
|
+
let user = await req.db.Spirit.recallOne("user", null, { email: req.session.currentUser });
|
|
135
|
+
if (user?.memory?._id) parent = user.memory._id;
|
|
136
|
+
else {
|
|
137
|
+
fail(res, "User had no id on load()");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// recall all spirits with the given service name and parent
|
|
143
|
+
let spirit = await req.db.Spirit.recallOne(req.body.service, parent, data, id);
|
|
144
|
+
|
|
145
|
+
res.send(spirit);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.log(error);
|
|
148
|
+
fail(res, "Server error");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
119
152
|
/**
|
|
120
153
|
* This API route runs a script on the server. Responds with the result.
|
|
121
154
|
* @param {Object} req
|
package/models/spirit.js
CHANGED
package/package.json
CHANGED
package/public/js/base.js
CHANGED
|
@@ -114,6 +114,8 @@ class Base {
|
|
|
114
114
|
* Loads all spirits of a certain service.
|
|
115
115
|
* @param {String} service The name of the spirits to load.
|
|
116
116
|
* @param {String} scope Defaults to local, else global.
|
|
117
|
+
* @param {Object} data Data to filter the spirits by.
|
|
118
|
+
* @param {ObjectID} id The id of the spirit to load.
|
|
117
119
|
* @returns Spirit world response.
|
|
118
120
|
*/
|
|
119
121
|
loadAll = async (service, scope = "local", data = {}, id = null) => {
|
|
@@ -122,6 +124,20 @@ class Base {
|
|
|
122
124
|
return response;
|
|
123
125
|
}
|
|
124
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Loads a single spirit of a certain service.
|
|
129
|
+
* @param {String} service The name of the spirit to load.
|
|
130
|
+
* @param {String} scope Defaults to local, else global.
|
|
131
|
+
* @param {Object} data Data to filter the spirits by.
|
|
132
|
+
* @param {ObjectID} id The id of the spirit to load.
|
|
133
|
+
* @returns Spirit world response.
|
|
134
|
+
*/
|
|
135
|
+
load = async (service, scope = "local", data = {}, id = null) => {
|
|
136
|
+
let response = await $.post("/s/load", JSON.stringify({ service, scope, data, id }));
|
|
137
|
+
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
|
|
125
141
|
/**
|
|
126
142
|
* Creates the toggle view button.
|
|
127
143
|
*/
|
|
@@ -2,7 +2,13 @@ export default async (req, user, io) => {
|
|
|
2
2
|
// let deleted = await req.db.Spirit.delete("gold");
|
|
3
3
|
let spirit = await req.db.Spirit.recallOrCreateOne("gold");
|
|
4
4
|
spirit.addBackup({
|
|
5
|
-
amount: spirit.memory?.data?.amount != null ? spirit.memory.data.amount + 1 :
|
|
5
|
+
amount: spirit.memory?.data?.amount != null ? spirit.memory.data.amount + 1 : 1
|
|
6
|
+
});
|
|
7
|
+
await spirit.commit();
|
|
8
|
+
|
|
9
|
+
spirit = await req.db.Spirit.recallOrCreateOne("gold", user.memory._id);
|
|
10
|
+
spirit.addBackup({
|
|
11
|
+
amount: spirit.memory?.data?.amount != null ? spirit.memory.data.amount + 1 : 1
|
|
6
12
|
});
|
|
7
13
|
await spirit.commit();
|
|
8
14
|
}
|
package/test/the-front/index.ejs
CHANGED
|
@@ -57,9 +57,11 @@
|
|
|
57
57
|
this.$info.append(this.newEmail + "<br>");
|
|
58
58
|
this.$info.append(this.newPassword + "<br>");
|
|
59
59
|
|
|
60
|
-
let loaded = await base.
|
|
60
|
+
let loaded = await base.load("gold", "global");
|
|
61
|
+
console.log(loaded);
|
|
62
|
+
this.$gold.text(`?/${loaded?.memory?.data?.amount !== null ? loaded.memory.data.amount : 0} Gold Added`);
|
|
63
|
+
loaded = await base.loadAll("gold");
|
|
61
64
|
console.log(loaded);
|
|
62
|
-
this.$gold.text(`?/${loaded[0]?.memory?.data?.amount !== null ? loaded[0].memory.data.amount : 0} Gold Added`);
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
runTest = async () => {
|