Built motion from commit 9e1399f3.|2.5.37
[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 _0x87ef=['where','filter','VIRTUAL','merge','options','findAll','rows','catch','show','includeAll','include','find','create','body','params','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','count','limit','Content-Range','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','send','index','SquareMessage','rawAttributes','fieldName','type','key','map','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','order','sort'];(function(_0x4541ee,_0x689687){var _0xde5008=function(_0x174a59){while(--_0x174a59){_0x4541ee['push'](_0x4541ee['shift']());}};_0xde5008(++_0x689687);}(_0x87ef,0x13f));var _0xf87e=function(_0x30a31e,_0x31f766){_0x30a31e=_0x30a31e-0x0;var _0x170879=_0x87ef[_0x30a31e];return _0x170879;};'use strict';var emlformat=require(_0xf87e('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf87e('0x1'));var jsonpatch=require(_0xf87e('0x2'));var rp=require(_0xf87e('0x3'));var moment=require(_0xf87e('0x4'));var BPromise=require(_0xf87e('0x5'));var Mustache=require(_0xf87e('0x6'));var util=require(_0xf87e('0x7'));var path=require(_0xf87e('0x8'));var sox=require(_0xf87e('0x9'));var csv=require(_0xf87e('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf87e('0xb'));var _=require(_0xf87e('0xc'));var squel=require(_0xf87e('0xd'));var crypto=require(_0xf87e('0xe'));var jsforce=require(_0xf87e('0xf'));var deskjs=require(_0xf87e('0x10'));var toCsv=require(_0xf87e('0xa'));var querystring=require('querystring');var Papa=require(_0xf87e('0x11'));var Redis=require('ioredis');var authService=require(_0xf87e('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xf87e('0x13'));var hardwareService=require(_0xf87e('0x14'));var logger=require('../../config/logger')(_0xf87e('0x15'));var utils=require('../../config/utils');var config=require(_0xf87e('0x16'));var licenseUtil=require(_0xf87e('0x17'));var db=require(_0xf87e('0x18'))['db'];function respondWithStatusCode(_0x2055f2,_0x3cf430){_0x3cf430=_0x3cf430||0xcc;return function(_0x4efa18){if(_0x4efa18){return _0x2055f2['sendStatus'](_0x3cf430);}return _0x2055f2[_0xf87e('0x19')](_0x3cf430)[_0xf87e('0x1a')]();};}function respondWithResult(_0x2a3fc6,_0x440a9f){_0x440a9f=_0x440a9f||0xc8;return function(_0x568a15){if(_0x568a15){return _0x2a3fc6['status'](_0x440a9f)[_0xf87e('0x1b')](_0x568a15);}};}function respondWithFilteredResult(_0x466d65,_0x5b4616){return function(_0x6df6f4){if(_0x6df6f4){var _0x40c3af=typeof _0x5b4616[_0xf87e('0x1c')]===_0xf87e('0x1d')&&typeof _0x5b4616['limit']===_0xf87e('0x1d');var _0x3f8e6e=_0x6df6f4[_0xf87e('0x1e')];var _0x10fe70=_0x40c3af?0x0:_0x5b4616[_0xf87e('0x1c')];var _0x17f22c=_0x40c3af?_0x6df6f4[_0xf87e('0x1e')]:_0x5b4616['offset']+_0x5b4616[_0xf87e('0x1f')];var _0x3c0815;if(_0x17f22c>=_0x3f8e6e){_0x17f22c=_0x3f8e6e;_0x3c0815=0xc8;}else{_0x3c0815=0xce;}_0x466d65[_0xf87e('0x19')](_0x3c0815);return _0x466d65['set'](_0xf87e('0x20'),_0x10fe70+'-'+_0x17f22c+'/'+_0x3f8e6e)[_0xf87e('0x1b')](_0x6df6f4);}return null;};}function patchUpdates(_0x4e716c){return function(_0x53177){try{jsonpatch[_0xf87e('0x21')](_0x53177,_0x4e716c,!![]);}catch(_0x44a99f){return BPromise[_0xf87e('0x22')](_0x44a99f);}return _0x53177[_0xf87e('0x23')]();};}function saveUpdates(_0x4ef633,_0x16bfc7){return function(_0x5ea936){if(_0x5ea936){return _0x5ea936[_0xf87e('0x24')](_0x4ef633)[_0xf87e('0x25')](function(_0x289adb){return _0x289adb;});}return null;};}function removeEntity(_0xd44dbf,_0x419096){return function(_0xf03593){if(_0xf03593){return _0xf03593[_0xf87e('0x26')]()[_0xf87e('0x25')](function(){_0xd44dbf[_0xf87e('0x19')](0xcc)[_0xf87e('0x1a')]();});}};}function handleEntityNotFound(_0x29f54a,_0x19f500){return function(_0xba804a){if(!_0xba804a){_0x29f54a[_0xf87e('0x27')](0x194);}return _0xba804a;};}function handleError(_0x4b43fe,_0x281c33){_0x281c33=_0x281c33||0x1f4;return function(_0x4040d1){logger[_0xf87e('0x28')](_0x4040d1[_0xf87e('0x29')]);if(_0x4040d1[_0xf87e('0x2a')]){delete _0x4040d1[_0xf87e('0x2a')];}_0x4b43fe[_0xf87e('0x19')](_0x281c33)[_0xf87e('0x2b')](_0x4040d1);};}exports[_0xf87e('0x2c')]=function(_0x2e41fa,_0x3ad696){var _0x52a354={},_0x1b60ac={},_0x3d9cef={'count':0x0,'rows':[]};var _0x3b206f=_['map'](db[_0xf87e('0x2d')][_0xf87e('0x2e')],function(_0x2a43b9){return{'name':_0x2a43b9[_0xf87e('0x2f')],'type':_0x2a43b9[_0xf87e('0x30')][_0xf87e('0x31')]};});_0x1b60ac['model']=_[_0xf87e('0x32')](_0x3b206f,_0xf87e('0x2a'));_0x1b60ac[_0xf87e('0x33')]=_[_0xf87e('0x34')](_0x2e41fa[_0xf87e('0x33')]);_0x1b60ac[_0xf87e('0x35')]=_[_0xf87e('0x36')](_0x1b60ac[_0xf87e('0x37')],_0x1b60ac[_0xf87e('0x33')]);_0x52a354[_0xf87e('0x38')]=_[_0xf87e('0x36')](_0x1b60ac['model'],qs[_0xf87e('0x39')](_0x2e41fa[_0xf87e('0x33')][_0xf87e('0x39')]));_0x52a354['attributes']=_0x52a354[_0xf87e('0x38')]['length']?_0x52a354[_0xf87e('0x38')]:_0x1b60ac[_0xf87e('0x37')];if(!_0x2e41fa[_0xf87e('0x33')][_0xf87e('0x3a')]('nolimit')){_0x52a354[_0xf87e('0x1f')]=qs[_0xf87e('0x1f')](_0x2e41fa[_0xf87e('0x33')][_0xf87e('0x1f')]);_0x52a354[_0xf87e('0x1c')]=qs[_0xf87e('0x1c')](_0x2e41fa[_0xf87e('0x33')][_0xf87e('0x1c')]);}_0x52a354[_0xf87e('0x3b')]=qs['sort'](_0x2e41fa['query'][_0xf87e('0x3c')]);_0x52a354[_0xf87e('0x3d')]=qs[_0xf87e('0x35')](_['pick'](_0x2e41fa[_0xf87e('0x33')],_0x1b60ac[_0xf87e('0x35')]),_0x3b206f);if(_0x2e41fa[_0xf87e('0x33')][_0xf87e('0x3e')]){_0x52a354['where']=_['merge'](_0x52a354[_0xf87e('0x3d')],{'$or':_[_0xf87e('0x32')](_0x3b206f,function(_0x1aa926){if(_0x1aa926[_0xf87e('0x30')]!==_0xf87e('0x3f')){var _0x1d2445={};_0x1d2445[_0x1aa926['name']]={'$like':'%'+_0x2e41fa[_0xf87e('0x33')][_0xf87e('0x3e')]+'%'};return _0x1d2445;}})});}_0x52a354=_[_0xf87e('0x40')]({},_0x52a354,_0x2e41fa[_0xf87e('0x41')]);var _0x580931={'where':_0x52a354[_0xf87e('0x3d')]};return db['SquareMessage'][_0xf87e('0x1e')](_0x580931)['then'](function(_0x1f80ab){_0x3d9cef[_0xf87e('0x1e')]=_0x1f80ab;if(_0x2e41fa[_0xf87e('0x33')]['includeAll']){_0x52a354['include']=[{'all':!![]}];}return db[_0xf87e('0x2d')][_0xf87e('0x42')](_0x52a354);})[_0xf87e('0x25')](function(_0x111b5b){_0x3d9cef[_0xf87e('0x43')]=_0x111b5b;return _0x3d9cef;})['then'](respondWithFilteredResult(_0x3ad696,_0x52a354))[_0xf87e('0x44')](handleError(_0x3ad696,null));};exports[_0xf87e('0x45')]=function(_0x58ca6a,_0x129c70){var _0x1b1417={'raw':!![],'where':{'id':_0x58ca6a['params']['id']}},_0x1adfd2={};_0x1adfd2[_0xf87e('0x37')]=_[_0xf87e('0x34')](db[_0xf87e('0x2d')][_0xf87e('0x2e')]);_0x1adfd2[_0xf87e('0x33')]=_[_0xf87e('0x34')](_0x58ca6a[_0xf87e('0x33')]);_0x1adfd2['filters']=_[_0xf87e('0x36')](_0x1adfd2[_0xf87e('0x37')],_0x1adfd2[_0xf87e('0x33')]);_0x1b1417['attributes']=_[_0xf87e('0x36')](_0x1adfd2[_0xf87e('0x37')],qs[_0xf87e('0x39')](_0x58ca6a[_0xf87e('0x33')][_0xf87e('0x39')]));_0x1b1417[_0xf87e('0x38')]=_0x1b1417['attributes']['length']?_0x1b1417[_0xf87e('0x38')]:_0x1adfd2['model'];if(_0x58ca6a['query'][_0xf87e('0x46')]){_0x1b1417[_0xf87e('0x47')]=[{'all':!![]}];}_0x1b1417=_[_0xf87e('0x40')]({},_0x1b1417,_0x58ca6a[_0xf87e('0x41')]);return db['SquareMessage'][_0xf87e('0x48')](_0x1b1417)[_0xf87e('0x25')](handleEntityNotFound(_0x129c70,null))[_0xf87e('0x25')](respondWithResult(_0x129c70,null))['catch'](handleError(_0x129c70,null));};exports['create']=function(_0x14e9ca,_0x494405){return db[_0xf87e('0x2d')][_0xf87e('0x49')](_0x14e9ca[_0xf87e('0x4a')],{})['then'](respondWithResult(_0x494405,0xc9))['catch'](handleError(_0x494405,null));};exports[_0xf87e('0x24')]=function(_0xa25d64,_0x1e9b5d){if(_0xa25d64['body']['id']){delete _0xa25d64[_0xf87e('0x4a')]['id'];}return db[_0xf87e('0x2d')][_0xf87e('0x48')]({'where':{'id':_0xa25d64[_0xf87e('0x4b')]['id']}})[_0xf87e('0x25')](handleEntityNotFound(_0x1e9b5d,null))[_0xf87e('0x25')](saveUpdates(_0xa25d64['body'],null))[_0xf87e('0x25')](respondWithResult(_0x1e9b5d,null))[_0xf87e('0x44')](handleError(_0x1e9b5d,null));};exports['destroy']=function(_0x2aaa9a,_0x18e519){return db[_0xf87e('0x2d')][_0xf87e('0x48')]({'where':{'id':_0x2aaa9a[_0xf87e('0x4b')]['id']}})[_0xf87e('0x25')](handleEntityNotFound(_0x18e519,null))['then'](removeEntity(_0x18e519,null))[_0xf87e('0x44')](handleError(_0x18e519,null));};