all files / app/engine/ conversationService.js

93.75% Statements 15/16
83.33% Branches 5/6
100% Functions 3/3
93.75% Lines 15/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31       467× 467× 122×   345× 345× 128×   345×         345× 345×     345× 345×   345×        
var path = require('path')
var AgentConversation = require(path.resolve('node_modules', 'mongoose')).model('AgentConversation')
 
var ConversationService = module.exports = {
  restoreAgentConversation: function (meta, agentQName, cb) {
    // var key = meta.agentDataId
    var ac = meta[ agentQName + ':' + meta.agentDataId + ':agentConversation' ]
    if (ac) {
      cb(null, ac, meta)
    } else {
      ConversationService.getAgentConversation(meta, agentQName, function (err, agentConversation) {
        if (agentConversation) {
          meta[ agentQName + ':' + agentConversation.agentDataId + ':agentConversation' ] = agentConversation
        }
        cb(err, agentConversation, meta)
      })
    }
  },
  getAgentConversation: function (meta, agentName, success) {
    var query = { agent: agentName }
    Iif (meta.conversationId != null) {
      query.conversationId = meta.conversationId
    } else {
      query.agentDataId = meta.agentDataId
      query.disposition = '1'
    }
    AgentConversation.findOne(query).exec(success)
  }
 
}