notherbase-fs 3.3.4 → 3.3.6

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.
@@ -70,7 +70,7 @@ export default class Creation {
70
70
  let user = await req.db.User.recallOne(req.session.currentUser);
71
71
  if (user) {
72
72
  context.userID = user.id;
73
- context.user = user.memory.data;
73
+ context.user = user.context;
74
74
  };
75
75
 
76
76
  res.render(req.toRender, context);
package/models/spirit.js CHANGED
@@ -41,6 +41,24 @@ export default class Spirit {
41
41
  return query;
42
42
  }
43
43
 
44
+ static buildBackupQuery = (service, data = null, parent = null, id = null) => {
45
+ let query = {
46
+ service: service,
47
+ parent: parent
48
+ };
49
+
50
+ if (id) query._id = id;
51
+ else if (data){
52
+ let keys = Object.keys(data);
53
+ for (let i = 0; i < keys.length; i++) {
54
+
55
+ query[`data.backups.0.data.${keys[i]}`] = data[keys[i]];
56
+ }
57
+ }
58
+
59
+ return query;
60
+ }
61
+
44
62
  /**
45
63
  * Creates a spirit in the database.
46
64
  * @param {String} service The name of the spirit.
@@ -179,11 +197,11 @@ export default class Spirit {
179
197
  * @param {Object} data Data to add to the backup.
180
198
  */
181
199
  addBackup = async (data, max = 5) => {
182
- if (!this.memory.data._backupsEnabled) {
200
+ if (!this.memory.data?._backupsEnabled) {
183
201
  let oldData = this.memory.data;
184
202
  this.memory.data = {
185
203
  _backupsEnabled: true,
186
- backups: [ oldData ]
204
+ backups: [{ _lastUpdate: Date.now(), data: oldData }]
187
205
  };
188
206
  }
189
207
 
package/models/user.js CHANGED
@@ -20,22 +20,24 @@ export default class User extends Spirit {
20
20
  let query = null;
21
21
 
22
22
  if (id) {
23
- query = Spirit.buildQuery("user", null, null, id);
23
+ query = Spirit.buildBackupQuery("user", null, null, id);
24
24
  }
25
25
  else if (username) {
26
- query = Spirit.buildQuery("user", { username: username });
26
+ query = Spirit.buildBackupQuery("user", { username: username });
27
27
  }
28
28
  else if (email) {
29
- query = Spirit.buildQuery("user", { email: email });
29
+ query = Spirit.buildBackupQuery("user", { email: email });
30
30
  }
31
31
  else return null;
32
32
 
33
+ console.log(query);
33
34
  let found = await Spirit.db.findOne(query);
34
35
 
35
36
  if (found) {
36
37
  user.memory = found;
37
38
  user.id = found._id;
38
- user.email = found.data.email;
39
+ user.context = found.data.backups[0].data;
40
+ user.email = user.context.email;
39
41
 
40
42
  return user;
41
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "exports": "./notherbase-fs.js",
6
6
  "scripts": {