dbmodel.AutoAttendant.find({where: [{Name: req.params.name },{ Company: company}, { Tenant: tenant}], include: [{model: dbmodel.Action, as: "Actions"}]}).then(function ( aaData) {




            try {



                var instance = msg.FormatMessage(undefined,"Auto Attendant Found", true,aaData);

                logger.debug("DVP-AutoAttendant.GetAttendantByName PGSQL  found");
                res.write(instance);
                res.end();
            } catch(exp) {

                logger.error("DVP-AutoAttendant.GetAttendantByName stringify json failed",  exp);
                var instance = msg.FormatMessage(exp,"Auto Attendant Error", false,undefined);
                res.write("");
                res.end();

            }






        }).catch(function (err){
                .then(function (inst) {


                    logger.debug('DVP-AutoAttendant.CreateAutoAttendant PGSQL AutoAttendant object saved successful');
                    status = true;

                    try {


                        var instance = msg.FormatMessage(returnerror, "AutoAttendant creation", status, undefined);
                        res.write(instance);
                        res.end();


                    }
                    catch (exp) {

                        logger.error('DVP-AutoAttendant.CreateAutoAttendant Service failed ', exp);
                        var instance = msg.FormatMessage(exp, "AutoAttendant creation", false, undefined);
                        res.write(instance);
                        res.end();


                    }
                }).catch(function (err) {
    database.findOne({_id: engagementId}, function (err, eng) {
        if (!err) {
            if (eng) {
                var ids = eng.siblings;
                ids = ids.map(function (id) {
                    return ObjectID(id);
                });

                database.find({_id: {$in: ids}}).toArray(function (err, anc) {
                    if (!err) {
                        logger.info('getAllAttachments - [%s]', engagementId);
                        jsonString = messageFormatter.FormatMessage(undefined, "EXCEPTION", true, anc);
                        res.end(jsonString);
                    }
                    else {
                        jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
                        res.end(jsonString);
                    }
                });
            }
            else {
                jsonString = messageFormatter.FormatMessage(new Error("No data"), "EXCEPTION", false, undefined);
                res.end(jsonString);
            }


        }
        else {

            logger.error('getAllAttachments - [%s]', engagementId, err);
            jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
            res.end(jsonString);
        }
    });
Beispiel #4
0
server.put('/DVP/API/:version/CallRuleApi/CallRule/:ruleId', authorization({resource:"callrule", action:"write"}), function(req, res, next)
{
    var reqId = uuid.v1();
    try
    {

        var reqBody = req.body;
        var ruleId = req.params.ruleId;
        var companyId = req.user.company;
        var tenantId = req.user.tenant;

        logger.debug('[DVP-RuleService.UpdateRule] - [%s] - HTTP Request Received - Req Body : ', reqId, reqBody);

        if (!companyId || !tenantId)
        {
            throw new Error("Invalid company or tenant");
        }

        if(reqBody)
        {

            ruleBackendHandler.UpdateRule(reqId, ruleId, reqBody, companyId, tenantId, function(err, updateResult)
            {
                if(err || !updateResult)
                {
                    var jsonString = messageFormatter.FormatMessage(err, "Update PBX User Failed", false, false);
                    logger.debug('[DVP-RuleService.UpdateRule] - [%s] - API RESPONSE : %s', reqId, jsonString);
                    res.end(jsonString);
                }
                else
                {
                    var jsonString = messageFormatter.FormatMessage(err, "Update PBX User Success", true, updateResult);
                    logger.debug('[DVP-RuleService.UpdateRule] - [%s] - API RESPONSE : %s', reqId, jsonString);
                    res.end(jsonString);
                }

            })
        }
        else
        {
            var jsonString = messageFormatter.FormatMessage(new Error('Empty request body'), "Empty request body", false, false);
            logger.debug('[DVP-RuleService.UpdateRule] - [%s] - API RESPONSE : %s', reqId, jsonString);
            res.end(jsonString);

        }


    }
    catch(ex)
    {
        logger.error('[DVP-RuleService.UpdateRule] - [%s] - Exception Occurred', reqId, ex);
        var jsonString = messageFormatter.FormatMessage(ex, "Exception occurred", false, false);
        logger.debug('[DVP-RuleService.UpdateRule] - [%s] - API RESPONSE : %s', reqId, jsonString);
        res.end(jsonString);

    }

    return next();

});
                    Ticket.findOne({company: ardsResponse.Company, tenant: ardsResponse.Tenant, _id: ardsResponse.SessionID}, function (err, ticket) {
                        if (err) {
                            jsonString = messageFormatter.FormatMessage(err, "Fail Find Ticket", false, undefined);
                            res.writeHead(503, {'Content-Type': 'application/json; charset=utf-8'});
                            res.end(jsonString);
                        }
                        else {
                            if (ticket) {

                                var oldTicket = deepcopy(ticket.toJSON());
                                var time = Date.now();
                                ticket.updated_at = time;
                                var tEvent = TicketEvent({
                                    type: 'status',
                                    body: {
                                        "message" :  "ARDS Ticket Assign To "+user.id,
                                        "time" : time
                                    }
                                });
                                ticket.events.push(tEvent);

                                ticket.assignee_group = undefined;
                                ticket.assignee = user.id ;

                                ticket.update(ticket, function (err, obj) {
                                    if (err) {
                                        jsonString = messageFormatter.FormatMessage(err, "Fail Find Ticket", false, undefined);
                                        res.writeHead(503, {'Content-Type': 'application/json; charset=utf-8'});
                                        res.end(jsonString);
                                    }
                                    if(obj){
                                        jsonString = messageFormatter.FormatMessage(undefined, "Ticket Assign To User.", true, undefined);
                                        res.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'});
                                        res.end(jsonString);
                                        RemoveRequest(ardsResponse.Tenant, ardsResponse.Company,ardsResponse.SessionID, "NONE", function(){

                                        });
                                        TriggerWorker.ExecuteTrigger(ticket.id, "change_assignee", oldTicket.assignee);
                                    }
                                    else{
                                        jsonString = messageFormatter.FormatMessage(undefined, "Invalid Ticket Information.", false, undefined);
                                        res.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'});
                                        res.end(jsonString);
                                        RejectRequest(ardsResponse.Tenant, ardsResponse.Company,ardsResponse.SessionID, "NoSession", function(){

                                        });
                                    }
                                });

                            } else {
                                jsonString = messageFormatter.FormatMessage(undefined, "Fail Find Ticket", false, undefined);
                                res.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'});
                                res.end(jsonString);
                                RejectRequest(ardsResponse.Tenant, ardsResponse.Company,ardsResponse.SessionID, "NoSession", function(){

                                });
                            }
                        }
                    });
 PackageUnit.find({type: req.params.type, active: true}, function(err, codecObj) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Get Codec By Type Failed", false, undefined);
     }else{
         jsonString = messageFormatter.FormatMessage(err, "Get Codec By Type Successful", true, codecObj);
     }
     res.end(jsonString);
 });
Beispiel #7
0
 Email.findOneAndUpdate({ _id: req.params.id, company: company, tenant: tenant }, email, function (err, twitter) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Update Email account failed", false, undefined);
     } else {
         jsonString = messageFormatter.FormatMessage(undefined, "Update Email account Success", true, twitter);
     }
     res.end(jsonString);
 });
 VPackage.find({}, function(err, vPackages) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Get Packages Failed", false, undefined);
     }else{
         jsonString = messageFormatter.FormatMessage(err, "Get Packages Successful", true, vPackages);
     }
     res.end(jsonString);
 });
 unit.save(function (err, packageUnit) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Package Unit save failed", false, undefined);
     } else {
         jsonString = messageFormatter.FormatMessage(undefined, "Package Unit saved successfully", true, packageUnit);
     }
     res.end(jsonString);
 });
 packageUnit.remove(function (err) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Delete Package Unit Failed", false, undefined);
     } else {
         jsonString = messageFormatter.FormatMessage(undefined, "Package Unit successfully deleted", true, undefined);
     }
     res.end(jsonString);
 });
 VPackage.findOne({packageName: req.params.packageName}, function(err, vPackage) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Get Package Failed", false, undefined);
     }else{
         jsonString = messageFormatter.FormatMessage(err, "Get Package Successful", true, vPackage);
     }
     res.end(jsonString);
 });
 PackageUnit.findOne({unitName: req.params.unitName}, function(err, packageUnit) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Get Package Unit Failed", false, undefined);
     }else{
         jsonString = messageFormatter.FormatMessage(err, "Get Package Unit Successful", true, packageUnit);
     }
     res.end(jsonString);
 });
 codec.save(function (err, codecObj) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Codec save failed", false, undefined);
     } else {
         jsonString = messageFormatter.FormatMessage(undefined, "Codec saved successfully", true, codecObj);
     }
     res.end(jsonString);
 });
 Codec.findOneAndUpdate({codec: req.params.codec}, req.body, function(err, codecObj) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Update Codec Failed", false, undefined);
     }else{
         jsonString = messageFormatter.FormatMessage(err, "Update Codec Successful", true, codecObj);
     }
     res.end(jsonString);
 });
 codecObj.remove(function (err) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Delete Codec Failed", false, undefined);
     } else {
         jsonString = messageFormatter.FormatMessage(undefined, "Codec successfully deleted", true, undefined);
     }
     res.end(jsonString);
 });
 Codec.find({active: true}, function(err, codecObj) {
     if (err) {
         jsonString = messageFormatter.FormatMessage(err, "Get Codec Failed", false, undefined);
     }else{
         jsonString = messageFormatter.FormatMessage(err, "Get Codec Successful", true, codecObj);
     }
     res.end(jsonString);
 });
Beispiel #17
0
        CroneHandler.CroneDataRecorder(req.body,company,tenant, function (error,result) {

            console.log("---------------------- length start -------------------"+Jobs);
            if(error)
            {
                var jsonString = messageFormatter.FormatMessage(error, "ERROR", false, undefined);
                logger.debug('[DVP-CronScheduler.New Cron] - [%s] - Error',reqId,jsonString);
                res.end(jsonString);
            }
            else
            {
                var job=new cronJob(pattern, function() {
                    CroneHandler.CronCallbackHandler(reqId,result.Company,result.Tenant, function (err,response) {

                        if(err)
                        {
                            console.log(err);
                        }
                        else
                        {
                            if(checkDate)
                            {
                                delete Jobs[reqId];

                                CroneHandler.JobRemover(reqId,company,tenant, function (errRemove,resRemove) {
                                    if(errRemove)
                                    {
                                        console.log("Error in object cache removing");
                                    }
                                    else
                                    {
                                        console.log("Object cache removed successfully");
                                    }
                                });

                            }
                        }

                    });


                }, null, false,req.body.Timezone);





                Jobs[reqId] =job;
                job.start();


                var jsonString = messageFormatter.FormatMessage(undefined, "SUCCESS", true, reqId);
                logger.debug('[DVP-CronScheduler.New Cron] - [%s] - Successfully saved',reqId,jsonString);
                res.end(jsonString);

            }

        });
Beispiel #18
0
    CroneHandler.CroneObjectUpdater(croneId,company,tenant,req.body, function (err,response) {
        if(err)
        {
            var jsonString = messageFormatter.FormatMessage(err, "ERROR", false, undefined);
            logger.debug('[DVP-CronScheduler.update Cron] - [%s] - Updation error',reqId,jsonString);
            res.end(jsonString);
        }
        else
        {



            var job=new cronJob(pattern, function() {
                CroneHandler.CronCallbackHandler(croneId,company,tenant, function (err,response) {

                    if(err)
                    {
                        console.log(err);
                    }
                    else
                    {
                        if(checkDate)
                        {
                            delete Jobs[croneId];

                            CroneHandler.JobRemover(croneId,company,tenant, function (errRemove,resRemove) {
                                if(errRemove)
                                {
                                    console.log("Error in object cache removing");
                                }
                                else
                                {
                                    console.log("Object cache removed successfully");
                                }
                            });

                        }
                    }

                });


            }, null, false,req.body.Timezone);

            Jobs[croneId] =job;
            job.start();

            var jsonString = messageFormatter.FormatMessage(undefined, "SUCCESS", true, response);
            logger.debug('[DVP-CronScheduler.update Cron] - [%s] - Updation success',reqId,jsonString);
            res.end(jsonString);
        }


    });
 database.find({_id: {$in: arrOfVals}}).toArray(function (err, eng) {
     if (!err) {
         logger.info('getAllEngagementsByDate - [%s]', selectedDate);
         jsonString = messageFormatter.FormatMessage(undefined, "EXCEPTION", true, eng);
         res.end(jsonString);
     }else{
         logger.error('getAllEngagementsByDate - [%s]', selectedDate, err);
         jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
         res.end(jsonString);
     }
 });
Beispiel #20
0
    email.save(function (err, email) {
        if (err) {
            jsonString = messageFormatter.FormatMessage(err, "Email save failed", false, undefined);

        } else {

            jsonString = messageFormatter.FormatMessage(err, "Email saved successfully", true, email);
        }

        res.end(jsonString);
    });
 database.find({_id: {$in: ids}}).toArray(function (err, anc) {
     if (!err) {
         logger.info('getAllAttachments - [%s]', engagementId);
         jsonString = messageFormatter.FormatMessage(undefined, "EXCEPTION", true, anc);
         res.end(jsonString);
     }
     else {
         jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
         res.end(jsonString);
     }
 });
 database.findOne({_id: engagementId}, function (err, eng) {
     if (!err) {
         logger.info('getEngagementById - [%s]', engagementId);
         jsonString = messageFormatter.FormatMessage(undefined, "EXCEPTION", true, eng);
         res.end(jsonString);
     }
     else {
                  logger.error('getEngagementById - [%s]', engagementId, err);
         jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
         res.end(jsonString);
     }
 });
Beispiel #23
0
server.post('/DVP/API/:version/CallRuleApi/CallRule/:ruleId/SetApplication/:appId', authorization({resource:"callrule", action:"write"}), function(req, res, next)
{
    var reqId = uuid.v1();

    try
    {
        var id = req.params.ruleId;
        var appId = req.params.appId;
        var companyId = req.user.company;
        var tenantId = req.user.tenant;

        logger.debug('[DVP-RuleService.CallRuleSetApplication] - [%s] - HTTP Request Received - Req Params : ruleId : %s, appId : %s', reqId, id, appId);

        if (!companyId || !tenantId)
        {
            throw new Error("Invalid company or tenant");
        }

        if(id && appId)
        {
            ruleBackendHandler.SetCallRuleAppDB(reqId, id, appId, companyId, tenantId, function(err, result){

                if(err)
                {
                    var jsonString = messageFormatter.FormatMessage(err, "ERROR", false, undefined);
                    logger.debug('[DVP-PBXService.CallRuleSetApplication] - [%s] - API RESPONSE : %s', reqId, jsonString);
                    res.end(jsonString);
                }
                else
                {
                    var jsonString = messageFormatter.FormatMessage(undefined, "App added to call rule successfully", result, undefined);
                    logger.debug('[DVP-PBXService.CallRuleSetApplication] - [%s] - API RESPONSE : %s', reqId, jsonString);
                    res.end(jsonString);
                }
            })
        }
        else
        {
            var jsonString = messageFormatter.FormatMessage(new Error("Empty params"), "ERROR", false, undefined);
            logger.debug('[DVP-PBXService.CallRuleSetApplication] - [%s] - API RESPONSE : %s', reqId, jsonString);
            res.end(jsonString);
        }
    }
    catch(ex)
    {
        var jsonString = messageFormatter.FormatMessage(ex, "ERROR", false, undefined);
        logger.debug('[DVP-PBXService.CallRuleSetApplication] - [%s] - API RESPONSE : %s', reqId, jsonString);
        res.end(jsonString);
    }

    return next();

});
    Client.findOne({clientId: req.params.clientid}, function(err, client) {
        if (err) {

            jsonString = messageFormatter.FormatMessage(err, "Get Client Failed", false, undefined);

        }else{

            jsonString = messageFormatter.FormatMessage(err, "Get Client Successful", true, client);

        }

        res.end(jsonString);
    });
Beispiel #25
0
    Email.find({ company: company, tenant: tenant }, function (err, email) {
        if (err) {
            jsonString = messageFormatter.FormatMessage(err, "Get Email accounts failed", false, undefined);
        } else {
            if (email && email.length > 0) {
                jsonString = messageFormatter.FormatMessage(undefined, "Get Email accounts Success", true, email);
            } else {

                jsonString = messageFormatter.FormatMessage(undefined, "No Email account found", false, undefined);
            }
        }
        res.end(jsonString);
    });
 database.insertOne(newEng, function (err, result) {
     var jsonString;
     if (!err) {
         logger.info('updateLinks - [%s]', newEng.engagementId);
         jsonString = messageFormatter.FormatMessage(undefined, "EXCEPTION", result.result.ok == 1, result.insertedId.toString());
         res.end(jsonString);
     }
     else {
         logger.error('save Root Engagement - [%s]', newEng.engagementId, err);
         jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
         res.end(jsonString);
     }
 });
Beispiel #27
0
    Email.findOne({ _id: req.params.id, company: company, tenant: tenant }, function (err, email) {
        if (err) {
            jsonString = messageFormatter.FormatMessage(err, "Get Email account failed", false, undefined);
        } else {
            if (email) {
                jsonString = messageFormatter.FormatMessage(undefined, "Get Email account Success", true, email);
            } else {

                jsonString = messageFormatter.FormatMessage(undefined, "No Email account found", false, undefined);
            }
        }
        res.end(jsonString);
    });
        database.findOne({_id: new ObjectID(attachmentId)}, function (err, eng) {
            if (!err) {
                logger.info('getAttachment - [%s]', attachmentId);
                jsonString = messageFormatter.FormatMessage(undefined, "EXCEPTION", true, eng);
                res.end(jsonString);
            }
            else {

                logger.error('getAttachment - [%s]', attachmentId, err);
                jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
                res.end(jsonString);
            }
        });
    collection.find({}).skip(skip).limit(size).toArray(function (err, eng) {
        if (!err) {
            logger.info('getAllEngagementsByDate - [%s]', selectedDate);
            jsonString = messageFormatter.FormatMessage(undefined, "EXCEPTION", true, eng);
            res.end(jsonString);
        }
        else {

            logger.error('getAllEngagementsByDate - [%s]', selectedDate, err);
            jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
            res.end(jsonString);
        }
    });
    }, function (err, result) {
        if (!err) {
            logger.info('updateLinks - [%s]', engagementId);
            jsonString = messageFormatter.FormatMessage(undefined, "EXCEPTION", result.result.ok == 1, insertedId);
            res.end(jsonString);
        }
        else {

            logger.error('updateLinks - [%s]', engagementId, err);
            jsonString = messageFormatter.FormatMessage(err, "EXCEPTION", false, undefined);
            res.end(jsonString);
        }
    })