imports/vx/client/code/vxapp.js
/**
     * Replace any number of properties in a specified row.
     *
     * @param {object} collection MongoDB collection to update.
     * @param {object} record Record to be updated.
     * @param {string} rowsPath JSON path to array of rows to be updated.
     * @param {string} rowId Name of a property that uniquely identifies row.
     * @param {string} id Unique ID of this row (typically GUID).
     * @param {object} row Row with new data (will be merged with existing data).
     */
Replace any number of properties in a specified row.
@param {object} collection MongoDB collection to update.
@param {object} record Record to be updated.
@param {string} rowsPath JSON path to array of rows to be updated.
@param {string} rowId Name of a property that uniquely identifies row.
@param {string} id Unique ID of this row (typically GUID).
@param {object} row Row with new data (will be merged with existing data).
Replace any number of properties in a specified row . @param { object } collection MongoDB collection to update . @param { object } record Record to be updated . @param { string } rowsPath JSON path to array of rows to be updated . @param { string } rowId Name of a property that uniquely identifies row . @param { string } id Unique ID of this row ( typically GUID ) . @param { object } row Row with new data ( will be merged with existing data ) .
replaceRow(collection, record, rowsPath, rowId, id, row) {
        try {
            const rows = get(record, rowsPath)
            const selector = {}
            selector[rowId] = id
            const existingRow = _.findWhere(rows, selector)
            if (!existingRow) {
                OLog.error(`vxapp.js replaceRow replacement recordId=${record._id} rowsPath=${rowsPath} ` +
                `rowId=${rowId} id=${id} row could not be found no update will occur`)
                return
            }
            const replacementRow = { ...existingRow, ...row }
            const mongoPath = Util.toMongoPath(rowsPath)
            const index = Util.indexOf(rows, rowId, id)
            if (index < 0) {
                OLog.error(`vxapp.js replaceRow replacement recordId=${record._id} rowsPath=${rowsPath} ` +
                `rowId=${rowId} id=${id} unable to derive index of row no update will occur`)
                return
            }
            const modifier = {}
            modifier.$set = {}
            modifier.$set[`${mongoPath}.${index}`] = replacementRow
            OLog.debug(`vxapp.js replaceRow recordId=${record._id} rowsPath=${rowsPath} ` +
                `rowId=${rowId} id=${id} mongoPath=${mongoPath} modifier=${OLog.debugString(modifier)}`)
            collection.update(record._id, modifier)
            OLog.debug(`vxapp.js replaceRow recordId=${record._id} *success*`)
        }
        catch (error) {
            UX.notifyForError(error)
        }
    }
replaceRow ( collection , record , rowsPath , rowId , id , row ) { try { const rows = get ( record , rowsPath ) const selector = { } selector [ rowId ] = id const existingRow = _ . findWhere ( rows , selector ) if ( ! existingRow ) { OLog . error ( ` ${ record . _id } ${ rowsPath } ` + ` ${ rowId } ${ id } ` ) return } const replacementRow = { ... existingRow , ... row } const mongoPath = Util . toMongoPath ( rowsPath ) const index = Util . indexOf ( rows , rowId , id ) if ( index < 0 ) { OLog . error ( ` ${ record . _id } ${ rowsPath } ` + ` ${ rowId } ${ id } ` ) return } const modifier = { } modifier . $set = { } modifier . $set [ ` ${ mongoPath } ${ index } ` ] = replacementRow OLog . debug ( ` ${ record . _id } ${ rowsPath } ` + ` ${ rowId } ${ id } ${ mongoPath } ${ OLog . debugString ( modifier ) } ` ) collection . update ( record . _id , modifier ) OLog . debug ( ` ${ record . _id } ` ) } catch ( error ) { UX . notifyForError ( error ) } }
Replace any number of properties in a specified row.
Replace any number of properties in a specified row .