Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return utils.Promise.all(records.map((record) => {
return this._destroy(mapper, utils.get(record, idAttribute), opts)
}))
})
result[0] = result[0].reduce((sum, record) => sum + (utils.get(record, field) || 0), 0)
return result
records.forEach((record) => {
const id = utils.get(record, idAttribute)
let _props = utils.plainCopy(record)
let itemRef
if (utils.isSorN(id)) {
itemRef = collectionRef.child(id)
} else {
itemRef = collectionRef.push()
utils.set(_props, idAttribute, itemRef.key)
}
refValueCollection.push({ ref: itemRef, props: _props })
})
const tasks = records.map((record) => this._find(mapper, utils.get(record, idAttribute), opts));
return utils.Promise.all(tasks).then((results) => {
_upsert (mapper, props, opts) {
const _props = utils.plainCopy(props)
opts || (opts = {})
const id = utils.get(_props, mapper.idAttribute)
const collectionRef = this.getRef(mapper, opts)
let itemRef
if (utils.isSorN(id)) {
itemRef = collectionRef.child(id)
} else {
itemRef = collectionRef.push()
utils.set(_props, mapper.idAttribute, itemRef.key)
}
return itemRef.set(_props)
.then(() => this._once(itemRef))
.then((record) => {
if (!record) {
throw new Error('Not Found')
let parentId = opts.params[parentKey]
if (parentId === false || !parentKey || !parentDef) {
if (parentId === false) {
delete opts.params[parentKey]
}
return false
} else {
delete opts.params[parentKey]
if (utils.isObject(id)) {
item = id
}
if (item) {
parentId = parentId || def.getForeignKey(item) || (def.getLocalField(item) ? utils.get(def.getLocalField(item), parentDef.idAttribute) : null)
}
if (parentId) {
delete opts.endpoint
const _opts = {}
utils.forOwn(opts, (value, key) => {
_opts[key] = value
})
utils._(_opts, parentDef)
endpoint = makePath(this.getEndpoint(parentDef, parentId, _opts), parentId, endpoint)
return false
}
}
})
records.forEach((record, i) => {
if (!record) {
return;
}
const id = utils.get(record, idAttribute);
if (!utils.isUndefined(id)) {
utils.deepMixIn(record, props[i]);
entities.push({
method: 'update',
key: this.datastore.key([this.getKind(mapper, opts), id]),
data: record
});
_records.push(record);
}
});
if (!_records.length) {