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.
- package/controllers/creation.js +1 -1
- package/models/spirit.js +20 -2
- package/models/user.js +6 -4
- package/package.json +1 -1
package/controllers/creation.js
CHANGED
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
|
|
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.
|
|
23
|
+
query = Spirit.buildBackupQuery("user", null, null, id);
|
|
24
24
|
}
|
|
25
25
|
else if (username) {
|
|
26
|
-
query = Spirit.
|
|
26
|
+
query = Spirit.buildBackupQuery("user", { username: username });
|
|
27
27
|
}
|
|
28
28
|
else if (email) {
|
|
29
|
-
query = Spirit.
|
|
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.
|
|
39
|
+
user.context = found.data.backups[0].data;
|
|
40
|
+
user.email = user.context.email;
|
|
39
41
|
|
|
40
42
|
return user;
|
|
41
43
|
}
|