Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / squareMessage / squareMessage.controller.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 _0x8d62=['filter','merge','VIRTUAL','include','findAll','rows','catch','params','fields','includeAll','options','find','update','body','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','send','index','map','SquareMessage','rawAttributes','fieldName','type','model','keys','query','filters','intersection','attributes','length','hasOwnProperty','nolimit','sort','where','pick'];(function(_0x122ef9,_0x451d2a){var _0x42fba0=function(_0x17c9d3){while(--_0x17c9d3){_0x122ef9['push'](_0x122ef9['shift']());}};_0x42fba0(++_0x451d2a);}(_0x8d62,0xf8));var _0x28d6=function(_0x51547b,_0x55ac59){_0x51547b=_0x51547b-0x0;var _0x196f6e=_0x8d62[_0x51547b];return _0x196f6e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x28d6('0x0'));var zipdir=require(_0x28d6('0x1'));var jsonpatch=require(_0x28d6('0x2'));var rp=require(_0x28d6('0x3'));var moment=require(_0x28d6('0x4'));var BPromise=require(_0x28d6('0x5'));var Mustache=require(_0x28d6('0x6'));var util=require(_0x28d6('0x7'));var path=require(_0x28d6('0x8'));var sox=require(_0x28d6('0x9'));var csv=require(_0x28d6('0xa'));var ejs=require(_0x28d6('0xb'));var fs=require('fs');var fs_extra=require(_0x28d6('0xc'));var _=require(_0x28d6('0xd'));var squel=require('squel');var crypto=require(_0x28d6('0xe'));var jsforce=require(_0x28d6('0xf'));var deskjs=require(_0x28d6('0x10'));var toCsv=require('to-csv');var querystring=require(_0x28d6('0x11'));var Papa=require('papaparse');var Redis=require(_0x28d6('0x12'));var authService=require(_0x28d6('0x13'));var qs=require(_0x28d6('0x14'));var as=require(_0x28d6('0x15'));var hardwareService=require(_0x28d6('0x16'));var logger=require('../../config/logger')(_0x28d6('0x17'));var utils=require(_0x28d6('0x18'));var config=require(_0x28d6('0x19'));var licenseUtil=require(_0x28d6('0x1a'));var db=require(_0x28d6('0x1b'))['db'];function respondWithStatusCode(_0x240839,_0x2c29bd){_0x2c29bd=_0x2c29bd||0xcc;return function(_0x43d460){if(_0x43d460){return _0x240839['sendStatus'](_0x2c29bd);}return _0x240839[_0x28d6('0x1c')](_0x2c29bd)[_0x28d6('0x1d')]();};}function respondWithResult(_0x33ba38,_0x549b39){_0x549b39=_0x549b39||0xc8;return function(_0x1621ee){if(_0x1621ee){return _0x33ba38['status'](_0x549b39)[_0x28d6('0x1e')](_0x1621ee);}};}function respondWithFilteredResult(_0x425ffb,_0x4b82e2){return function(_0x1881a8){if(_0x1881a8){var _0x159d2a=typeof _0x4b82e2[_0x28d6('0x1f')]===_0x28d6('0x20')&&typeof _0x4b82e2[_0x28d6('0x21')]==='undefined';var _0x35317d=_0x1881a8['count'];var _0x44db1a=_0x159d2a?0x0:_0x4b82e2[_0x28d6('0x1f')];var _0x2824bd=_0x159d2a?_0x1881a8[_0x28d6('0x22')]:_0x4b82e2[_0x28d6('0x1f')]+_0x4b82e2[_0x28d6('0x21')];var _0x2d521d;if(_0x2824bd>=_0x35317d){_0x2824bd=_0x35317d;_0x2d521d=0xc8;}else{_0x2d521d=0xce;}_0x425ffb['status'](_0x2d521d);return _0x425ffb[_0x28d6('0x23')](_0x28d6('0x24'),_0x44db1a+'-'+_0x2824bd+'/'+_0x35317d)['json'](_0x1881a8);}return null;};}function patchUpdates(_0x26362e){return function(_0x24f764){try{jsonpatch[_0x28d6('0x25')](_0x24f764,_0x26362e,!![]);}catch(_0x252c1d){return BPromise[_0x28d6('0x26')](_0x252c1d);}return _0x24f764[_0x28d6('0x27')]();};}function saveUpdates(_0x376a64,_0x506be6){return function(_0xcf8fa0){if(_0xcf8fa0){return _0xcf8fa0['update'](_0x376a64)[_0x28d6('0x28')](function(_0x2288eb){return _0x2288eb;});}return null;};}function removeEntity(_0x455dd6,_0x3d128b){return function(_0x26809d){if(_0x26809d){return _0x26809d[_0x28d6('0x29')]()['then'](function(){_0x455dd6['status'](0xcc)[_0x28d6('0x1d')]();});}};}function handleEntityNotFound(_0x2fb6f7,_0x31aa98){return function(_0x210bfc){if(!_0x210bfc){_0x2fb6f7['sendStatus'](0x194);}return _0x210bfc;};}function handleError(_0x18edec,_0x2c4594){_0x2c4594=_0x2c4594||0x1f4;return function(_0x2b9862){logger[_0x28d6('0x2a')](_0x2b9862[_0x28d6('0x2b')]);if(_0x2b9862[_0x28d6('0x2c')]){delete _0x2b9862[_0x28d6('0x2c')];}_0x18edec[_0x28d6('0x1c')](_0x2c4594)[_0x28d6('0x2d')](_0x2b9862);};}exports[_0x28d6('0x2e')]=function(_0x28aaa6,_0x1f2298){var _0x30e05c={},_0x3ba89f={},_0x4b140e={'count':0x0,'rows':[]};var _0x48ada1=_[_0x28d6('0x2f')](db[_0x28d6('0x30')][_0x28d6('0x31')],function(_0x124404){return{'name':_0x124404[_0x28d6('0x32')],'type':_0x124404[_0x28d6('0x33')]['key']};});_0x3ba89f[_0x28d6('0x34')]=_['map'](_0x48ada1,_0x28d6('0x2c'));_0x3ba89f['query']=_[_0x28d6('0x35')](_0x28aaa6[_0x28d6('0x36')]);_0x3ba89f[_0x28d6('0x37')]=_[_0x28d6('0x38')](_0x3ba89f[_0x28d6('0x34')],_0x3ba89f['query']);_0x30e05c['attributes']=_[_0x28d6('0x38')](_0x3ba89f[_0x28d6('0x34')],qs['fields'](_0x28aaa6[_0x28d6('0x36')]['fields']));_0x30e05c[_0x28d6('0x39')]=_0x30e05c['attributes'][_0x28d6('0x3a')]?_0x30e05c['attributes']:_0x3ba89f[_0x28d6('0x34')];if(!_0x28aaa6[_0x28d6('0x36')][_0x28d6('0x3b')](_0x28d6('0x3c'))){_0x30e05c[_0x28d6('0x21')]=qs[_0x28d6('0x21')](_0x28aaa6[_0x28d6('0x36')]['limit']);_0x30e05c[_0x28d6('0x1f')]=qs[_0x28d6('0x1f')](_0x28aaa6[_0x28d6('0x36')][_0x28d6('0x1f')]);}_0x30e05c['order']=qs[_0x28d6('0x3d')](_0x28aaa6[_0x28d6('0x36')][_0x28d6('0x3d')]);_0x30e05c[_0x28d6('0x3e')]=qs['filters'](_[_0x28d6('0x3f')](_0x28aaa6[_0x28d6('0x36')],_0x3ba89f[_0x28d6('0x37')]),_0x48ada1);if(_0x28aaa6[_0x28d6('0x36')][_0x28d6('0x40')]){_0x30e05c[_0x28d6('0x3e')]=_[_0x28d6('0x41')](_0x30e05c[_0x28d6('0x3e')],{'$or':_[_0x28d6('0x2f')](_0x48ada1,function(_0x163a10){if(_0x163a10[_0x28d6('0x33')]!==_0x28d6('0x42')){var _0x286b3d={};_0x286b3d[_0x163a10[_0x28d6('0x2c')]]={'$like':'%'+_0x28aaa6[_0x28d6('0x36')][_0x28d6('0x40')]+'%'};return _0x286b3d;}})});}_0x30e05c=_['merge']({},_0x30e05c,_0x28aaa6['options']);var _0x4ea872={'where':_0x30e05c[_0x28d6('0x3e')]};return db['SquareMessage']['count'](_0x4ea872)[_0x28d6('0x28')](function(_0x4ea383){_0x4b140e[_0x28d6('0x22')]=_0x4ea383;if(_0x28aaa6[_0x28d6('0x36')]['includeAll']){_0x30e05c[_0x28d6('0x43')]=[{'all':!![]}];}return db[_0x28d6('0x30')][_0x28d6('0x44')](_0x30e05c);})[_0x28d6('0x28')](function(_0x3388dc){_0x4b140e[_0x28d6('0x45')]=_0x3388dc;return _0x4b140e;})[_0x28d6('0x28')](respondWithFilteredResult(_0x1f2298,_0x30e05c))[_0x28d6('0x46')](handleError(_0x1f2298,null));};exports['show']=function(_0x1bc066,_0x3acc76){var _0x553d13={'raw':!![],'where':{'id':_0x1bc066[_0x28d6('0x47')]['id']}},_0x25ac32={};_0x25ac32[_0x28d6('0x34')]=_['keys'](db[_0x28d6('0x30')][_0x28d6('0x31')]);_0x25ac32[_0x28d6('0x36')]=_[_0x28d6('0x35')](_0x1bc066['query']);_0x25ac32[_0x28d6('0x37')]=_[_0x28d6('0x38')](_0x25ac32[_0x28d6('0x34')],_0x25ac32['query']);_0x553d13[_0x28d6('0x39')]=_[_0x28d6('0x38')](_0x25ac32[_0x28d6('0x34')],qs[_0x28d6('0x48')](_0x1bc066['query'][_0x28d6('0x48')]));_0x553d13[_0x28d6('0x39')]=_0x553d13[_0x28d6('0x39')][_0x28d6('0x3a')]?_0x553d13[_0x28d6('0x39')]:_0x25ac32['model'];if(_0x1bc066[_0x28d6('0x36')][_0x28d6('0x49')]){_0x553d13[_0x28d6('0x43')]=[{'all':!![]}];}_0x553d13=_[_0x28d6('0x41')]({},_0x553d13,_0x1bc066[_0x28d6('0x4a')]);return db[_0x28d6('0x30')][_0x28d6('0x4b')](_0x553d13)[_0x28d6('0x28')](handleEntityNotFound(_0x3acc76,null))[_0x28d6('0x28')](respondWithResult(_0x3acc76,null))[_0x28d6('0x46')](handleError(_0x3acc76,null));};exports['create']=function(_0x4c8edb,_0x261c01){return db['SquareMessage']['create'](_0x4c8edb['body'],{})[_0x28d6('0x28')](respondWithResult(_0x261c01,0xc9))['catch'](handleError(_0x261c01,null));};exports[_0x28d6('0x4c')]=function(_0x543f58,_0x1cfe1f){if(_0x543f58[_0x28d6('0x4d')]['id']){delete _0x543f58[_0x28d6('0x4d')]['id'];}return db['SquareMessage']['find']({'where':{'id':_0x543f58['params']['id']}})[_0x28d6('0x28')](handleEntityNotFound(_0x1cfe1f,null))[_0x28d6('0x28')](saveUpdates(_0x543f58['body'],null))[_0x28d6('0x28')](respondWithResult(_0x1cfe1f,null))[_0x28d6('0x46')](handleError(_0x1cfe1f,null));};exports[_0x28d6('0x29')]=function(_0x27e8e6,_0x1d3d61){return db[_0x28d6('0x30')][_0x28d6('0x4b')]({'where':{'id':_0x27e8e6[_0x28d6('0x47')]['id']}})['then'](handleEntityNotFound(_0x1d3d61,null))[_0x28d6('0x28')](removeEntity(_0x1d3d61,null))[_0x28d6('0x46')](handleError(_0x1d3d61,null));};