Built motion from commit 4e7c323b.|2.5.34
[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 _0xf960=['sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','json','offset','undefined','limit','count','Content-Range','reject','save','then','destroy','stack','name','send','map','SquareMessage','rawAttributes','type','key','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','findAll','catch','show','params','include','find','create','body','eml-format','zip-dir','request-promise','moment','mustache'];(function(_0x151b2a,_0x2b88b8){var _0x5c2c04=function(_0x1786d0){while(--_0x1786d0){_0x151b2a['push'](_0x151b2a['shift']());}};_0x5c2c04(++_0x2b88b8);}(_0xf960,0x193));var _0x0f96=function(_0x14fad0,_0x278d75){_0x14fad0=_0x14fad0-0x0;var _0x5c665f=_0xf960[_0x14fad0];return _0x5c665f;};'use strict';var emlformat=require(_0x0f96('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x0f96('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x0f96('0x2'));var moment=require(_0x0f96('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x0f96('0x4'));var util=require('util');var path=require('path');var sox=require(_0x0f96('0x5'));var csv=require(_0x0f96('0x6'));var ejs=require(_0x0f96('0x7'));var fs=require('fs');var fs_extra=require(_0x0f96('0x8'));var _=require(_0x0f96('0x9'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x0f96('0xa'));var deskjs=require(_0x0f96('0xb'));var toCsv=require(_0x0f96('0x6'));var querystring=require(_0x0f96('0xc'));var Papa=require(_0x0f96('0xd'));var Redis=require(_0x0f96('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x0f96('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x0f96('0x10'));var logger=require('../../config/logger')(_0x0f96('0x11'));var utils=require(_0x0f96('0x12'));var config=require(_0x0f96('0x13'));var licenseUtil=require(_0x0f96('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xe8aee6,_0x23182a){_0x23182a=_0x23182a||0xcc;return function(_0x1c0283){if(_0x1c0283){return _0xe8aee6[_0x0f96('0x15')](_0x23182a);}return _0xe8aee6['status'](_0x23182a)[_0x0f96('0x16')]();};}function respondWithResult(_0x103185,_0x36d1ca){_0x36d1ca=_0x36d1ca||0xc8;return function(_0x386943){if(_0x386943){return _0x103185[_0x0f96('0x17')](_0x36d1ca)[_0x0f96('0x18')](_0x386943);}};}function respondWithFilteredResult(_0x5080c3,_0x232d94){return function(_0x47ba05){if(_0x47ba05){var _0x4f55cf=typeof _0x232d94[_0x0f96('0x19')]===_0x0f96('0x1a')&&typeof _0x232d94[_0x0f96('0x1b')]===_0x0f96('0x1a');var _0x3f1273=_0x47ba05[_0x0f96('0x1c')];var _0x2dc06c=_0x4f55cf?0x0:_0x232d94[_0x0f96('0x19')];var _0x36ded7=_0x4f55cf?_0x47ba05[_0x0f96('0x1c')]:_0x232d94[_0x0f96('0x19')]+_0x232d94[_0x0f96('0x1b')];var _0x173f3c;if(_0x36ded7>=_0x3f1273){_0x36ded7=_0x3f1273;_0x173f3c=0xc8;}else{_0x173f3c=0xce;}_0x5080c3[_0x0f96('0x17')](_0x173f3c);return _0x5080c3['set'](_0x0f96('0x1d'),_0x2dc06c+'-'+_0x36ded7+'/'+_0x3f1273)[_0x0f96('0x18')](_0x47ba05);}return null;};}function patchUpdates(_0x125b50){return function(_0xea96e0){try{jsonpatch['apply'](_0xea96e0,_0x125b50,!![]);}catch(_0x210a93){return BPromise[_0x0f96('0x1e')](_0x210a93);}return _0xea96e0[_0x0f96('0x1f')]();};}function saveUpdates(_0x47993c,_0x25494f){return function(_0x201226){if(_0x201226){return _0x201226['update'](_0x47993c)[_0x0f96('0x20')](function(_0x142de1){return _0x142de1;});}return null;};}function removeEntity(_0x366146,_0x21bd49){return function(_0x4b3d9f){if(_0x4b3d9f){return _0x4b3d9f[_0x0f96('0x21')]()[_0x0f96('0x20')](function(){_0x366146[_0x0f96('0x17')](0xcc)[_0x0f96('0x16')]();});}};}function handleEntityNotFound(_0x262353,_0x34676c){return function(_0x3cfca7){if(!_0x3cfca7){_0x262353['sendStatus'](0x194);}return _0x3cfca7;};}function handleError(_0x248b45,_0x3a7c7b){_0x3a7c7b=_0x3a7c7b||0x1f4;return function(_0x31e9e6){logger['error'](_0x31e9e6[_0x0f96('0x22')]);if(_0x31e9e6[_0x0f96('0x23')]){delete _0x31e9e6[_0x0f96('0x23')];}_0x248b45[_0x0f96('0x17')](_0x3a7c7b)[_0x0f96('0x24')](_0x31e9e6);};}exports['index']=function(_0x2961e1,_0x254683){var _0x3489bc={},_0x219757={},_0xcb71bd={'count':0x0,'rows':[]};var _0x1f9f2c=_[_0x0f96('0x25')](db[_0x0f96('0x26')][_0x0f96('0x27')],function(_0x163f5f){return{'name':_0x163f5f['fieldName'],'type':_0x163f5f[_0x0f96('0x28')][_0x0f96('0x29')]};});_0x219757['model']=_[_0x0f96('0x25')](_0x1f9f2c,_0x0f96('0x23'));_0x219757['query']=_[_0x0f96('0x2a')](_0x2961e1[_0x0f96('0x2b')]);_0x219757[_0x0f96('0x2c')]=_[_0x0f96('0x2d')](_0x219757[_0x0f96('0x2e')],_0x219757[_0x0f96('0x2b')]);_0x3489bc[_0x0f96('0x2f')]=_['intersection'](_0x219757['model'],qs[_0x0f96('0x30')](_0x2961e1['query']['fields']));_0x3489bc['attributes']=_0x3489bc[_0x0f96('0x2f')][_0x0f96('0x31')]?_0x3489bc[_0x0f96('0x2f')]:_0x219757['model'];if(!_0x2961e1[_0x0f96('0x2b')][_0x0f96('0x32')](_0x0f96('0x33'))){_0x3489bc[_0x0f96('0x1b')]=qs[_0x0f96('0x1b')](_0x2961e1[_0x0f96('0x2b')][_0x0f96('0x1b')]);_0x3489bc[_0x0f96('0x19')]=qs['offset'](_0x2961e1[_0x0f96('0x2b')]['offset']);}_0x3489bc[_0x0f96('0x34')]=qs[_0x0f96('0x35')](_0x2961e1[_0x0f96('0x2b')][_0x0f96('0x35')]);_0x3489bc[_0x0f96('0x36')]=qs[_0x0f96('0x2c')](_[_0x0f96('0x37')](_0x2961e1['query'],_0x219757['filters']),_0x1f9f2c);if(_0x2961e1[_0x0f96('0x2b')][_0x0f96('0x38')]){_0x3489bc[_0x0f96('0x36')]=_[_0x0f96('0x39')](_0x3489bc['where'],{'$or':_[_0x0f96('0x25')](_0x1f9f2c,function(_0x2c14af){if(_0x2c14af[_0x0f96('0x28')]!==_0x0f96('0x3a')){var _0x1a880e={};_0x1a880e[_0x2c14af[_0x0f96('0x23')]]={'$like':'%'+_0x2961e1[_0x0f96('0x2b')][_0x0f96('0x38')]+'%'};return _0x1a880e;}})});}_0x3489bc=_[_0x0f96('0x39')]({},_0x3489bc,_0x2961e1['options']);var _0xa58381={'where':_0x3489bc[_0x0f96('0x36')]};return db['SquareMessage'][_0x0f96('0x1c')](_0xa58381)[_0x0f96('0x20')](function(_0x35eb62){_0xcb71bd['count']=_0x35eb62;if(_0x2961e1[_0x0f96('0x2b')][_0x0f96('0x3b')]){_0x3489bc['include']=[{'all':!![]}];}return db[_0x0f96('0x26')][_0x0f96('0x3c')](_0x3489bc);})['then'](function(_0x24a4d9){_0xcb71bd['rows']=_0x24a4d9;return _0xcb71bd;})['then'](respondWithFilteredResult(_0x254683,_0x3489bc))[_0x0f96('0x3d')](handleError(_0x254683,null));};exports[_0x0f96('0x3e')]=function(_0x29de3d,_0x231be2){var _0x261452={'raw':!![],'where':{'id':_0x29de3d[_0x0f96('0x3f')]['id']}},_0x1e6b76={};_0x1e6b76[_0x0f96('0x2e')]=_['keys'](db['SquareMessage'][_0x0f96('0x27')]);_0x1e6b76['query']=_[_0x0f96('0x2a')](_0x29de3d[_0x0f96('0x2b')]);_0x1e6b76[_0x0f96('0x2c')]=_[_0x0f96('0x2d')](_0x1e6b76[_0x0f96('0x2e')],_0x1e6b76[_0x0f96('0x2b')]);_0x261452[_0x0f96('0x2f')]=_['intersection'](_0x1e6b76[_0x0f96('0x2e')],qs[_0x0f96('0x30')](_0x29de3d[_0x0f96('0x2b')][_0x0f96('0x30')]));_0x261452[_0x0f96('0x2f')]=_0x261452[_0x0f96('0x2f')][_0x0f96('0x31')]?_0x261452[_0x0f96('0x2f')]:_0x1e6b76[_0x0f96('0x2e')];if(_0x29de3d[_0x0f96('0x2b')][_0x0f96('0x3b')]){_0x261452[_0x0f96('0x40')]=[{'all':!![]}];}_0x261452=_['merge']({},_0x261452,_0x29de3d['options']);return db[_0x0f96('0x26')][_0x0f96('0x41')](_0x261452)[_0x0f96('0x20')](handleEntityNotFound(_0x231be2,null))['then'](respondWithResult(_0x231be2,null))[_0x0f96('0x3d')](handleError(_0x231be2,null));};exports[_0x0f96('0x42')]=function(_0x26ae06,_0x2d363b){return db[_0x0f96('0x26')]['create'](_0x26ae06[_0x0f96('0x43')],{})[_0x0f96('0x20')](respondWithResult(_0x2d363b,0xc9))['catch'](handleError(_0x2d363b,null));};exports['update']=function(_0x26a29a,_0x3fce0c){if(_0x26a29a[_0x0f96('0x43')]['id']){delete _0x26a29a[_0x0f96('0x43')]['id'];}return db[_0x0f96('0x26')]['find']({'where':{'id':_0x26a29a[_0x0f96('0x3f')]['id']}})[_0x0f96('0x20')](handleEntityNotFound(_0x3fce0c,null))[_0x0f96('0x20')](saveUpdates(_0x26a29a[_0x0f96('0x43')],null))[_0x0f96('0x20')](respondWithResult(_0x3fce0c,null))[_0x0f96('0x3d')](handleError(_0x3fce0c,null));};exports[_0x0f96('0x21')]=function(_0xc61a62,_0x52321e){return db[_0x0f96('0x26')]['find']({'where':{'id':_0xc61a62[_0x0f96('0x3f')]['id']}})[_0x0f96('0x20')](handleEntityNotFound(_0x52321e,null))[_0x0f96('0x20')](removeEntity(_0x52321e,null))[_0x0f96('0x3d')](handleError(_0x52321e,null));};