Built motion from commit c0cdc9d8.|2.6.28
[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 _0xa702=['zip-dir','fast-json-patch','request-promise','bluebird','path','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','json','undefined','limit','count','offset','Content-Range','apply','reject','update','then','destroy','end','error','name','send','map','rawAttributes','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','merge','type','options','includeAll','include','SquareMessage','findAll','rows','catch','show','params','create','body','find','eml-format','rimraf'];(function(_0x2601b4,_0x315e78){var _0x3e3661=function(_0x13b45b){while(--_0x13b45b){_0x2601b4['push'](_0x2601b4['shift']());}};_0x3e3661(++_0x315e78);}(_0xa702,0x1ae));var _0x2a70=function(_0x3437b5,_0x2bc627){_0x3437b5=_0x3437b5-0x0;var _0x56bf67=_0xa702[_0x3437b5];return _0x56bf67;};'use strict';var emlformat=require(_0x2a70('0x0'));var rimraf=require(_0x2a70('0x1'));var zipdir=require(_0x2a70('0x2'));var jsonpatch=require(_0x2a70('0x3'));var rp=require(_0x2a70('0x4'));var moment=require('moment');var BPromise=require(_0x2a70('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x2a70('0x6'));var sox=require('sox');var csv=require(_0x2a70('0x7'));var ejs=require(_0x2a70('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x2a70('0x9'));var crypto=require(_0x2a70('0xa'));var jsforce=require('jsforce');var deskjs=require(_0x2a70('0xb'));var toCsv=require('to-csv');var querystring=require(_0x2a70('0xc'));var Papa=require(_0x2a70('0xd'));var Redis=require(_0x2a70('0xe'));var authService=require(_0x2a70('0xf'));var qs=require(_0x2a70('0x10'));var as=require(_0x2a70('0x11'));var hardwareService=require(_0x2a70('0x12'));var logger=require(_0x2a70('0x13'))(_0x2a70('0x14'));var utils=require(_0x2a70('0x15'));var config=require(_0x2a70('0x16'));var licenseUtil=require(_0x2a70('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1327f4,_0x255eaa){_0x255eaa=_0x255eaa||0xcc;return function(_0x49dc04){if(_0x49dc04){return _0x1327f4[_0x2a70('0x18')](_0x255eaa);}return _0x1327f4[_0x2a70('0x19')](_0x255eaa)['end']();};}function respondWithResult(_0xc0b867,_0x9587d8){_0x9587d8=_0x9587d8||0xc8;return function(_0x5562cb){if(_0x5562cb){return _0xc0b867[_0x2a70('0x19')](_0x9587d8)[_0x2a70('0x1a')](_0x5562cb);}};}function respondWithFilteredResult(_0x58c9a4,_0x46f840){return function(_0x2c5619){if(_0x2c5619){var _0x5d992a=typeof _0x46f840['offset']===_0x2a70('0x1b')&&typeof _0x46f840[_0x2a70('0x1c')]===_0x2a70('0x1b');var _0xaca16b=_0x2c5619[_0x2a70('0x1d')];var _0x550ea0=_0x5d992a?0x0:_0x46f840[_0x2a70('0x1e')];var _0x2c59fe=_0x5d992a?_0x2c5619['count']:_0x46f840['offset']+_0x46f840[_0x2a70('0x1c')];var _0x4abbf9;if(_0x2c59fe>=_0xaca16b){_0x2c59fe=_0xaca16b;_0x4abbf9=0xc8;}else{_0x4abbf9=0xce;}_0x58c9a4[_0x2a70('0x19')](_0x4abbf9);return _0x58c9a4['set'](_0x2a70('0x1f'),_0x550ea0+'-'+_0x2c59fe+'/'+_0xaca16b)[_0x2a70('0x1a')](_0x2c5619);}return null;};}function patchUpdates(_0x1b7764){return function(_0x29fbf3){try{jsonpatch[_0x2a70('0x20')](_0x29fbf3,_0x1b7764,!![]);}catch(_0x395057){return BPromise[_0x2a70('0x21')](_0x395057);}return _0x29fbf3['save']();};}function saveUpdates(_0x558436,_0x932b18){return function(_0x5cdac3){if(_0x5cdac3){return _0x5cdac3[_0x2a70('0x22')](_0x558436)[_0x2a70('0x23')](function(_0x10bc80){return _0x10bc80;});}return null;};}function removeEntity(_0xe2a027,_0x3de817){return function(_0x1ef985){if(_0x1ef985){return _0x1ef985[_0x2a70('0x24')]()[_0x2a70('0x23')](function(){_0xe2a027[_0x2a70('0x19')](0xcc)[_0x2a70('0x25')]();});}};}function handleEntityNotFound(_0xf3d89e,_0x61a342){return function(_0x530b1b){if(!_0x530b1b){_0xf3d89e['sendStatus'](0x194);}return _0x530b1b;};}function handleError(_0x38208f,_0x163061){_0x163061=_0x163061||0x1f4;return function(_0x220be7){logger[_0x2a70('0x26')](_0x220be7['stack']);if(_0x220be7[_0x2a70('0x27')]){delete _0x220be7[_0x2a70('0x27')];}_0x38208f[_0x2a70('0x19')](_0x163061)[_0x2a70('0x28')](_0x220be7);};}exports['index']=function(_0x588efc,_0x47dafe){var _0x18f571={},_0x57dae1={},_0x22fb1b={'count':0x0,'rows':[]};var _0x5bfe28=_[_0x2a70('0x29')](db['SquareMessage'][_0x2a70('0x2a')],function(_0x1aa897){return{'name':_0x1aa897['fieldName'],'type':_0x1aa897['type'][_0x2a70('0x2b')]};});_0x57dae1[_0x2a70('0x2c')]=_['map'](_0x5bfe28,_0x2a70('0x27'));_0x57dae1[_0x2a70('0x2d')]=_[_0x2a70('0x2e')](_0x588efc[_0x2a70('0x2d')]);_0x57dae1['filters']=_[_0x2a70('0x2f')](_0x57dae1[_0x2a70('0x2c')],_0x57dae1[_0x2a70('0x2d')]);_0x18f571[_0x2a70('0x30')]=_[_0x2a70('0x2f')](_0x57dae1[_0x2a70('0x2c')],qs[_0x2a70('0x31')](_0x588efc[_0x2a70('0x2d')]['fields']));_0x18f571['attributes']=_0x18f571[_0x2a70('0x30')][_0x2a70('0x32')]?_0x18f571['attributes']:_0x57dae1[_0x2a70('0x2c')];if(!_0x588efc[_0x2a70('0x2d')][_0x2a70('0x33')](_0x2a70('0x34'))){_0x18f571[_0x2a70('0x1c')]=qs[_0x2a70('0x1c')](_0x588efc[_0x2a70('0x2d')][_0x2a70('0x1c')]);_0x18f571[_0x2a70('0x1e')]=qs['offset'](_0x588efc[_0x2a70('0x2d')][_0x2a70('0x1e')]);}_0x18f571[_0x2a70('0x35')]=qs['sort'](_0x588efc[_0x2a70('0x2d')][_0x2a70('0x36')]);_0x18f571[_0x2a70('0x37')]=qs[_0x2a70('0x38')](_[_0x2a70('0x39')](_0x588efc[_0x2a70('0x2d')],_0x57dae1[_0x2a70('0x38')]),_0x5bfe28);if(_0x588efc[_0x2a70('0x2d')]['filter']){_0x18f571[_0x2a70('0x37')]=_[_0x2a70('0x3a')](_0x18f571[_0x2a70('0x37')],{'$or':_[_0x2a70('0x29')](_0x5bfe28,function(_0x7715ef){if(_0x7715ef[_0x2a70('0x3b')]!=='VIRTUAL'){var _0x2227f1={};_0x2227f1[_0x7715ef[_0x2a70('0x27')]]={'$like':'%'+_0x588efc[_0x2a70('0x2d')]['filter']+'%'};return _0x2227f1;}})});}_0x18f571=_[_0x2a70('0x3a')]({},_0x18f571,_0x588efc[_0x2a70('0x3c')]);var _0x5330d1={'where':_0x18f571['where']};return db['SquareMessage'][_0x2a70('0x1d')](_0x5330d1)[_0x2a70('0x23')](function(_0x3979b9){_0x22fb1b['count']=_0x3979b9;if(_0x588efc[_0x2a70('0x2d')][_0x2a70('0x3d')]){_0x18f571[_0x2a70('0x3e')]=[{'all':!![]}];}return db[_0x2a70('0x3f')][_0x2a70('0x40')](_0x18f571);})['then'](function(_0x6c2295){_0x22fb1b[_0x2a70('0x41')]=_0x6c2295;return _0x22fb1b;})[_0x2a70('0x23')](respondWithFilteredResult(_0x47dafe,_0x18f571))[_0x2a70('0x42')](handleError(_0x47dafe,null));};exports[_0x2a70('0x43')]=function(_0xd1c3fb,_0x229ccc){var _0x848bc3={'raw':!![],'where':{'id':_0xd1c3fb[_0x2a70('0x44')]['id']}},_0xa0f46c={};_0xa0f46c[_0x2a70('0x2c')]=_[_0x2a70('0x2e')](db[_0x2a70('0x3f')][_0x2a70('0x2a')]);_0xa0f46c[_0x2a70('0x2d')]=_['keys'](_0xd1c3fb[_0x2a70('0x2d')]);_0xa0f46c[_0x2a70('0x38')]=_[_0x2a70('0x2f')](_0xa0f46c[_0x2a70('0x2c')],_0xa0f46c[_0x2a70('0x2d')]);_0x848bc3[_0x2a70('0x30')]=_[_0x2a70('0x2f')](_0xa0f46c[_0x2a70('0x2c')],qs[_0x2a70('0x31')](_0xd1c3fb['query']['fields']));_0x848bc3[_0x2a70('0x30')]=_0x848bc3[_0x2a70('0x30')][_0x2a70('0x32')]?_0x848bc3[_0x2a70('0x30')]:_0xa0f46c[_0x2a70('0x2c')];if(_0xd1c3fb[_0x2a70('0x2d')][_0x2a70('0x3d')]){_0x848bc3['include']=[{'all':!![]}];}_0x848bc3=_[_0x2a70('0x3a')]({},_0x848bc3,_0xd1c3fb[_0x2a70('0x3c')]);return db[_0x2a70('0x3f')]['find'](_0x848bc3)[_0x2a70('0x23')](handleEntityNotFound(_0x229ccc,null))[_0x2a70('0x23')](respondWithResult(_0x229ccc,null))['catch'](handleError(_0x229ccc,null));};exports[_0x2a70('0x45')]=function(_0x5ea976,_0x36e110){return db[_0x2a70('0x3f')][_0x2a70('0x45')](_0x5ea976[_0x2a70('0x46')],{})[_0x2a70('0x23')](respondWithResult(_0x36e110,0xc9))['catch'](handleError(_0x36e110,null));};exports[_0x2a70('0x22')]=function(_0x332af1,_0x4bcb2f){if(_0x332af1[_0x2a70('0x46')]['id']){delete _0x332af1['body']['id'];}return db[_0x2a70('0x3f')][_0x2a70('0x47')]({'where':{'id':_0x332af1[_0x2a70('0x44')]['id']}})[_0x2a70('0x23')](handleEntityNotFound(_0x4bcb2f,null))['then'](saveUpdates(_0x332af1[_0x2a70('0x46')],null))['then'](respondWithResult(_0x4bcb2f,null))[_0x2a70('0x42')](handleError(_0x4bcb2f,null));};exports['destroy']=function(_0x4f7dea,_0x358bb3){return db[_0x2a70('0x3f')][_0x2a70('0x47')]({'where':{'id':_0x4f7dea[_0x2a70('0x44')]['id']}})[_0x2a70('0x23')](handleEntityNotFound(_0x358bb3,null))[_0x2a70('0x23')](removeEntity(_0x358bb3,null))[_0x2a70('0x42')](handleError(_0x358bb3,null));};