Built motion from commit 3a7e82ea.|2.6.29
[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 _0xe3b3=['../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','apply','reject','save','destroy','then','error','name','index','map','rawAttributes','type','key','model','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','sort','where','pick','filter','merge','options','SquareMessage','includeAll','include','findAll','rows','catch','show','params','length','update','body','find','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service'];(function(_0x20d9d1,_0xcf39d2){var _0x54f62a=function(_0x15859c){while(--_0x15859c){_0x20d9d1['push'](_0x20d9d1['shift']());}};_0x54f62a(++_0xcf39d2);}(_0xe3b3,0x1b3));var _0x3e3b=function(_0x25a1c3,_0x1269c2){_0x25a1c3=_0x25a1c3-0x0;var _0x305030=_0xe3b3[_0x25a1c3];return _0x305030;};'use strict';var emlformat=require(_0x3e3b('0x0'));var rimraf=require(_0x3e3b('0x1'));var zipdir=require(_0x3e3b('0x2'));var jsonpatch=require(_0x3e3b('0x3'));var rp=require(_0x3e3b('0x4'));var moment=require(_0x3e3b('0x5'));var BPromise=require(_0x3e3b('0x6'));var Mustache=require(_0x3e3b('0x7'));var util=require(_0x3e3b('0x8'));var path=require(_0x3e3b('0x9'));var sox=require('sox');var csv=require(_0x3e3b('0xa'));var ejs=require(_0x3e3b('0xb'));var fs=require('fs');var fs_extra=require(_0x3e3b('0xc'));var _=require('lodash');var squel=require(_0x3e3b('0xd'));var crypto=require(_0x3e3b('0xe'));var jsforce=require(_0x3e3b('0xf'));var deskjs=require(_0x3e3b('0x10'));var toCsv=require(_0x3e3b('0xa'));var querystring=require(_0x3e3b('0x11'));var Papa=require(_0x3e3b('0x12'));var Redis=require(_0x3e3b('0x13'));var authService=require(_0x3e3b('0x14'));var qs=require('../../components/parsers/qs');var as=require(_0x3e3b('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x3e3b('0x16'))(_0x3e3b('0x17'));var utils=require(_0x3e3b('0x18'));var config=require(_0x3e3b('0x19'));var licenseUtil=require(_0x3e3b('0x1a'));var db=require(_0x3e3b('0x1b'))['db'];function respondWithStatusCode(_0x1ae7a6,_0x471a74){_0x471a74=_0x471a74||0xcc;return function(_0x107dce){if(_0x107dce){return _0x1ae7a6[_0x3e3b('0x1c')](_0x471a74);}return _0x1ae7a6[_0x3e3b('0x1d')](_0x471a74)[_0x3e3b('0x1e')]();};}function respondWithResult(_0x19878a,_0x1cc39f){_0x1cc39f=_0x1cc39f||0xc8;return function(_0x43eb3a){if(_0x43eb3a){return _0x19878a[_0x3e3b('0x1d')](_0x1cc39f)[_0x3e3b('0x1f')](_0x43eb3a);}};}function respondWithFilteredResult(_0x4fffd3,_0x2a6d19){return function(_0x537e66){if(_0x537e66){var _0x45f5d5=typeof _0x2a6d19[_0x3e3b('0x20')]===_0x3e3b('0x21')&&typeof _0x2a6d19['limit']==='undefined';var _0x5f4e5d=_0x537e66[_0x3e3b('0x22')];var _0x3c9829=_0x45f5d5?0x0:_0x2a6d19[_0x3e3b('0x20')];var _0x35fc4e=_0x45f5d5?_0x537e66[_0x3e3b('0x22')]:_0x2a6d19[_0x3e3b('0x20')]+_0x2a6d19[_0x3e3b('0x23')];var _0x42d031;if(_0x35fc4e>=_0x5f4e5d){_0x35fc4e=_0x5f4e5d;_0x42d031=0xc8;}else{_0x42d031=0xce;}_0x4fffd3['status'](_0x42d031);return _0x4fffd3[_0x3e3b('0x24')]('Content-Range',_0x3c9829+'-'+_0x35fc4e+'/'+_0x5f4e5d)[_0x3e3b('0x1f')](_0x537e66);}return null;};}function patchUpdates(_0x1eb56f){return function(_0x1a096a){try{jsonpatch[_0x3e3b('0x25')](_0x1a096a,_0x1eb56f,!![]);}catch(_0x5a40fe){return BPromise[_0x3e3b('0x26')](_0x5a40fe);}return _0x1a096a[_0x3e3b('0x27')]();};}function saveUpdates(_0x567443,_0x1af87e){return function(_0xc1b47a){if(_0xc1b47a){return _0xc1b47a['update'](_0x567443)['then'](function(_0x5cba48){return _0x5cba48;});}return null;};}function removeEntity(_0x47660d,_0x1334df){return function(_0x15ec1c){if(_0x15ec1c){return _0x15ec1c[_0x3e3b('0x28')]()[_0x3e3b('0x29')](function(){_0x47660d[_0x3e3b('0x1d')](0xcc)[_0x3e3b('0x1e')]();});}};}function handleEntityNotFound(_0x2903aa,_0x1ab037){return function(_0x452be0){if(!_0x452be0){_0x2903aa[_0x3e3b('0x1c')](0x194);}return _0x452be0;};}function handleError(_0x29af34,_0x1ff8c0){_0x1ff8c0=_0x1ff8c0||0x1f4;return function(_0x7da1af){logger[_0x3e3b('0x2a')](_0x7da1af['stack']);if(_0x7da1af[_0x3e3b('0x2b')]){delete _0x7da1af[_0x3e3b('0x2b')];}_0x29af34[_0x3e3b('0x1d')](_0x1ff8c0)['send'](_0x7da1af);};}exports[_0x3e3b('0x2c')]=function(_0x59b061,_0x4588cd){var _0x4bb59f={},_0x5922bb={},_0xc15d5b={'count':0x0,'rows':[]};var _0x3262a4=_[_0x3e3b('0x2d')](db['SquareMessage'][_0x3e3b('0x2e')],function(_0x6ad43e){return{'name':_0x6ad43e['fieldName'],'type':_0x6ad43e[_0x3e3b('0x2f')][_0x3e3b('0x30')]};});_0x5922bb[_0x3e3b('0x31')]=_[_0x3e3b('0x2d')](_0x3262a4,'name');_0x5922bb[_0x3e3b('0x32')]=_[_0x3e3b('0x33')](_0x59b061[_0x3e3b('0x32')]);_0x5922bb[_0x3e3b('0x34')]=_[_0x3e3b('0x35')](_0x5922bb['model'],_0x5922bb[_0x3e3b('0x32')]);_0x4bb59f['attributes']=_[_0x3e3b('0x35')](_0x5922bb[_0x3e3b('0x31')],qs['fields'](_0x59b061[_0x3e3b('0x32')][_0x3e3b('0x36')]));_0x4bb59f['attributes']=_0x4bb59f[_0x3e3b('0x37')]['length']?_0x4bb59f[_0x3e3b('0x37')]:_0x5922bb[_0x3e3b('0x31')];if(!_0x59b061[_0x3e3b('0x32')][_0x3e3b('0x38')](_0x3e3b('0x39'))){_0x4bb59f[_0x3e3b('0x23')]=qs[_0x3e3b('0x23')](_0x59b061[_0x3e3b('0x32')]['limit']);_0x4bb59f[_0x3e3b('0x20')]=qs[_0x3e3b('0x20')](_0x59b061[_0x3e3b('0x32')]['offset']);}_0x4bb59f['order']=qs[_0x3e3b('0x3a')](_0x59b061[_0x3e3b('0x32')][_0x3e3b('0x3a')]);_0x4bb59f[_0x3e3b('0x3b')]=qs[_0x3e3b('0x34')](_[_0x3e3b('0x3c')](_0x59b061[_0x3e3b('0x32')],_0x5922bb[_0x3e3b('0x34')]),_0x3262a4);if(_0x59b061[_0x3e3b('0x32')]['filter']){_0x4bb59f[_0x3e3b('0x3b')]=_['merge'](_0x4bb59f[_0x3e3b('0x3b')],{'$or':_[_0x3e3b('0x2d')](_0x3262a4,function(_0x120844){if(_0x120844[_0x3e3b('0x2f')]!=='VIRTUAL'){var _0x2a48cb={};_0x2a48cb[_0x120844[_0x3e3b('0x2b')]]={'$like':'%'+_0x59b061[_0x3e3b('0x32')][_0x3e3b('0x3d')]+'%'};return _0x2a48cb;}})});}_0x4bb59f=_[_0x3e3b('0x3e')]({},_0x4bb59f,_0x59b061[_0x3e3b('0x3f')]);var _0x7a539e={'where':_0x4bb59f[_0x3e3b('0x3b')]};return db[_0x3e3b('0x40')]['count'](_0x7a539e)['then'](function(_0x460f33){_0xc15d5b[_0x3e3b('0x22')]=_0x460f33;if(_0x59b061[_0x3e3b('0x32')][_0x3e3b('0x41')]){_0x4bb59f[_0x3e3b('0x42')]=[{'all':!![]}];}return db['SquareMessage'][_0x3e3b('0x43')](_0x4bb59f);})[_0x3e3b('0x29')](function(_0x3e36e2){_0xc15d5b[_0x3e3b('0x44')]=_0x3e36e2;return _0xc15d5b;})[_0x3e3b('0x29')](respondWithFilteredResult(_0x4588cd,_0x4bb59f))[_0x3e3b('0x45')](handleError(_0x4588cd,null));};exports[_0x3e3b('0x46')]=function(_0x2ab6df,_0x1b032a){var _0xba3b07={'raw':!![],'where':{'id':_0x2ab6df[_0x3e3b('0x47')]['id']}},_0x3093f5={};_0x3093f5[_0x3e3b('0x31')]=_[_0x3e3b('0x33')](db[_0x3e3b('0x40')][_0x3e3b('0x2e')]);_0x3093f5[_0x3e3b('0x32')]=_['keys'](_0x2ab6df[_0x3e3b('0x32')]);_0x3093f5[_0x3e3b('0x34')]=_[_0x3e3b('0x35')](_0x3093f5[_0x3e3b('0x31')],_0x3093f5[_0x3e3b('0x32')]);_0xba3b07[_0x3e3b('0x37')]=_[_0x3e3b('0x35')](_0x3093f5['model'],qs[_0x3e3b('0x36')](_0x2ab6df['query'][_0x3e3b('0x36')]));_0xba3b07['attributes']=_0xba3b07[_0x3e3b('0x37')][_0x3e3b('0x48')]?_0xba3b07[_0x3e3b('0x37')]:_0x3093f5[_0x3e3b('0x31')];if(_0x2ab6df[_0x3e3b('0x32')][_0x3e3b('0x41')]){_0xba3b07['include']=[{'all':!![]}];}_0xba3b07=_[_0x3e3b('0x3e')]({},_0xba3b07,_0x2ab6df[_0x3e3b('0x3f')]);return db[_0x3e3b('0x40')]['find'](_0xba3b07)[_0x3e3b('0x29')](handleEntityNotFound(_0x1b032a,null))['then'](respondWithResult(_0x1b032a,null))[_0x3e3b('0x45')](handleError(_0x1b032a,null));};exports['create']=function(_0x429393,_0x81e619){return db[_0x3e3b('0x40')]['create'](_0x429393['body'],{})[_0x3e3b('0x29')](respondWithResult(_0x81e619,0xc9))[_0x3e3b('0x45')](handleError(_0x81e619,null));};exports[_0x3e3b('0x49')]=function(_0x333070,_0x947564){if(_0x333070[_0x3e3b('0x4a')]['id']){delete _0x333070[_0x3e3b('0x4a')]['id'];}return db[_0x3e3b('0x40')][_0x3e3b('0x4b')]({'where':{'id':_0x333070['params']['id']}})[_0x3e3b('0x29')](handleEntityNotFound(_0x947564,null))['then'](saveUpdates(_0x333070[_0x3e3b('0x4a')],null))[_0x3e3b('0x29')](respondWithResult(_0x947564,null))['catch'](handleError(_0x947564,null));};exports['destroy']=function(_0x5616fe,_0x40564d){return db[_0x3e3b('0x40')]['find']({'where':{'id':_0x5616fe[_0x3e3b('0x47')]['id']}})['then'](handleEntityNotFound(_0x40564d,null))[_0x3e3b('0x29')](removeEntity(_0x40564d,null))[_0x3e3b('0x45')](handleError(_0x40564d,null));};