5a67c39cde6d14a6bca0bf118396e98a79614479
[motion2.git] / server / api / template / template.rpc.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x7dc8=['model','include','map','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','client','request','then','info','Template,\x20%s,\x20%s','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','GetTemplate','Template','findAll','options','raw','where','attributes','limit'];(function(_0x273de0,_0x564057){var _0x309969=function(_0x1fa6de){while(--_0x1fa6de){_0x273de0['push'](_0x273de0['shift']());}};_0x309969(++_0x564057);}(_0x7dc8,0x1b0));var _0x87dc=function(_0x1d0b52,_0x24b776){_0x1d0b52=_0x1d0b52-0x0;var _0x2e9da3=_0x7dc8[_0x1d0b52];return _0x2e9da3;};'use strict';var _=require('lodash');var util=require('util');var moment=require('moment');var BPromise=require(_0x87dc('0x0'));var rs=require(_0x87dc('0x1'));var fs=require('fs');var Redis=require(_0x87dc('0x2'));var db=require(_0x87dc('0x3'))['db'];var utils=require(_0x87dc('0x4'));var logger=require('../../config/logger')(_0x87dc('0x5'));var config=require(_0x87dc('0x6'));var jayson=require(_0x87dc('0x7'));var client=jayson[_0x87dc('0x8')]['http']({'port':0x232a});function respondWithRpcPromise(_0x223649,_0x528525,_0x543a14){return new BPromise(function(_0xb6148c,_0x548b80){return client[_0x87dc('0x9')](_0x223649,_0x543a14)[_0x87dc('0xa')](function(_0x3a30c1){logger[_0x87dc('0xb')](_0x87dc('0xc'),_0x528525,_0x87dc('0xd'));logger[_0x87dc('0xe')](_0x87dc('0xf'),_0x528525,'request\x20sent',JSON[_0x87dc('0x10')](_0x3a30c1));if(_0x3a30c1[_0x87dc('0x11')]){if(_0x3a30c1[_0x87dc('0x11')][_0x87dc('0x12')]===0x1f4){logger[_0x87dc('0x11')](_0x87dc('0xc'),_0x528525,_0x3a30c1[_0x87dc('0x11')][_0x87dc('0x13')]);return _0x548b80(_0x3a30c1['error'][_0x87dc('0x13')]);}logger['error'](_0x87dc('0xc'),_0x528525,_0x3a30c1[_0x87dc('0x11')][_0x87dc('0x13')]);return _0xb6148c(_0x3a30c1[_0x87dc('0x11')][_0x87dc('0x13')]);}else{logger[_0x87dc('0xb')](_0x87dc('0xc'),_0x528525,'request\x20sent');_0xb6148c(_0x3a30c1[_0x87dc('0x14')]['message']);}})[_0x87dc('0x15')](function(_0x14541b){logger['error'](_0x87dc('0xc'),_0x528525,_0x14541b);_0x548b80(_0x14541b);});});}exports[_0x87dc('0x16')]=function(_0x4f3554){var _0x4b314c=this;return new Promise(function(_0x10af3f,_0x342117){return db[_0x87dc('0x17')][_0x87dc('0x18')]({'raw':_0x4f3554['options']?_0x4f3554[_0x87dc('0x19')][_0x87dc('0x1a')]===undefined?!![]:![]:!![],'where':_0x4f3554[_0x87dc('0x19')]?_0x4f3554[_0x87dc('0x19')][_0x87dc('0x1b')]||null:null,'attributes':_0x4f3554['options']?_0x4f3554[_0x87dc('0x19')][_0x87dc('0x1c')]||null:null,'limit':_0x4f3554[_0x87dc('0x19')]?_0x4f3554[_0x87dc('0x19')][_0x87dc('0x1d')]||null:null,'include':_0x4f3554[_0x87dc('0x19')]?_0x4f3554['options']['include']?_['map'](_0x4f3554[_0x87dc('0x19')]['include'],function(_0x30bf3){return{'model':db[_0x30bf3[_0x87dc('0x1e')]],'as':_0x30bf3['as'],'attributes':_0x30bf3[_0x87dc('0x1c')],'include':_0x30bf3[_0x87dc('0x1f')]?_[_0x87dc('0x20')](_0x30bf3[_0x87dc('0x1f')],function(_0x2adab0){return{'model':db[_0x2adab0[_0x87dc('0x1e')]],'as':_0x2adab0['as'],'attributes':_0x2adab0['attributes'],'include':_0x2adab0[_0x87dc('0x1f')]?_[_0x87dc('0x20')](_0x2adab0['include'],function(_0x2eb6d5){return{'model':db[_0x2eb6d5[_0x87dc('0x1e')]],'as':_0x2eb6d5['as'],'attributes':_0x2eb6d5['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x4c7441){logger['info'](_0x87dc('0x16'),_0x4f3554);logger[_0x87dc('0xe')](_0x87dc('0x16'),_0x4f3554,JSON[_0x87dc('0x10')](_0x4c7441));_0x10af3f(_0x4c7441);})[_0x87dc('0x15')](function(_0x1fa42a){logger[_0x87dc('0x11')](_0x87dc('0x16'),_0x1fa42a[_0x87dc('0x13')],_0x4f3554);_0x342117(_0x4b314c[_0x87dc('0x11')](0x1f4,_0x1fa42a[_0x87dc('0x13')]));});});};