Built motion from commit (unavailable).|2.5.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 _0x326f=['query','filters','intersection','attributes','model','fields','length','sort','where','pick','VIRTUAL','options','SquareMessage','includeAll','findAll','rows','catch','show','params','find','create','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','save','update','then','destroy','end','error','stack','name','send','render','merge','body','contact','agent','interaction','account','index','map','rawAttributes','type','key','keys'];(function(_0x547068,_0x311651){var _0x2bbb99=function(_0x1ba48c){while(--_0x1ba48c){_0x547068['push'](_0x547068['shift']());}};_0x2bbb99(++_0x311651);}(_0x326f,0x191));var _0xf326=function(_0xb5c61e,_0x45dcf6){_0xb5c61e=_0xb5c61e-0x0;var _0x3c668a=_0x326f[_0xb5c61e];return _0x3c668a;};'use strict';var emlformat=require(_0xf326('0x0'));var rimraf=require(_0xf326('0x1'));var zipdir=require(_0xf326('0x2'));var jsonpatch=require(_0xf326('0x3'));var rp=require(_0xf326('0x4'));var moment=require('moment');var BPromise=require(_0xf326('0x5'));var Mustache=require(_0xf326('0x6'));var util=require('util');var path=require(_0xf326('0x7'));var sox=require(_0xf326('0x8'));var csv=require(_0xf326('0x9'));var ejs=require(_0xf326('0xa'));var fs=require('fs');var fs_extra=require(_0xf326('0xb'));var _=require('lodash');var squel=require(_0xf326('0xc'));var crypto=require(_0xf326('0xd'));var jsforce=require(_0xf326('0xe'));var deskjs=require(_0xf326('0xf'));var toCsv=require(_0xf326('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf326('0x10'));var authService=require(_0xf326('0x11'));var qs=require(_0xf326('0x12'));var as=require(_0xf326('0x13'));var hardwareService=require(_0xf326('0x14'));var logger=require('../../config/logger')(_0xf326('0x15'));var utils=require(_0xf326('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xf326('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xefb985,_0x98af3b){_0x98af3b=_0x98af3b||0xcc;return function(_0x5a63b6){if(_0x5a63b6){return _0xefb985[_0xf326('0x18')](_0x98af3b);}return _0xefb985[_0xf326('0x19')](_0x98af3b)['end']();};}function respondWithResult(_0x4c952a,_0x2d9f49){_0x2d9f49=_0x2d9f49||0xc8;return function(_0x18b1c9){if(_0x18b1c9){return _0x4c952a[_0xf326('0x19')](_0x2d9f49)[_0xf326('0x1a')](_0x18b1c9);}};}function respondWithFilteredResult(_0x1cdb5a,_0x4e3966){return function(_0x27d53c){if(_0x27d53c){var _0x29b5c8=typeof _0x4e3966[_0xf326('0x1b')]===_0xf326('0x1c')&&typeof _0x4e3966[_0xf326('0x1d')]==='undefined';var _0x35ee84=_0x27d53c['count'];var _0x4a4c5f=_0x29b5c8?0x0:_0x4e3966[_0xf326('0x1b')];var _0x1b6a8a=_0x29b5c8?_0x27d53c[_0xf326('0x1e')]:_0x4e3966['offset']+_0x4e3966[_0xf326('0x1d')];var _0x4896fc;if(_0x1b6a8a>=_0x35ee84){_0x1b6a8a=_0x35ee84;_0x4896fc=0xc8;}else{_0x4896fc=0xce;}_0x1cdb5a[_0xf326('0x19')](_0x4896fc);return _0x1cdb5a[_0xf326('0x1f')](_0xf326('0x20'),_0x4a4c5f+'-'+_0x1b6a8a+'/'+_0x35ee84)[_0xf326('0x1a')](_0x27d53c);}return null;};}function patchUpdates(_0xebb044){return function(_0xd1e5dd){try{jsonpatch['apply'](_0xd1e5dd,_0xebb044,!![]);}catch(_0x2b5a04){return BPromise['reject'](_0x2b5a04);}return _0xd1e5dd[_0xf326('0x21')]();};}function saveUpdates(_0xe3b582,_0x2afcbb){return function(_0x2c4d37){if(_0x2c4d37){return _0x2c4d37[_0xf326('0x22')](_0xe3b582)[_0xf326('0x23')](function(_0x33f6f4){return _0x33f6f4;});}return null;};}function removeEntity(_0x376675,_0x434be6){return function(_0x1a400b){if(_0x1a400b){return _0x1a400b[_0xf326('0x24')]()['then'](function(){_0x376675[_0xf326('0x19')](0xcc)[_0xf326('0x25')]();});}};}function handleEntityNotFound(_0x4ee4a3,_0x56d498){return function(_0x5c3d63){if(!_0x5c3d63){_0x4ee4a3[_0xf326('0x18')](0x194);}return _0x5c3d63;};}function handleError(_0x2cfb9c,_0x4d21a0){_0x4d21a0=_0x4d21a0||0x1f4;return function(_0x35823d){logger[_0xf326('0x26')](_0x35823d[_0xf326('0x27')]);if(_0x35823d[_0xf326('0x28')]){delete _0x35823d[_0xf326('0x28')];}_0x2cfb9c[_0xf326('0x19')](_0x4d21a0)[_0xf326('0x29')](_0x35823d);};}function getMustacheRender(_0x59d82a,_0xafba3c){return Mustache[_0xf326('0x2a')](_0x59d82a,_[_0xf326('0x2b')](_0xafba3c[_0xf326('0x2c')],{'contact':_0xafba3c[_0xf326('0x2d')],'message':_0xafba3c['message'],'agent':_0xafba3c[_0xf326('0x2e')],'interaction':_0xafba3c[_0xf326('0x2f')],'account':_0xafba3c[_0xf326('0x30')]}))||'';}exports[_0xf326('0x31')]=function(_0x5e58e6,_0x2bede6){var _0x1e27c3={},_0x1dcf84={},_0x11ba75={'count':0x0,'rows':[]};var _0x2b8de6=_[_0xf326('0x32')](db['SquareMessage'][_0xf326('0x33')],function(_0x4bc756){return{'name':_0x4bc756['fieldName'],'type':_0x4bc756[_0xf326('0x34')][_0xf326('0x35')]};});_0x1dcf84['model']=_['map'](_0x2b8de6,'name');_0x1dcf84['query']=_[_0xf326('0x36')](_0x5e58e6[_0xf326('0x37')]);_0x1dcf84[_0xf326('0x38')]=_[_0xf326('0x39')](_0x1dcf84['model'],_0x1dcf84[_0xf326('0x37')]);_0x1e27c3[_0xf326('0x3a')]=_[_0xf326('0x39')](_0x1dcf84[_0xf326('0x3b')],qs['fields'](_0x5e58e6[_0xf326('0x37')][_0xf326('0x3c')]));_0x1e27c3[_0xf326('0x3a')]=_0x1e27c3['attributes'][_0xf326('0x3d')]?_0x1e27c3[_0xf326('0x3a')]:_0x1dcf84[_0xf326('0x3b')];if(!_0x5e58e6[_0xf326('0x37')]['hasOwnProperty']('nolimit')){_0x1e27c3[_0xf326('0x1d')]=qs[_0xf326('0x1d')](_0x5e58e6[_0xf326('0x37')][_0xf326('0x1d')]);_0x1e27c3[_0xf326('0x1b')]=qs[_0xf326('0x1b')](_0x5e58e6['query'][_0xf326('0x1b')]);}_0x1e27c3['order']=qs[_0xf326('0x3e')](_0x5e58e6['query'][_0xf326('0x3e')]);_0x1e27c3[_0xf326('0x3f')]=qs['filters'](_[_0xf326('0x40')](_0x5e58e6[_0xf326('0x37')],_0x1dcf84['filters']),_0x2b8de6);if(_0x5e58e6['query']['filter']){_0x1e27c3[_0xf326('0x3f')]=_[_0xf326('0x2b')](_0x1e27c3[_0xf326('0x3f')],{'$or':_[_0xf326('0x32')](_0x2b8de6,function(_0x5a5faf){if(_0x5a5faf['type']!==_0xf326('0x41')){var _0x128d71={};_0x128d71[_0x5a5faf[_0xf326('0x28')]]={'$like':'%'+_0x5e58e6[_0xf326('0x37')]['filter']+'%'};return _0x128d71;}})});}_0x1e27c3=_['merge']({},_0x1e27c3,_0x5e58e6[_0xf326('0x42')]);var _0x1827bd={'where':_0x1e27c3[_0xf326('0x3f')]};return db[_0xf326('0x43')][_0xf326('0x1e')](_0x1827bd)[_0xf326('0x23')](function(_0x163d9d){_0x11ba75[_0xf326('0x1e')]=_0x163d9d;if(_0x5e58e6[_0xf326('0x37')][_0xf326('0x44')]){_0x1e27c3['include']=[{'all':!![]}];}return db[_0xf326('0x43')][_0xf326('0x45')](_0x1e27c3);})[_0xf326('0x23')](function(_0x4e8630){_0x11ba75[_0xf326('0x46')]=_0x4e8630;return _0x11ba75;})['then'](respondWithFilteredResult(_0x2bede6,_0x1e27c3))[_0xf326('0x47')](handleError(_0x2bede6,null));};exports[_0xf326('0x48')]=function(_0x26690f,_0x1292d0){var _0x4f1554={'raw':!![],'where':{'id':_0x26690f[_0xf326('0x49')]['id']}},_0x704b2a={};_0x704b2a[_0xf326('0x3b')]=_['keys'](db[_0xf326('0x43')]['rawAttributes']);_0x704b2a[_0xf326('0x37')]=_[_0xf326('0x36')](_0x26690f[_0xf326('0x37')]);_0x704b2a[_0xf326('0x38')]=_['intersection'](_0x704b2a['model'],_0x704b2a[_0xf326('0x37')]);_0x4f1554[_0xf326('0x3a')]=_[_0xf326('0x39')](_0x704b2a[_0xf326('0x3b')],qs[_0xf326('0x3c')](_0x26690f[_0xf326('0x37')]['fields']));_0x4f1554[_0xf326('0x3a')]=_0x4f1554[_0xf326('0x3a')][_0xf326('0x3d')]?_0x4f1554[_0xf326('0x3a')]:_0x704b2a[_0xf326('0x3b')];if(_0x26690f[_0xf326('0x37')][_0xf326('0x44')]){_0x4f1554['include']=[{'all':!![]}];}_0x4f1554=_[_0xf326('0x2b')]({},_0x4f1554,_0x26690f[_0xf326('0x42')]);return db[_0xf326('0x43')][_0xf326('0x4a')](_0x4f1554)[_0xf326('0x23')](handleEntityNotFound(_0x1292d0,null))['then'](respondWithResult(_0x1292d0,null))[_0xf326('0x47')](handleError(_0x1292d0,null));};exports['create']=function(_0x8bc9a7,_0x2cf8b0){return db[_0xf326('0x43')][_0xf326('0x4b')](_0x8bc9a7[_0xf326('0x2c')],{})[_0xf326('0x23')](respondWithResult(_0x2cf8b0,0xc9))[_0xf326('0x47')](handleError(_0x2cf8b0,null));};exports[_0xf326('0x22')]=function(_0x574bcc,_0x358f5a){if(_0x574bcc[_0xf326('0x2c')]['id']){delete _0x574bcc[_0xf326('0x2c')]['id'];}return db[_0xf326('0x43')][_0xf326('0x4a')]({'where':{'id':_0x574bcc[_0xf326('0x49')]['id']}})['then'](handleEntityNotFound(_0x358f5a,null))[_0xf326('0x23')](saveUpdates(_0x574bcc[_0xf326('0x2c')],null))[_0xf326('0x23')](respondWithResult(_0x358f5a,null))['catch'](handleError(_0x358f5a,null));};exports[_0xf326('0x24')]=function(_0x1d56c4,_0x4f1ef2){return db['SquareMessage'][_0xf326('0x4a')]({'where':{'id':_0x1d56c4[_0xf326('0x49')]['id']}})[_0xf326('0x23')](handleEntityNotFound(_0x4f1ef2,null))[_0xf326('0x23')](removeEntity(_0x4f1ef2,null))[_0xf326('0x47')](handleError(_0x4f1ef2,null));};