2d81d38ec22e90eb60332c64fbeb58a17526c83d
[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 _0xb3fb=['include','model','map','stringify','lodash','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','request','then','info','Template,\x20%s,\x20%s','debug','Template,\x20%s,\x20%s,\x20%s','request\x20sent','code','error','message','result','catch','GetTemplate','Template','findAll','options','raw','where','attributes','limit'];(function(_0x3d3b05,_0x334c57){var _0x2c6ca3=function(_0x3fd1cc){while(--_0x3fd1cc){_0x3d3b05['push'](_0x3d3b05['shift']());}};_0x2c6ca3(++_0x334c57);}(_0xb3fb,0x6d));var _0xbb3f=function(_0x2bbe84,_0x27e011){_0x2bbe84=_0x2bbe84-0x0;var _0x5467bd=_0xb3fb[_0x2bbe84];return _0x5467bd;};'use strict';var _=require(_0xbb3f('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0xbb3f('0x1'));var rs=require(_0xbb3f('0x2'));var fs=require('fs');var Redis=require(_0xbb3f('0x3'));var db=require(_0xbb3f('0x4'))['db'];var utils=require(_0xbb3f('0x5'));var logger=require(_0xbb3f('0x6'))(_0xbb3f('0x7'));var config=require(_0xbb3f('0x8'));var jayson=require(_0xbb3f('0x9'));var client=jayson[_0xbb3f('0xa')]['http']({'port':0x232a});function respondWithRpcPromise(_0x122df2,_0x248a80,_0x1a4135){return new BPromise(function(_0x57798f,_0x24bdc4){return client[_0xbb3f('0xb')](_0x122df2,_0x1a4135)[_0xbb3f('0xc')](function(_0x2fa739){logger[_0xbb3f('0xd')](_0xbb3f('0xe'),_0x248a80,'request\x20sent');logger[_0xbb3f('0xf')](_0xbb3f('0x10'),_0x248a80,_0xbb3f('0x11'),JSON['stringify'](_0x2fa739));if(_0x2fa739['error']){if(_0x2fa739['error'][_0xbb3f('0x12')]===0x1f4){logger[_0xbb3f('0x13')](_0xbb3f('0xe'),_0x248a80,_0x2fa739[_0xbb3f('0x13')][_0xbb3f('0x14')]);return _0x24bdc4(_0x2fa739[_0xbb3f('0x13')][_0xbb3f('0x14')]);}logger[_0xbb3f('0x13')]('Template,\x20%s,\x20%s',_0x248a80,_0x2fa739[_0xbb3f('0x13')][_0xbb3f('0x14')]);return _0x57798f(_0x2fa739[_0xbb3f('0x13')][_0xbb3f('0x14')]);}else{logger[_0xbb3f('0xd')](_0xbb3f('0xe'),_0x248a80,_0xbb3f('0x11'));_0x57798f(_0x2fa739[_0xbb3f('0x15')][_0xbb3f('0x14')]);}})[_0xbb3f('0x16')](function(_0x55bd48){logger[_0xbb3f('0x13')](_0xbb3f('0xe'),_0x248a80,_0x55bd48);_0x24bdc4(_0x55bd48);});});}exports[_0xbb3f('0x17')]=function(_0x14ec8d){var _0x1c164a=this;return new Promise(function(_0x22948c,_0x85922c){return db[_0xbb3f('0x18')][_0xbb3f('0x19')]({'raw':_0x14ec8d[_0xbb3f('0x1a')]?_0x14ec8d['options'][_0xbb3f('0x1b')]===undefined?!![]:![]:!![],'where':_0x14ec8d['options']?_0x14ec8d[_0xbb3f('0x1a')][_0xbb3f('0x1c')]||null:null,'attributes':_0x14ec8d['options']?_0x14ec8d[_0xbb3f('0x1a')][_0xbb3f('0x1d')]||null:null,'limit':_0x14ec8d[_0xbb3f('0x1a')]?_0x14ec8d[_0xbb3f('0x1a')][_0xbb3f('0x1e')]||null:null,'include':_0x14ec8d[_0xbb3f('0x1a')]?_0x14ec8d[_0xbb3f('0x1a')]['include']?_['map'](_0x14ec8d[_0xbb3f('0x1a')][_0xbb3f('0x1f')],function(_0x453f17){return{'model':db[_0x453f17[_0xbb3f('0x20')]],'as':_0x453f17['as'],'attributes':_0x453f17[_0xbb3f('0x1d')],'include':_0x453f17[_0xbb3f('0x1f')]?_[_0xbb3f('0x21')](_0x453f17[_0xbb3f('0x1f')],function(_0x1b80c1){return{'model':db[_0x1b80c1['model']],'as':_0x1b80c1['as'],'attributes':_0x1b80c1[_0xbb3f('0x1d')],'include':_0x1b80c1[_0xbb3f('0x1f')]?_[_0xbb3f('0x21')](_0x1b80c1[_0xbb3f('0x1f')],function(_0x46e192){return{'model':db[_0x46e192[_0xbb3f('0x20')]],'as':_0x46e192['as'],'attributes':_0x46e192[_0xbb3f('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xbb3f('0xc')](function(_0x740d98){logger[_0xbb3f('0xd')](_0xbb3f('0x17'),_0x14ec8d);logger['debug'](_0xbb3f('0x17'),_0x14ec8d,JSON[_0xbb3f('0x22')](_0x740d98));_0x22948c(_0x740d98);})[_0xbb3f('0x16')](function(_0x1c1920){logger[_0xbb3f('0x13')](_0xbb3f('0x17'),_0x1c1920[_0xbb3f('0x14')],_0x14ec8d);_0x85922c(_0x1c164a[_0xbb3f('0x13')](0x1f4,_0x1c1920[_0xbb3f('0x14')]));});});};