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 _0x414f=['intersection','attributes','fields','hasOwnProperty','limit','order','sort','where','filters','pick','merge','map','type','VIRTUAL','filter','options','SquareMessage','includeAll','include','findAll','catch','params','length','find','create','body','update','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','apply','reject','save','then','destroy','error','stack','name','send','rawAttributes','fieldName','model','query','keys'];(function(_0x3f6368,_0x9ba37f){var _0x75cea4=function(_0x113196){while(--_0x113196){_0x3f6368['push'](_0x3f6368['shift']());}};_0x75cea4(++_0x9ba37f);}(_0x414f,0x13f));var _0xf414=function(_0x26f03d,_0x4866c2){_0x26f03d=_0x26f03d-0x0;var _0x42dc9f=_0x414f[_0x26f03d];return _0x42dc9f;};'use strict';var emlformat=require(_0xf414('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf414('0x1'));var jsonpatch=require(_0xf414('0x2'));var rp=require('request-promise');var moment=require(_0xf414('0x3'));var BPromise=require(_0xf414('0x4'));var Mustache=require(_0xf414('0x5'));var util=require(_0xf414('0x6'));var path=require(_0xf414('0x7'));var sox=require(_0xf414('0x8'));var csv=require(_0xf414('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf414('0xa'));var _=require('lodash');var squel=require(_0xf414('0xb'));var crypto=require(_0xf414('0xc'));var jsforce=require(_0xf414('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xf414('0xe'));var Papa=require(_0xf414('0xf'));var Redis=require(_0xf414('0x10'));var authService=require(_0xf414('0x11'));var qs=require(_0xf414('0x12'));var as=require(_0xf414('0x13'));var hardwareService=require(_0xf414('0x14'));var logger=require(_0xf414('0x15'))('api');var utils=require('../../config/utils');var config=require(_0xf414('0x16'));var licenseUtil=require(_0xf414('0x17'));var db=require(_0xf414('0x18'))['db'];function respondWithStatusCode(_0x396c30,_0x9be4f8){_0x9be4f8=_0x9be4f8||0xcc;return function(_0x488d03){if(_0x488d03){return _0x396c30[_0xf414('0x19')](_0x9be4f8);}return _0x396c30[_0xf414('0x1a')](_0x9be4f8)[_0xf414('0x1b')]();};}function respondWithResult(_0x46d679,_0x99bbd1){_0x99bbd1=_0x99bbd1||0xc8;return function(_0x5da0b7){if(_0x5da0b7){return _0x46d679[_0xf414('0x1a')](_0x99bbd1)[_0xf414('0x1c')](_0x5da0b7);}};}function respondWithFilteredResult(_0x46fb28,_0x706d2e){return function(_0x4d3021){if(_0x4d3021){var _0x17125d=typeof _0x706d2e[_0xf414('0x1d')]===_0xf414('0x1e')&&typeof _0x706d2e['limit']===_0xf414('0x1e');var _0x452904=_0x4d3021[_0xf414('0x1f')];var _0x32e970=_0x17125d?0x0:_0x706d2e[_0xf414('0x1d')];var _0x4f9658=_0x17125d?_0x4d3021[_0xf414('0x1f')]:_0x706d2e['offset']+_0x706d2e['limit'];var _0x24b65e;if(_0x4f9658>=_0x452904){_0x4f9658=_0x452904;_0x24b65e=0xc8;}else{_0x24b65e=0xce;}_0x46fb28[_0xf414('0x1a')](_0x24b65e);return _0x46fb28['set']('Content-Range',_0x32e970+'-'+_0x4f9658+'/'+_0x452904)['json'](_0x4d3021);}return null;};}function patchUpdates(_0x3145ed){return function(_0x1ccfce){try{jsonpatch[_0xf414('0x20')](_0x1ccfce,_0x3145ed,!![]);}catch(_0x417af1){return BPromise[_0xf414('0x21')](_0x417af1);}return _0x1ccfce[_0xf414('0x22')]();};}function saveUpdates(_0x3bbbe8,_0x1e116c){return function(_0x1dbfa9){if(_0x1dbfa9){return _0x1dbfa9['update'](_0x3bbbe8)[_0xf414('0x23')](function(_0x3ae2a0){return _0x3ae2a0;});}return null;};}function removeEntity(_0x236504,_0x4999e4){return function(_0x8bd1d0){if(_0x8bd1d0){return _0x8bd1d0[_0xf414('0x24')]()[_0xf414('0x23')](function(){_0x236504[_0xf414('0x1a')](0xcc)[_0xf414('0x1b')]();});}};}function handleEntityNotFound(_0x398631,_0x1340d8){return function(_0x3f7a7d){if(!_0x3f7a7d){_0x398631['sendStatus'](0x194);}return _0x3f7a7d;};}function handleError(_0x2f9cb3,_0x564c66){_0x564c66=_0x564c66||0x1f4;return function(_0x47e0a1){logger[_0xf414('0x25')](_0x47e0a1[_0xf414('0x26')]);if(_0x47e0a1[_0xf414('0x27')]){delete _0x47e0a1[_0xf414('0x27')];}_0x2f9cb3[_0xf414('0x1a')](_0x564c66)[_0xf414('0x28')](_0x47e0a1);};}exports['index']=function(_0x53efd2,_0x306a1c){var _0x25b40f={},_0x209790={},_0x5e925b={'count':0x0,'rows':[]};var _0x433425=_['map'](db['SquareMessage'][_0xf414('0x29')],function(_0x8cf16c){return{'name':_0x8cf16c[_0xf414('0x2a')],'type':_0x8cf16c['type']['key']};});_0x209790[_0xf414('0x2b')]=_['map'](_0x433425,_0xf414('0x27'));_0x209790[_0xf414('0x2c')]=_[_0xf414('0x2d')](_0x53efd2[_0xf414('0x2c')]);_0x209790['filters']=_[_0xf414('0x2e')](_0x209790['model'],_0x209790['query']);_0x25b40f[_0xf414('0x2f')]=_[_0xf414('0x2e')](_0x209790[_0xf414('0x2b')],qs[_0xf414('0x30')](_0x53efd2[_0xf414('0x2c')][_0xf414('0x30')]));_0x25b40f[_0xf414('0x2f')]=_0x25b40f[_0xf414('0x2f')]['length']?_0x25b40f['attributes']:_0x209790[_0xf414('0x2b')];if(!_0x53efd2[_0xf414('0x2c')][_0xf414('0x31')]('nolimit')){_0x25b40f['limit']=qs[_0xf414('0x32')](_0x53efd2['query'][_0xf414('0x32')]);_0x25b40f['offset']=qs[_0xf414('0x1d')](_0x53efd2[_0xf414('0x2c')]['offset']);}_0x25b40f[_0xf414('0x33')]=qs[_0xf414('0x34')](_0x53efd2[_0xf414('0x2c')]['sort']);_0x25b40f[_0xf414('0x35')]=qs[_0xf414('0x36')](_[_0xf414('0x37')](_0x53efd2[_0xf414('0x2c')],_0x209790[_0xf414('0x36')]),_0x433425);if(_0x53efd2[_0xf414('0x2c')]['filter']){_0x25b40f[_0xf414('0x35')]=_[_0xf414('0x38')](_0x25b40f[_0xf414('0x35')],{'$or':_[_0xf414('0x39')](_0x433425,function(_0x21142c){if(_0x21142c[_0xf414('0x3a')]!==_0xf414('0x3b')){var _0xa0638a={};_0xa0638a[_0x21142c[_0xf414('0x27')]]={'$like':'%'+_0x53efd2['query'][_0xf414('0x3c')]+'%'};return _0xa0638a;}})});}_0x25b40f=_[_0xf414('0x38')]({},_0x25b40f,_0x53efd2[_0xf414('0x3d')]);var _0x16dd5e={'where':_0x25b40f[_0xf414('0x35')]};return db[_0xf414('0x3e')][_0xf414('0x1f')](_0x16dd5e)[_0xf414('0x23')](function(_0x248f7f){_0x5e925b[_0xf414('0x1f')]=_0x248f7f;if(_0x53efd2[_0xf414('0x2c')][_0xf414('0x3f')]){_0x25b40f[_0xf414('0x40')]=[{'all':!![]}];}return db[_0xf414('0x3e')][_0xf414('0x41')](_0x25b40f);})[_0xf414('0x23')](function(_0x43d141){_0x5e925b['rows']=_0x43d141;return _0x5e925b;})[_0xf414('0x23')](respondWithFilteredResult(_0x306a1c,_0x25b40f))[_0xf414('0x42')](handleError(_0x306a1c,null));};exports['show']=function(_0x29c5ef,_0x3c95e6){var _0x56c830={'raw':!![],'where':{'id':_0x29c5ef[_0xf414('0x43')]['id']}},_0x41706d={};_0x41706d[_0xf414('0x2b')]=_[_0xf414('0x2d')](db[_0xf414('0x3e')][_0xf414('0x29')]);_0x41706d[_0xf414('0x2c')]=_['keys'](_0x29c5ef[_0xf414('0x2c')]);_0x41706d[_0xf414('0x36')]=_[_0xf414('0x2e')](_0x41706d[_0xf414('0x2b')],_0x41706d[_0xf414('0x2c')]);_0x56c830[_0xf414('0x2f')]=_[_0xf414('0x2e')](_0x41706d[_0xf414('0x2b')],qs[_0xf414('0x30')](_0x29c5ef['query'][_0xf414('0x30')]));_0x56c830[_0xf414('0x2f')]=_0x56c830[_0xf414('0x2f')][_0xf414('0x44')]?_0x56c830['attributes']:_0x41706d['model'];if(_0x29c5ef[_0xf414('0x2c')][_0xf414('0x3f')]){_0x56c830['include']=[{'all':!![]}];}_0x56c830=_['merge']({},_0x56c830,_0x29c5ef[_0xf414('0x3d')]);return db[_0xf414('0x3e')][_0xf414('0x45')](_0x56c830)[_0xf414('0x23')](handleEntityNotFound(_0x3c95e6,null))[_0xf414('0x23')](respondWithResult(_0x3c95e6,null))[_0xf414('0x42')](handleError(_0x3c95e6,null));};exports[_0xf414('0x46')]=function(_0x269beb,_0x49ad21){return db[_0xf414('0x3e')][_0xf414('0x46')](_0x269beb[_0xf414('0x47')],{})[_0xf414('0x23')](respondWithResult(_0x49ad21,0xc9))[_0xf414('0x42')](handleError(_0x49ad21,null));};exports[_0xf414('0x48')]=function(_0x2670f5,_0x5c7ec1){if(_0x2670f5[_0xf414('0x47')]['id']){delete _0x2670f5[_0xf414('0x47')]['id'];}return db['SquareMessage'][_0xf414('0x45')]({'where':{'id':_0x2670f5[_0xf414('0x43')]['id']}})[_0xf414('0x23')](handleEntityNotFound(_0x5c7ec1,null))[_0xf414('0x23')](saveUpdates(_0x2670f5[_0xf414('0x47')],null))[_0xf414('0x23')](respondWithResult(_0x5c7ec1,null))['catch'](handleError(_0x5c7ec1,null));};exports[_0xf414('0x24')]=function(_0x5b5b69,_0x528379){return db[_0xf414('0x3e')][_0xf414('0x45')]({'where':{'id':_0x5b5b69[_0xf414('0x43')]['id']}})['then'](handleEntityNotFound(_0x528379,null))[_0xf414('0x23')](removeEntity(_0x528379,null))[_0xf414('0x42')](handleError(_0x528379,null));};