27d0efa46c75405973f56a5f3ee11f9b439c5223
[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 _0x094f=['mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','update','destroy','then','end','sendStatus','error','stack','name','map','SquareMessage','rawAttributes','type','keys','query','filters','intersection','model','attributes','fields','length','order','sort','where','pick','filter','merge','options','includeAll','include','rows','catch','show','params','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird'];(function(_0x397e5f,_0x454c8f){var _0x5302b8=function(_0x1a29ef){while(--_0x1a29ef){_0x397e5f['push'](_0x397e5f['shift']());}};_0x5302b8(++_0x454c8f);}(_0x094f,0x80));var _0xf094=function(_0x396466,_0xe9857b){_0x396466=_0x396466-0x0;var _0x5e9ab4=_0x094f[_0x396466];return _0x5e9ab4;};'use strict';var emlformat=require(_0xf094('0x0'));var rimraf=require(_0xf094('0x1'));var zipdir=require(_0xf094('0x2'));var jsonpatch=require(_0xf094('0x3'));var rp=require('request-promise');var moment=require(_0xf094('0x4'));var BPromise=require(_0xf094('0x5'));var Mustache=require(_0xf094('0x6'));var util=require('util');var path=require('path');var sox=require(_0xf094('0x7'));var csv=require(_0xf094('0x8'));var ejs=require(_0xf094('0x9'));var fs=require('fs');var fs_extra=require(_0xf094('0xa'));var _=require(_0xf094('0xb'));var squel=require(_0xf094('0xc'));var crypto=require(_0xf094('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf094('0xe'));var authService=require(_0xf094('0xf'));var qs=require(_0xf094('0x10'));var as=require(_0xf094('0x11'));var hardwareService=require(_0xf094('0x12'));var logger=require('../../config/logger')(_0xf094('0x13'));var utils=require(_0xf094('0x14'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x41d385,_0x4d99bd){_0x4d99bd=_0x4d99bd||0xcc;return function(_0x583a23){if(_0x583a23){return _0x41d385['sendStatus'](_0x4d99bd);}return _0x41d385[_0xf094('0x15')](_0x4d99bd)['end']();};}function respondWithResult(_0x4b97cb,_0x32f64d){_0x32f64d=_0x32f64d||0xc8;return function(_0x29d688){if(_0x29d688){return _0x4b97cb[_0xf094('0x15')](_0x32f64d)[_0xf094('0x16')](_0x29d688);}};}function respondWithFilteredResult(_0x13471a,_0x187460){return function(_0x51f2af){if(_0x51f2af){var _0x47ecb1=typeof _0x187460[_0xf094('0x17')]===_0xf094('0x18')&&typeof _0x187460[_0xf094('0x19')]===_0xf094('0x18');var _0x2be8d0=_0x51f2af[_0xf094('0x1a')];var _0x584e99=_0x47ecb1?0x0:_0x187460[_0xf094('0x17')];var _0x45542d=_0x47ecb1?_0x51f2af[_0xf094('0x1a')]:_0x187460['offset']+_0x187460['limit'];var _0x5ec15d;if(_0x45542d>=_0x2be8d0){_0x45542d=_0x2be8d0;_0x5ec15d=0xc8;}else{_0x5ec15d=0xce;}_0x13471a['status'](_0x5ec15d);return _0x13471a[_0xf094('0x1b')](_0xf094('0x1c'),_0x584e99+'-'+_0x45542d+'/'+_0x2be8d0)[_0xf094('0x16')](_0x51f2af);}return null;};}function patchUpdates(_0x4e601d){return function(_0x109a0f){try{jsonpatch[_0xf094('0x1d')](_0x109a0f,_0x4e601d,!![]);}catch(_0x7b77b8){return BPromise[_0xf094('0x1e')](_0x7b77b8);}return _0x109a0f['save']();};}function saveUpdates(_0x3aff2f,_0x2db49d){return function(_0x5e9de5){if(_0x5e9de5){return _0x5e9de5[_0xf094('0x1f')](_0x3aff2f)['then'](function(_0x3a9fe3){return _0x3a9fe3;});}return null;};}function removeEntity(_0x4f74af,_0x2e0c75){return function(_0xbf4029){if(_0xbf4029){return _0xbf4029[_0xf094('0x20')]()[_0xf094('0x21')](function(){_0x4f74af[_0xf094('0x15')](0xcc)[_0xf094('0x22')]();});}};}function handleEntityNotFound(_0x51f7f4,_0x5f44ff){return function(_0xaf91fa){if(!_0xaf91fa){_0x51f7f4[_0xf094('0x23')](0x194);}return _0xaf91fa;};}function handleError(_0x5621d8,_0x14016c){_0x14016c=_0x14016c||0x1f4;return function(_0xc1ff00){logger[_0xf094('0x24')](_0xc1ff00[_0xf094('0x25')]);if(_0xc1ff00[_0xf094('0x26')]){delete _0xc1ff00['name'];}_0x5621d8[_0xf094('0x15')](_0x14016c)['send'](_0xc1ff00);};}exports['index']=function(_0xfef319,_0x32f5ca){var _0x211faa={},_0x112415={},_0x5537cf={'count':0x0,'rows':[]};var _0x4a7575=_[_0xf094('0x27')](db[_0xf094('0x28')][_0xf094('0x29')],function(_0xcc5640){return{'name':_0xcc5640['fieldName'],'type':_0xcc5640[_0xf094('0x2a')]['key']};});_0x112415['model']=_[_0xf094('0x27')](_0x4a7575,_0xf094('0x26'));_0x112415['query']=_[_0xf094('0x2b')](_0xfef319[_0xf094('0x2c')]);_0x112415[_0xf094('0x2d')]=_[_0xf094('0x2e')](_0x112415[_0xf094('0x2f')],_0x112415[_0xf094('0x2c')]);_0x211faa[_0xf094('0x30')]=_[_0xf094('0x2e')](_0x112415['model'],qs[_0xf094('0x31')](_0xfef319[_0xf094('0x2c')][_0xf094('0x31')]));_0x211faa[_0xf094('0x30')]=_0x211faa['attributes'][_0xf094('0x32')]?_0x211faa['attributes']:_0x112415['model'];if(!_0xfef319[_0xf094('0x2c')]['hasOwnProperty']('nolimit')){_0x211faa[_0xf094('0x19')]=qs[_0xf094('0x19')](_0xfef319[_0xf094('0x2c')][_0xf094('0x19')]);_0x211faa[_0xf094('0x17')]=qs[_0xf094('0x17')](_0xfef319[_0xf094('0x2c')][_0xf094('0x17')]);}_0x211faa[_0xf094('0x33')]=qs[_0xf094('0x34')](_0xfef319[_0xf094('0x2c')]['sort']);_0x211faa[_0xf094('0x35')]=qs[_0xf094('0x2d')](_[_0xf094('0x36')](_0xfef319[_0xf094('0x2c')],_0x112415[_0xf094('0x2d')]),_0x4a7575);if(_0xfef319[_0xf094('0x2c')][_0xf094('0x37')]){_0x211faa['where']=_[_0xf094('0x38')](_0x211faa[_0xf094('0x35')],{'$or':_[_0xf094('0x27')](_0x4a7575,function(_0x5320d6){if(_0x5320d6[_0xf094('0x2a')]!=='VIRTUAL'){var _0x281e56={};_0x281e56[_0x5320d6[_0xf094('0x26')]]={'$like':'%'+_0xfef319['query'][_0xf094('0x37')]+'%'};return _0x281e56;}})});}_0x211faa=_[_0xf094('0x38')]({},_0x211faa,_0xfef319[_0xf094('0x39')]);var _0x46c703={'where':_0x211faa[_0xf094('0x35')]};return db[_0xf094('0x28')][_0xf094('0x1a')](_0x46c703)[_0xf094('0x21')](function(_0xb92643){_0x5537cf['count']=_0xb92643;if(_0xfef319['query'][_0xf094('0x3a')]){_0x211faa[_0xf094('0x3b')]=[{'all':!![]}];}return db['SquareMessage']['findAll'](_0x211faa);})[_0xf094('0x21')](function(_0x306812){_0x5537cf[_0xf094('0x3c')]=_0x306812;return _0x5537cf;})['then'](respondWithFilteredResult(_0x32f5ca,_0x211faa))[_0xf094('0x3d')](handleError(_0x32f5ca,null));};exports[_0xf094('0x3e')]=function(_0x4da2b2,_0x1ce616){var _0x1090c2={'raw':!![],'where':{'id':_0x4da2b2[_0xf094('0x3f')]['id']}},_0x237b59={};_0x237b59[_0xf094('0x2f')]=_[_0xf094('0x2b')](db['SquareMessage']['rawAttributes']);_0x237b59[_0xf094('0x2c')]=_['keys'](_0x4da2b2['query']);_0x237b59[_0xf094('0x2d')]=_[_0xf094('0x2e')](_0x237b59[_0xf094('0x2f')],_0x237b59['query']);_0x1090c2['attributes']=_[_0xf094('0x2e')](_0x237b59[_0xf094('0x2f')],qs[_0xf094('0x31')](_0x4da2b2[_0xf094('0x2c')][_0xf094('0x31')]));_0x1090c2[_0xf094('0x30')]=_0x1090c2[_0xf094('0x30')]['length']?_0x1090c2[_0xf094('0x30')]:_0x237b59['model'];if(_0x4da2b2['query'][_0xf094('0x3a')]){_0x1090c2[_0xf094('0x3b')]=[{'all':!![]}];}_0x1090c2=_[_0xf094('0x38')]({},_0x1090c2,_0x4da2b2[_0xf094('0x39')]);return db[_0xf094('0x28')][_0xf094('0x40')](_0x1090c2)[_0xf094('0x21')](handleEntityNotFound(_0x1ce616,null))[_0xf094('0x21')](respondWithResult(_0x1ce616,null))['catch'](handleError(_0x1ce616,null));};exports[_0xf094('0x41')]=function(_0x33e906,_0x32370a){return db['SquareMessage']['create'](_0x33e906[_0xf094('0x42')],{})['then'](respondWithResult(_0x32370a,0xc9))[_0xf094('0x3d')](handleError(_0x32370a,null));};exports[_0xf094('0x1f')]=function(_0x30e70d,_0x1af84e){if(_0x30e70d[_0xf094('0x42')]['id']){delete _0x30e70d[_0xf094('0x42')]['id'];}return db[_0xf094('0x28')]['find']({'where':{'id':_0x30e70d[_0xf094('0x3f')]['id']}})['then'](handleEntityNotFound(_0x1af84e,null))[_0xf094('0x21')](saveUpdates(_0x30e70d['body'],null))[_0xf094('0x21')](respondWithResult(_0x1af84e,null))[_0xf094('0x3d')](handleError(_0x1af84e,null));};exports[_0xf094('0x20')]=function(_0x431cc2,_0x451847){return db[_0xf094('0x28')]['find']({'where':{'id':_0x431cc2[_0xf094('0x3f')]['id']}})[_0xf094('0x21')](handleEntityNotFound(_0x451847,null))['then'](removeEntity(_0x451847,null))[_0xf094('0x3d')](handleError(_0x451847,null));};