Built motion from commit b0a9a629.|2.6.33
[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 _0x6fba=['filters','pick','filter','where','VIRTUAL','merge','options','include','SquareMessage','findAll','show','includeAll','find','catch','create','body','update','params','destroy','moment','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','then','sendStatus','stack','name','send','map','fieldName','type','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit'];(function(_0x21c21a,_0x167fa3){var _0x2cc73c=function(_0x513b61){while(--_0x513b61){_0x21c21a['push'](_0x21c21a['shift']());}};_0x2cc73c(++_0x167fa3);}(_0x6fba,0x97));var _0xa6fb=function(_0x4e2ea2,_0x28aff7){_0x4e2ea2=_0x4e2ea2-0x0;var _0x171c09=_0x6fba[_0x4e2ea2];return _0x171c09;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xa6fb('0x0'));var BPromise=require(_0xa6fb('0x1'));var Mustache=require(_0xa6fb('0x2'));var util=require(_0xa6fb('0x3'));var path=require('path');var sox=require('sox');var csv=require(_0xa6fb('0x4'));var ejs=require(_0xa6fb('0x5'));var fs=require('fs');var fs_extra=require(_0xa6fb('0x6'));var _=require(_0xa6fb('0x7'));var squel=require(_0xa6fb('0x8'));var crypto=require(_0xa6fb('0x9'));var jsforce=require('jsforce');var deskjs=require(_0xa6fb('0xa'));var toCsv=require(_0xa6fb('0x4'));var querystring=require(_0xa6fb('0xb'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xa6fb('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0xa6fb('0xd'));var hardwareService=require(_0xa6fb('0xe'));var logger=require(_0xa6fb('0xf'))(_0xa6fb('0x10'));var utils=require(_0xa6fb('0x11'));var config=require('../../config/environment');var licenseUtil=require(_0xa6fb('0x12'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x506125,_0x32b785){_0x32b785=_0x32b785||0xcc;return function(_0xd02423){if(_0xd02423){return _0x506125['sendStatus'](_0x32b785);}return _0x506125[_0xa6fb('0x13')](_0x32b785)[_0xa6fb('0x14')]();};}function respondWithResult(_0x28ef89,_0x268bdc){_0x268bdc=_0x268bdc||0xc8;return function(_0x3396ef){if(_0x3396ef){return _0x28ef89[_0xa6fb('0x13')](_0x268bdc)['json'](_0x3396ef);}};}function respondWithFilteredResult(_0x3228c6,_0x40bd8e){return function(_0x3e7208){if(_0x3e7208){var _0x26a6d1=typeof _0x40bd8e[_0xa6fb('0x15')]===_0xa6fb('0x16')&&typeof _0x40bd8e[_0xa6fb('0x17')]===_0xa6fb('0x16');var _0x173498=_0x3e7208['count'];var _0x4fa149=_0x26a6d1?0x0:_0x40bd8e[_0xa6fb('0x15')];var _0x1b4bbe=_0x26a6d1?_0x3e7208[_0xa6fb('0x18')]:_0x40bd8e[_0xa6fb('0x15')]+_0x40bd8e[_0xa6fb('0x17')];var _0x4c37dd;if(_0x1b4bbe>=_0x173498){_0x1b4bbe=_0x173498;_0x4c37dd=0xc8;}else{_0x4c37dd=0xce;}_0x3228c6[_0xa6fb('0x13')](_0x4c37dd);return _0x3228c6[_0xa6fb('0x19')](_0xa6fb('0x1a'),_0x4fa149+'-'+_0x1b4bbe+'/'+_0x173498)[_0xa6fb('0x1b')](_0x3e7208);}return null;};}function patchUpdates(_0x4d9514){return function(_0x1f06cf){try{jsonpatch[_0xa6fb('0x1c')](_0x1f06cf,_0x4d9514,!![]);}catch(_0x276fa4){return BPromise[_0xa6fb('0x1d')](_0x276fa4);}return _0x1f06cf['save']();};}function saveUpdates(_0x40d761,_0x36fbd5){return function(_0x7a324d){if(_0x7a324d){return _0x7a324d['update'](_0x40d761)[_0xa6fb('0x1e')](function(_0xf331b6){return _0xf331b6;});}return null;};}function removeEntity(_0xcd0ef8,_0x5533f9){return function(_0x4be3e9){if(_0x4be3e9){return _0x4be3e9['destroy']()[_0xa6fb('0x1e')](function(){_0xcd0ef8['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x26be24,_0x35aef6){return function(_0x5bbb08){if(!_0x5bbb08){_0x26be24[_0xa6fb('0x1f')](0x194);}return _0x5bbb08;};}function handleError(_0x3b2585,_0x19a7e2){_0x19a7e2=_0x19a7e2||0x1f4;return function(_0x1414b6){logger['error'](_0x1414b6[_0xa6fb('0x20')]);if(_0x1414b6[_0xa6fb('0x21')]){delete _0x1414b6[_0xa6fb('0x21')];}_0x3b2585[_0xa6fb('0x13')](_0x19a7e2)[_0xa6fb('0x22')](_0x1414b6);};}exports['index']=function(_0x209aef,_0x4f178e){var _0x18d8f8={},_0x178ec6={},_0x131ea5={'count':0x0,'rows':[]};var _0x11120c=_[_0xa6fb('0x23')](db['SquareMessage']['rawAttributes'],function(_0x11054d){return{'name':_0x11054d[_0xa6fb('0x24')],'type':_0x11054d[_0xa6fb('0x25')]['key']};});_0x178ec6[_0xa6fb('0x26')]=_['map'](_0x11120c,_0xa6fb('0x21'));_0x178ec6[_0xa6fb('0x27')]=_[_0xa6fb('0x28')](_0x209aef['query']);_0x178ec6['filters']=_[_0xa6fb('0x29')](_0x178ec6[_0xa6fb('0x26')],_0x178ec6['query']);_0x18d8f8[_0xa6fb('0x2a')]=_['intersection'](_0x178ec6[_0xa6fb('0x26')],qs[_0xa6fb('0x2b')](_0x209aef[_0xa6fb('0x27')][_0xa6fb('0x2b')]));_0x18d8f8['attributes']=_0x18d8f8['attributes'][_0xa6fb('0x2c')]?_0x18d8f8['attributes']:_0x178ec6[_0xa6fb('0x26')];if(!_0x209aef[_0xa6fb('0x27')][_0xa6fb('0x2d')](_0xa6fb('0x2e'))){_0x18d8f8[_0xa6fb('0x17')]=qs['limit'](_0x209aef[_0xa6fb('0x27')][_0xa6fb('0x17')]);_0x18d8f8[_0xa6fb('0x15')]=qs[_0xa6fb('0x15')](_0x209aef[_0xa6fb('0x27')][_0xa6fb('0x15')]);}_0x18d8f8['order']=qs['sort'](_0x209aef[_0xa6fb('0x27')]['sort']);_0x18d8f8['where']=qs[_0xa6fb('0x2f')](_[_0xa6fb('0x30')](_0x209aef[_0xa6fb('0x27')],_0x178ec6[_0xa6fb('0x2f')]),_0x11120c);if(_0x209aef['query'][_0xa6fb('0x31')]){_0x18d8f8[_0xa6fb('0x32')]=_['merge'](_0x18d8f8['where'],{'$or':_['map'](_0x11120c,function(_0x16473f){if(_0x16473f[_0xa6fb('0x25')]!==_0xa6fb('0x33')){var _0x23198d={};_0x23198d[_0x16473f[_0xa6fb('0x21')]]={'$like':'%'+_0x209aef[_0xa6fb('0x27')][_0xa6fb('0x31')]+'%'};return _0x23198d;}})});}_0x18d8f8=_[_0xa6fb('0x34')]({},_0x18d8f8,_0x209aef[_0xa6fb('0x35')]);var _0x4b32ef={'where':_0x18d8f8[_0xa6fb('0x32')]};return db['SquareMessage'][_0xa6fb('0x18')](_0x4b32ef)[_0xa6fb('0x1e')](function(_0x3a3e12){_0x131ea5[_0xa6fb('0x18')]=_0x3a3e12;if(_0x209aef[_0xa6fb('0x27')]['includeAll']){_0x18d8f8[_0xa6fb('0x36')]=[{'all':!![]}];}return db[_0xa6fb('0x37')][_0xa6fb('0x38')](_0x18d8f8);})[_0xa6fb('0x1e')](function(_0x1c339e){_0x131ea5['rows']=_0x1c339e;return _0x131ea5;})[_0xa6fb('0x1e')](respondWithFilteredResult(_0x4f178e,_0x18d8f8))['catch'](handleError(_0x4f178e,null));};exports[_0xa6fb('0x39')]=function(_0x357180,_0x2d9db4){var _0x2db059={'raw':!![],'where':{'id':_0x357180['params']['id']}},_0x38a3ab={};_0x38a3ab[_0xa6fb('0x26')]=_['keys'](db[_0xa6fb('0x37')]['rawAttributes']);_0x38a3ab[_0xa6fb('0x27')]=_['keys'](_0x357180['query']);_0x38a3ab['filters']=_[_0xa6fb('0x29')](_0x38a3ab['model'],_0x38a3ab['query']);_0x2db059[_0xa6fb('0x2a')]=_['intersection'](_0x38a3ab[_0xa6fb('0x26')],qs[_0xa6fb('0x2b')](_0x357180[_0xa6fb('0x27')][_0xa6fb('0x2b')]));_0x2db059['attributes']=_0x2db059[_0xa6fb('0x2a')]['length']?_0x2db059['attributes']:_0x38a3ab['model'];if(_0x357180[_0xa6fb('0x27')][_0xa6fb('0x3a')]){_0x2db059[_0xa6fb('0x36')]=[{'all':!![]}];}_0x2db059=_[_0xa6fb('0x34')]({},_0x2db059,_0x357180[_0xa6fb('0x35')]);return db[_0xa6fb('0x37')][_0xa6fb('0x3b')](_0x2db059)['then'](handleEntityNotFound(_0x2d9db4,null))[_0xa6fb('0x1e')](respondWithResult(_0x2d9db4,null))[_0xa6fb('0x3c')](handleError(_0x2d9db4,null));};exports[_0xa6fb('0x3d')]=function(_0x152115,_0x5dcfb0){return db[_0xa6fb('0x37')][_0xa6fb('0x3d')](_0x152115[_0xa6fb('0x3e')],{})[_0xa6fb('0x1e')](respondWithResult(_0x5dcfb0,0xc9))['catch'](handleError(_0x5dcfb0,null));};exports[_0xa6fb('0x3f')]=function(_0x7bcdcc,_0x25682a){if(_0x7bcdcc['body']['id']){delete _0x7bcdcc[_0xa6fb('0x3e')]['id'];}return db[_0xa6fb('0x37')]['find']({'where':{'id':_0x7bcdcc[_0xa6fb('0x40')]['id']}})[_0xa6fb('0x1e')](handleEntityNotFound(_0x25682a,null))[_0xa6fb('0x1e')](saveUpdates(_0x7bcdcc[_0xa6fb('0x3e')],null))[_0xa6fb('0x1e')](respondWithResult(_0x25682a,null))[_0xa6fb('0x3c')](handleError(_0x25682a,null));};exports[_0xa6fb('0x41')]=function(_0xf4b4b0,_0x23a44f){return db[_0xa6fb('0x37')]['find']({'where':{'id':_0xf4b4b0[_0xa6fb('0x40')]['id']}})['then'](handleEntityNotFound(_0x23a44f,null))[_0xa6fb('0x1e')](removeEntity(_0x23a44f,null))[_0xa6fb('0x3c')](handleError(_0x23a44f,null));};