@wxn0brp/db-core 0.2.10 → 0.2.11
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/dist/base/actions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { setDataForToggleOne, setDataForUpdateOneOrAdd } from "../helpers/assignDataPush.js";
|
|
2
2
|
class ActionsBase {
|
|
3
3
|
_inited = true;
|
|
4
4
|
numberId = false;
|
|
@@ -49,19 +49,19 @@ class ActionsBase {
|
|
|
49
49
|
}
|
|
50
50
|
async updateOneOrAdd(config) {
|
|
51
51
|
const res = await this.updateOne(config);
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
52
|
+
if (res)
|
|
53
|
+
return true;
|
|
54
|
+
setDataForUpdateOneOrAdd(config);
|
|
55
|
+
await this.add(config);
|
|
56
|
+
return false;
|
|
57
57
|
}
|
|
58
58
|
async toggleOne(config) {
|
|
59
59
|
const res = await this.removeOne(config);
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return
|
|
60
|
+
if (res)
|
|
61
|
+
return true;
|
|
62
|
+
setDataForToggleOne(config);
|
|
63
|
+
await this.add(config);
|
|
64
|
+
return false;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
export default ActionsBase;
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
export function assignDataPush(data) {
|
|
2
|
+
if (!data)
|
|
3
|
+
return {};
|
|
2
4
|
if (typeof data !== "object" || Array.isArray(data))
|
|
3
|
-
return;
|
|
5
|
+
return {};
|
|
6
|
+
if (Object.keys(data).length === 0)
|
|
7
|
+
return {};
|
|
4
8
|
const obj = {};
|
|
5
9
|
for (const key of Object.keys(data)) {
|
|
6
|
-
if (key.startsWith("$")) {
|
|
7
|
-
Object.keys(data[key]).forEach((k) => {
|
|
8
|
-
obj[k] = data[key][k];
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
else
|
|
10
|
+
if (!key.startsWith("$")) {
|
|
12
11
|
obj[key] = data[key];
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const dk = data[key];
|
|
15
|
+
if (Array.isArray(dk))
|
|
16
|
+
continue;
|
|
17
|
+
Object.keys(dk).forEach((k) => obj[k] = dk[k]);
|
|
13
18
|
}
|
|
14
19
|
return obj;
|
|
15
20
|
}
|
|
16
|
-
export function
|
|
21
|
+
export function setDataForUpdateOneOrAdd(query) {
|
|
17
22
|
query.data = Object.assign({}, assignDataPush(query.search), assignDataPush(query.updater), assignDataPush(query.add_arg));
|
|
18
23
|
}
|
|
19
|
-
export function
|
|
24
|
+
export function setDataForToggleOne(query) {
|
|
20
25
|
query.data = Object.assign({}, assignDataPush(query.search), assignDataPush(query.data));
|
|
21
26
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.2.
|
|
1
|
+
export const version = "0.2.11";
|
package/package.json
CHANGED