notherbase-fs 4.4.1 → 4.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.
@@ -186,7 +186,32 @@ export default class SpiritWorld {
186
186
  spirit = await req.db.Spirit.create(req.body.service, spiritData, parent);
187
187
  }
188
188
 
189
- res.send("spirit saved");
189
+ res.send(spirit.memory._id);
190
+ } catch (error) {
191
+ console.log(error);
192
+ fail(res, "Server error");
193
+ }
194
+ }
195
+
196
+ delete = async (req, res) => {
197
+ try {
198
+ let parent = null;
199
+ let data = req.body.data ? req.body.data : {};
200
+ let id = req.body.id ? req.body.id : null;
201
+
202
+ // if the scope is local, the parent is the user's id
203
+ if (req.body.scope === "local") {
204
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
205
+ if (user?.memory?._id) parent = user.memory._id;
206
+ else {
207
+ fail(res, "User had no id on load()");
208
+ return;
209
+ }
210
+ }
211
+
212
+ // delete the spirits
213
+ let deleted = await req.db.Spirit.delete(req.body.service, parent, data, id);
214
+ res.send(deleted);
190
215
  } catch (error) {
191
216
  console.log(error);
192
217
  fail(res, "Server error");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "4.4.1",
3
+ "version": "4.4.3",
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.