notherbase-fs 4.4.2 → 4.4.4

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.
@@ -22,6 +22,7 @@ export default class SpiritWorld {
22
22
  this.router.post("/loadAll", this.loadAll);
23
23
  this.router.post("/load", this.load);
24
24
  this.router.post("/save", this.save);
25
+ this.router.post("/delete", this.delete);
25
26
  this.router.post("/serve", this.serve);
26
27
  this.router.use("/user", this.user.router);
27
28
  }
@@ -193,6 +194,31 @@ export default class SpiritWorld {
193
194
  }
194
195
  }
195
196
 
197
+ delete = async (req, res) => {
198
+ try {
199
+ let parent = null;
200
+ let data = req.body.data ? req.body.data : {};
201
+ let id = req.body.id ? req.body.id : null;
202
+
203
+ // if the scope is local, the parent is the user's id
204
+ if (req.body.scope === "local") {
205
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
206
+ if (user?.memory?._id) parent = user.memory._id;
207
+ else {
208
+ fail(res, "User had no id on load()");
209
+ return;
210
+ }
211
+ }
212
+
213
+ // delete the spirits
214
+ let deleted = await req.db.Spirit.delete(req.body.service, parent, data, id);
215
+ res.send(deleted);
216
+ } catch (error) {
217
+ console.log(error);
218
+ fail(res, "Server error");
219
+ }
220
+ }
221
+
196
222
  /**
197
223
  * This API route runs a script on the server. Responds with the result.
198
224
  * @param {Object} req
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "4.4.2",
3
+ "version": "4.4.4",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "exports": "./notherbase-fs.js",
6
6
  "scripts": {
package/public/js/base.js CHANGED
@@ -141,6 +141,19 @@ class Base {
141
141
  return response;
142
142
  }
143
143
 
144
+ /**
145
+ * Deletes a spirit of a certain service.
146
+ * @param {String} service The name of the spirit to delete.
147
+ * @param {String} scope Defaults to local, else global.
148
+ * @param {Object} data Data to filter the spirits by.
149
+ * @param {ObjectID} id The id of the spirit to delete.
150
+ * @returns Spirit world response.
151
+ */
152
+ delete = async (service, scope = "local", data = {}, id = null) => {
153
+ let response = await $.post("/s/delete", JSON.stringify({ service, scope, data, id }));
154
+ return response;
155
+ }
156
+
144
157
  /**
145
158
  * Appends html to the head.
146
159
  * @param {String} html The html to append.