corebasic 1.0.125 → 1.0.127
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/libs/elabase.js +17 -1
- package/package.json +1 -1
package/libs/elabase.js
CHANGED
|
@@ -91,6 +91,7 @@ export const insert = async (meta, collection, value, _id) => {
|
|
|
91
91
|
if (typeof value === "object" && !Array.isArray(value))
|
|
92
92
|
value.company = meta.company
|
|
93
93
|
}
|
|
94
|
+
value.outlet = value.outlet ?? meta.outlet
|
|
94
95
|
// ---------------------
|
|
95
96
|
|
|
96
97
|
var arg = {
|
|
@@ -102,6 +103,12 @@ export const insert = async (meta, collection, value, _id) => {
|
|
|
102
103
|
if (_id)
|
|
103
104
|
arg._id = _id
|
|
104
105
|
|
|
106
|
+
if (!(["string", "number"].includes(typeof value?._id)))
|
|
107
|
+
throw {message: "Error: invalid _id in Dip.insert()"}
|
|
108
|
+
if (typeof value?._id === "string" && value._id.trim().length === 0)
|
|
109
|
+
throw {message: "Error: invalid _id in Dip.insert()"}
|
|
110
|
+
|
|
111
|
+
|
|
105
112
|
if (isTransaction) {
|
|
106
113
|
transactions.push(arg)
|
|
107
114
|
return
|
|
@@ -166,8 +173,17 @@ export const update = async (meta, collection, query, update, options) => {
|
|
|
166
173
|
query.company = meta.company
|
|
167
174
|
update.$set = update.$set ?? {}
|
|
168
175
|
update.$set.company = meta.company
|
|
169
|
-
if (
|
|
176
|
+
if (options?.upsert) {
|
|
177
|
+
update.$setOnInsert = update.$setOnInsert ?? {}
|
|
170
178
|
update.$setOnInsert.company = meta.company
|
|
179
|
+
update.$setOnInsert.outlet = update.$setOnInsert.outlet ?? update.$set?.outlet ?? meta.outlet
|
|
180
|
+
|
|
181
|
+
let _id = update.$setOnInsert._id ?? update.$set?._id ?? query?._id
|
|
182
|
+
if (!(["string", "number"].includes(typeof _id)))
|
|
183
|
+
throw {message: "Error: invalid _id in Dip.update() with upsert"}
|
|
184
|
+
if (typeof _id === "string" && _id.trim().length === 0)
|
|
185
|
+
throw {message: "Error: invalid _id in Dip.update() with upsert"}
|
|
186
|
+
}
|
|
171
187
|
}
|
|
172
188
|
// ---------------------
|
|
173
189
|
|