notherbase-fs 3.2.3 → 3.2.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.
- package/models/spirit.js +17 -4
- package/package.json +1 -1
- package/test/the-front/index.ejs +4 -0
- package/test/the-front/load-groups.js +46 -0
package/models/spirit.js
CHANGED
|
@@ -125,12 +125,25 @@ export default class Spirit {
|
|
|
125
125
|
* @param {Object} data Data to save.
|
|
126
126
|
* @returns Updated
|
|
127
127
|
*/
|
|
128
|
-
commit = async (data = this.memory.data) => {
|
|
128
|
+
commit = async (data = this.memory.data, which = -1) => {
|
|
129
129
|
this.memory._lastUpdate = Date.now();
|
|
130
130
|
|
|
131
|
-
this.memory
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
if (!Array.isArray(this.memory)) {
|
|
132
|
+
this.memory.data = data;
|
|
133
|
+
this.memory.markModified("data");
|
|
134
|
+
await this.memory.save();
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
for (let i = 0; i < this.memory.length; i++) {
|
|
138
|
+
if (data) {
|
|
139
|
+
if (which < 0) this.memory[i].data = data;
|
|
140
|
+
else if (which === i) this.memory[i].data = data;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.memory[i].markModified("data");
|
|
144
|
+
await this.memory[i].save();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
134
147
|
|
|
135
148
|
return "Updated";
|
|
136
149
|
}
|
package/package.json
CHANGED
package/test/the-front/index.ejs
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default async function (req, user) {
|
|
2
|
+
let spirit = await req.db.Spirit.recallAll("group");
|
|
3
|
+
|
|
4
|
+
let inGroups = [];
|
|
5
|
+
|
|
6
|
+
for (let i = 0; i < spirit.memory.length; i++) {
|
|
7
|
+
if (!spirit.memory[i].data) spirit.memory.splice(i, 1);
|
|
8
|
+
else {
|
|
9
|
+
if (Array.isArray(spirit.memory[i].data.members)) {
|
|
10
|
+
if (spirit.memory[i].data.members.includes(`${user.id}`)) {
|
|
11
|
+
let groupInfo = {
|
|
12
|
+
id: spirit.memory[i].id,
|
|
13
|
+
...spirit.memory[i].data
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for (let j = 0; j < spirit.memory[i].data.members.length; j++) {
|
|
17
|
+
let user = await req.db.User.recallOne(null, null, spirit.memory[i].data.members[j]);
|
|
18
|
+
groupInfo.members[j] = {
|
|
19
|
+
id: spirit.memory[i].data.members[j],
|
|
20
|
+
name: user.memory.data.username
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (Array.isArray(spirit.memory[i].data.joinRequests)) {
|
|
25
|
+
for (let j = 0; j < spirit.memory[i].data.joinRequests.length; j++) {
|
|
26
|
+
let user = await req.db.User.recallOne(null, null, spirit.memory[i].data.joinRequests[j].id);
|
|
27
|
+
groupInfo.joinRequests[j] = {
|
|
28
|
+
id: spirit.memory[i].data.joinRequests[j].id,
|
|
29
|
+
name: user.memory.data.username,
|
|
30
|
+
note: spirit.memory[i].data.joinRequests[j].note
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else spirit.memory[i].data.joinRequests = [];
|
|
35
|
+
|
|
36
|
+
inGroups.push(groupInfo);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else spirit.memory[i].data.members = [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
spirit.commit();
|
|
44
|
+
|
|
45
|
+
return inGroups;
|
|
46
|
+
}
|