813ae0258617e50be02b9d23d42430ac35c27b5d
[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 _0xfc7c=['../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','status','end','offset','undefined','count','limit','set','save','update','then','destroy','error','stack','name','send','map','rawAttributes','fieldName','type','key','model','query','intersection','fields','attributes','hasOwnProperty','where','filters','filter','merge','SquareMessage','includeAll','include','findAll','rows','catch','show','params','keys','length','options','find','create','body','rimraf','fast-json-patch','request-promise','moment','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis'];(function(_0x3cd125,_0x1085cc){var _0x26b040=function(_0x162109){while(--_0x162109){_0x3cd125['push'](_0x3cd125['shift']());}};_0x26b040(++_0x1085cc);}(_0xfc7c,0x18d));var _0xcfc7=function(_0x3e0742,_0x11d62a){_0x3e0742=_0x3e0742-0x0;var _0x3da75a=_0xfc7c[_0x3e0742];return _0x3da75a;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xcfc7('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xcfc7('0x1'));var rp=require(_0xcfc7('0x2'));var moment=require(_0xcfc7('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xcfc7('0x4'));var util=require(_0xcfc7('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0xcfc7('0x6'));var ejs=require(_0xcfc7('0x7'));var fs=require('fs');var fs_extra=require(_0xcfc7('0x8'));var _=require(_0xcfc7('0x9'));var squel=require(_0xcfc7('0xa'));var crypto=require(_0xcfc7('0xb'));var jsforce=require(_0xcfc7('0xc'));var deskjs=require(_0xcfc7('0xd'));var toCsv=require(_0xcfc7('0x6'));var querystring=require(_0xcfc7('0xe'));var Papa=require(_0xcfc7('0xf'));var Redis=require(_0xcfc7('0x10'));var authService=require(_0xcfc7('0x11'));var qs=require(_0xcfc7('0x12'));var as=require(_0xcfc7('0x13'));var hardwareService=require(_0xcfc7('0x14'));var logger=require(_0xcfc7('0x15'))('api');var utils=require(_0xcfc7('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xcfc7('0x17'));var db=require(_0xcfc7('0x18'))['db'];function respondWithStatusCode(_0x26f712,_0x297b0d){_0x297b0d=_0x297b0d||0xcc;return function(_0x2f20de){if(_0x2f20de){return _0x26f712['sendStatus'](_0x297b0d);}return _0x26f712[_0xcfc7('0x19')](_0x297b0d)[_0xcfc7('0x1a')]();};}function respondWithResult(_0x946997,_0x50f9c8){_0x50f9c8=_0x50f9c8||0xc8;return function(_0x1be055){if(_0x1be055){return _0x946997['status'](_0x50f9c8)['json'](_0x1be055);}};}function respondWithFilteredResult(_0x4ba779,_0x5ddb57){return function(_0x3e539a){if(_0x3e539a){var _0x3cf374=typeof _0x5ddb57[_0xcfc7('0x1b')]===_0xcfc7('0x1c')&&typeof _0x5ddb57['limit']===_0xcfc7('0x1c');var _0x42e85e=_0x3e539a[_0xcfc7('0x1d')];var _0x2c445b=_0x3cf374?0x0:_0x5ddb57[_0xcfc7('0x1b')];var _0x449e8e=_0x3cf374?_0x3e539a[_0xcfc7('0x1d')]:_0x5ddb57['offset']+_0x5ddb57[_0xcfc7('0x1e')];var _0x42c161;if(_0x449e8e>=_0x42e85e){_0x449e8e=_0x42e85e;_0x42c161=0xc8;}else{_0x42c161=0xce;}_0x4ba779[_0xcfc7('0x19')](_0x42c161);return _0x4ba779[_0xcfc7('0x1f')]('Content-Range',_0x2c445b+'-'+_0x449e8e+'/'+_0x42e85e)['json'](_0x3e539a);}return null;};}function patchUpdates(_0x6e20a4){return function(_0x1c4a6e){try{jsonpatch['apply'](_0x1c4a6e,_0x6e20a4,!![]);}catch(_0x2bfee2){return BPromise['reject'](_0x2bfee2);}return _0x1c4a6e[_0xcfc7('0x20')]();};}function saveUpdates(_0x2ee75,_0xf61318){return function(_0xd0e656){if(_0xd0e656){return _0xd0e656[_0xcfc7('0x21')](_0x2ee75)[_0xcfc7('0x22')](function(_0x1f36ed){return _0x1f36ed;});}return null;};}function removeEntity(_0x1005ea,_0x45d94f){return function(_0x5b174a){if(_0x5b174a){return _0x5b174a[_0xcfc7('0x23')]()['then'](function(){_0x1005ea[_0xcfc7('0x19')](0xcc)[_0xcfc7('0x1a')]();});}};}function handleEntityNotFound(_0x2ab4f4,_0x1ca71a){return function(_0x50cf62){if(!_0x50cf62){_0x2ab4f4['sendStatus'](0x194);}return _0x50cf62;};}function handleError(_0x3a51a6,_0x8e3834){_0x8e3834=_0x8e3834||0x1f4;return function(_0x2f6b69){logger[_0xcfc7('0x24')](_0x2f6b69[_0xcfc7('0x25')]);if(_0x2f6b69[_0xcfc7('0x26')]){delete _0x2f6b69[_0xcfc7('0x26')];}_0x3a51a6[_0xcfc7('0x19')](_0x8e3834)[_0xcfc7('0x27')](_0x2f6b69);};}exports['index']=function(_0x19a56c,_0x51fda1){var _0xfd301={},_0xc08874={},_0x16b82a={'count':0x0,'rows':[]};var _0x153d20=_[_0xcfc7('0x28')](db['SquareMessage'][_0xcfc7('0x29')],function(_0x55005f){return{'name':_0x55005f[_0xcfc7('0x2a')],'type':_0x55005f[_0xcfc7('0x2b')][_0xcfc7('0x2c')]};});_0xc08874[_0xcfc7('0x2d')]=_[_0xcfc7('0x28')](_0x153d20,_0xcfc7('0x26'));_0xc08874[_0xcfc7('0x2e')]=_['keys'](_0x19a56c[_0xcfc7('0x2e')]);_0xc08874['filters']=_[_0xcfc7('0x2f')](_0xc08874[_0xcfc7('0x2d')],_0xc08874[_0xcfc7('0x2e')]);_0xfd301['attributes']=_[_0xcfc7('0x2f')](_0xc08874[_0xcfc7('0x2d')],qs[_0xcfc7('0x30')](_0x19a56c[_0xcfc7('0x2e')][_0xcfc7('0x30')]));_0xfd301[_0xcfc7('0x31')]=_0xfd301[_0xcfc7('0x31')]['length']?_0xfd301['attributes']:_0xc08874[_0xcfc7('0x2d')];if(!_0x19a56c[_0xcfc7('0x2e')][_0xcfc7('0x32')]('nolimit')){_0xfd301['limit']=qs[_0xcfc7('0x1e')](_0x19a56c[_0xcfc7('0x2e')][_0xcfc7('0x1e')]);_0xfd301[_0xcfc7('0x1b')]=qs['offset'](_0x19a56c[_0xcfc7('0x2e')][_0xcfc7('0x1b')]);}_0xfd301['order']=qs['sort'](_0x19a56c[_0xcfc7('0x2e')]['sort']);_0xfd301[_0xcfc7('0x33')]=qs[_0xcfc7('0x34')](_['pick'](_0x19a56c['query'],_0xc08874[_0xcfc7('0x34')]),_0x153d20);if(_0x19a56c['query'][_0xcfc7('0x35')]){_0xfd301[_0xcfc7('0x33')]=_['merge'](_0xfd301['where'],{'$or':_[_0xcfc7('0x28')](_0x153d20,function(_0x5d1247){if(_0x5d1247[_0xcfc7('0x2b')]!=='VIRTUAL'){var _0x17b8f7={};_0x17b8f7[_0x5d1247['name']]={'$like':'%'+_0x19a56c[_0xcfc7('0x2e')][_0xcfc7('0x35')]+'%'};return _0x17b8f7;}})});}_0xfd301=_[_0xcfc7('0x36')]({},_0xfd301,_0x19a56c['options']);var _0x1a8e1d={'where':_0xfd301[_0xcfc7('0x33')]};return db[_0xcfc7('0x37')][_0xcfc7('0x1d')](_0x1a8e1d)['then'](function(_0x341f0f){_0x16b82a[_0xcfc7('0x1d')]=_0x341f0f;if(_0x19a56c['query'][_0xcfc7('0x38')]){_0xfd301[_0xcfc7('0x39')]=[{'all':!![]}];}return db[_0xcfc7('0x37')][_0xcfc7('0x3a')](_0xfd301);})['then'](function(_0x5b6963){_0x16b82a[_0xcfc7('0x3b')]=_0x5b6963;return _0x16b82a;})[_0xcfc7('0x22')](respondWithFilteredResult(_0x51fda1,_0xfd301))[_0xcfc7('0x3c')](handleError(_0x51fda1,null));};exports[_0xcfc7('0x3d')]=function(_0xf5df2c,_0x1e5cae){var _0x40592a={'raw':!![],'where':{'id':_0xf5df2c[_0xcfc7('0x3e')]['id']}},_0xdf54d2={};_0xdf54d2['model']=_[_0xcfc7('0x3f')](db[_0xcfc7('0x37')]['rawAttributes']);_0xdf54d2[_0xcfc7('0x2e')]=_[_0xcfc7('0x3f')](_0xf5df2c[_0xcfc7('0x2e')]);_0xdf54d2[_0xcfc7('0x34')]=_[_0xcfc7('0x2f')](_0xdf54d2[_0xcfc7('0x2d')],_0xdf54d2[_0xcfc7('0x2e')]);_0x40592a[_0xcfc7('0x31')]=_[_0xcfc7('0x2f')](_0xdf54d2[_0xcfc7('0x2d')],qs['fields'](_0xf5df2c[_0xcfc7('0x2e')][_0xcfc7('0x30')]));_0x40592a[_0xcfc7('0x31')]=_0x40592a['attributes'][_0xcfc7('0x40')]?_0x40592a[_0xcfc7('0x31')]:_0xdf54d2['model'];if(_0xf5df2c[_0xcfc7('0x2e')][_0xcfc7('0x38')]){_0x40592a[_0xcfc7('0x39')]=[{'all':!![]}];}_0x40592a=_['merge']({},_0x40592a,_0xf5df2c[_0xcfc7('0x41')]);return db[_0xcfc7('0x37')][_0xcfc7('0x42')](_0x40592a)[_0xcfc7('0x22')](handleEntityNotFound(_0x1e5cae,null))[_0xcfc7('0x22')](respondWithResult(_0x1e5cae,null))[_0xcfc7('0x3c')](handleError(_0x1e5cae,null));};exports['create']=function(_0x2bd033,_0x4e0f36){return db[_0xcfc7('0x37')][_0xcfc7('0x43')](_0x2bd033['body'],{})[_0xcfc7('0x22')](respondWithResult(_0x4e0f36,0xc9))[_0xcfc7('0x3c')](handleError(_0x4e0f36,null));};exports[_0xcfc7('0x21')]=function(_0x46dd3c,_0x1cd994){if(_0x46dd3c[_0xcfc7('0x44')]['id']){delete _0x46dd3c[_0xcfc7('0x44')]['id'];}return db[_0xcfc7('0x37')]['find']({'where':{'id':_0x46dd3c[_0xcfc7('0x3e')]['id']}})['then'](handleEntityNotFound(_0x1cd994,null))['then'](saveUpdates(_0x46dd3c[_0xcfc7('0x44')],null))['then'](respondWithResult(_0x1cd994,null))[_0xcfc7('0x3c')](handleError(_0x1cd994,null));};exports[_0xcfc7('0x23')]=function(_0x425bd6,_0x5a73cb){return db[_0xcfc7('0x37')][_0xcfc7('0x42')]({'where':{'id':_0x425bd6[_0xcfc7('0x3e')]['id']}})[_0xcfc7('0x22')](handleEntityNotFound(_0x5a73cb,null))[_0xcfc7('0x22')](removeEntity(_0x5a73cb,null))['catch'](handleError(_0x5a73cb,null));};