imports/vx/server/code/vxapp.js
/**
     * Handle an update of an existing record, updating the Transactions collection as needed.
     *
     * @param {object} collection Collection.
     * @param {string} userId User ID who is inserting the record.
     * @param {object} doc Document after insert.
     * @param {object} fieldNames Field names that were updated.
     * @param {object} modifier Modifier used to perform update.
     * @param {object} options Options used to perform update.
     * @param {object} previous Document before update.
     */
Handle an update of an existing record, updating the Transactions collection as needed.
@param {object} collection Collection.
@param {string} userId User ID who is inserting the record.
@param {object} doc Document after insert.
@param {object} fieldNames Field names that were updated.
@param {object} modifier Modifier used to perform update.
@param {object} options Options used to perform update.
@param {object} previous Document before update.
Handle an update of an existing record updating the Transactions collection as needed . @param { object } collection Collection . @param { string } userId User ID who is inserting the record . @param { object } doc Document after insert . @param { object } fieldNames Field names that were updated . @param { object } modifier Modifier used to perform update . @param { object } options Options used to perform update . @param { object } previous Document before update .
handleUpdate(collection, userId, doc, fieldNames, modifier, options, previous) {
        if (!userId) {
            return
        }
        try {
            let transactions = VXApp.findTransactions(collection, userId, doc)
            if (!transactions) {
                transactions = VXApp.makeTransactions(collection, Util.getCurrentDomainId(userId), userId, previous)
            }
            const undoStackSize = Util.getConfigValue("undoStackSize") || 100
            const selector = VXApp.makeTransactionsSelector(collection, userId, doc)
            if (transactions.history.length >= undoStackSize) {
                OLog.debug(`vxapp.js handleUpdate ${collection._name} domain=${selector.domain} userId=${userId} stack at maximum undoStackSize=${undoStackSize} index=${transactions.index} length=${transactions.history.length} *shift*`)
                transactions.history.shift()
            }
            else {
                OLog.debug(`vxapp.js handleUpdate ${collection._name} domain=${selector.domain} userId=${userId} stack at still has room undoStackSize=${undoStackSize} index=${transactions.index} length=${transactions.history.length}`)
            }
            transactions.history.push(doc)
            const modifier = {}
            modifier.$set = {}
            modifier.$set.index = transactions.history.length - 1
            modifier.$set.history = transactions.history
            const result = Transactions.update(selector, modifier)
            if (result !== 1) {
                OLog.error(`vxapp.js handleUpdate *fail* result=${result} ${collection._name} domain=${selector.domain} userId=${userId} fieldNames=${OLog.debugString(fieldNames)} selector=${OLog.debugString(selector)} modifier=${OLog.debugString(modifier)}`)
            }
        }
        catch (error) {
            OLog.error(`vxapp.js handleUpdate *fail* ${collection._name} domain=${Util.getCurrentDomainId(userId)} userId=${userId} fieldNames=${OLog.debugString(fieldNames)} error=${error}`)
        }
    }
handleUpdate ( collection , userId , doc , fieldNames , modifier , options , previous ) { if ( ! userId ) { return } try { let transactions = VXApp . findTransactions ( collection , userId , doc ) if ( ! transactions ) { transactions = VXApp . makeTransactions ( collection , Util . getCurrentDomainId ( userId ) , userId , previous ) } const undoStackSize = Util . getConfigValue ( "undoStackSize" ) || 100 const selector = VXApp . makeTransactionsSelector ( collection , userId , doc ) if ( transactions . history . length >= undoStackSize ) { OLog . debug ( ` ${ collection . _name } ${ selector . domain } ${ userId } ${ undoStackSize } ${ transactions . index } ${ transactions . history . length } ` ) transactions . history . shift ( ) } else { OLog . debug ( ` ${ collection . _name } ${ selector . domain } ${ userId } ${ undoStackSize } ${ transactions . index } ${ transactions . history . length } ` ) } transactions . history . push ( doc ) const modifier = { } modifier . $set = { } modifier . $set . index = transactions . history . length - 1 modifier . $set . history = transactions . history const result = Transactions . update ( selector , modifier ) if ( result !== 1 ) { OLog . error ( ` ${ result } ${ collection . _name } ${ selector . domain } ${ userId } ${ OLog . debugString ( fieldNames ) } ${ OLog . debugString ( selector ) } ${ OLog . debugString ( modifier ) } ` ) } } catch ( error ) { OLog . error ( ` ${ collection . _name } ${ Util . getCurrentDomainId ( userId ) } ${ userId } ${ OLog . debugString ( fieldNames ) } ${ error } ` ) } }
Handle an update of an existing record, updating the Transactions collection as needed.
Handle an update of an existing record updating the Transactions collection as needed .
// No userId is supplied when Domains is updated by the system, no undo/redo is necessary.