910c5cc4f351ba55d650b1a5c5229f5ed8ed1dae
[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 _0x8201=['reject','save','update','then','stack','send','index','map','SquareMessage','rawAttributes','fieldName','type','model','name','keys','filters','attributes','intersection','fields','length','hasOwnProperty','query','order','sort','where','pick','filter','merge','VIRTUAL','options','count','include','findAll','catch','show','includeAll','find','create','body','params','destroy','html-pdf','zip-dir','request-promise','bluebird','mustache','path','sox','to-csv','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','offset','limit','Content-Range','json','apply'];(function(_0x11b8f8,_0x110c29){var _0x58c93c=function(_0x286b76){while(--_0x286b76){_0x11b8f8['push'](_0x11b8f8['shift']());}};_0x58c93c(++_0x110c29);}(_0x8201,0x71));var _0x1820=function(_0x1690c2,_0x462d33){_0x1690c2=_0x1690c2-0x0;var _0x193f13=_0x8201[_0x1690c2];return _0x193f13;};'use strict';var pdf=require(_0x1820('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x1820('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x1820('0x2'));var moment=require('moment');var BPromise=require(_0x1820('0x3'));var Mustache=require(_0x1820('0x4'));var util=require('util');var path=require(_0x1820('0x5'));var sox=require(_0x1820('0x6'));var csv=require(_0x1820('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x1820('0x8'));var squel=require(_0x1820('0x9'));var crypto=require('crypto');var jsforce=require(_0x1820('0xa'));var deskjs=require(_0x1820('0xb'));var toCsv=require(_0x1820('0x7'));var querystring=require(_0x1820('0xc'));var Papa=require(_0x1820('0xd'));var Redis=require(_0x1820('0xe'));var authService=require(_0x1820('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x1820('0x10'));var logger=require(_0x1820('0x11'))(_0x1820('0x12'));var utils=require(_0x1820('0x13'));var config=require(_0x1820('0x14'));var licenseUtil=require(_0x1820('0x15'));var db=require(_0x1820('0x16'))['db'];function respondWithStatusCode(_0x4b5920,_0x4fd81d){_0x4fd81d=_0x4fd81d||0xcc;return function(_0x57b825){if(_0x57b825){return _0x4b5920[_0x1820('0x17')](_0x4fd81d);}return _0x4b5920['status'](_0x4fd81d)[_0x1820('0x18')]();};}function respondWithResult(_0x448fd9,_0x230223){_0x230223=_0x230223||0xc8;return function(_0x5317cf){if(_0x5317cf){return _0x448fd9[_0x1820('0x19')](_0x230223)['json'](_0x5317cf);}};}function respondWithFilteredResult(_0x467d22,_0x28eef6){return function(_0x327479){if(_0x327479){var _0x20eb5e=_0x327479['count'],_0x5b3332=_0x28eef6[_0x1820('0x1a')],_0x416660=_0x28eef6[_0x1820('0x1a')]+_0x28eef6[_0x1820('0x1b')],_0x343387;if(_0x416660>=_0x20eb5e){_0x416660=_0x20eb5e;_0x343387=0xc8;}else{_0x343387=0xce;}_0x467d22[_0x1820('0x19')](_0x343387);return _0x467d22['set'](_0x1820('0x1c'),_0x5b3332+'-'+_0x416660+'/'+_0x20eb5e)[_0x1820('0x1d')](_0x327479);}return null;};}function patchUpdates(_0x149dcd){return function(_0x2f240f){try{jsonpatch[_0x1820('0x1e')](_0x2f240f,_0x149dcd,!![]);}catch(_0x343664){return BPromise[_0x1820('0x1f')](_0x343664);}return _0x2f240f[_0x1820('0x20')]();};}function saveUpdates(_0x56a36a,_0x14603d){return function(_0xd81af1){if(_0xd81af1){return _0xd81af1[_0x1820('0x21')](_0x56a36a)[_0x1820('0x22')](function(_0x5deef2){return _0x5deef2;});}return null;};}function removeEntity(_0x50db2b,_0x3dcdbb){return function(_0x3702ea){if(_0x3702ea){return _0x3702ea['destroy']()[_0x1820('0x22')](function(){_0x50db2b[_0x1820('0x19')](0xcc)[_0x1820('0x18')]();});}};}function handleEntityNotFound(_0xc7145b,_0x2d9074){return function(_0x485c71){if(!_0x485c71){_0xc7145b['sendStatus'](0x194);}return _0x485c71;};}function handleError(_0x4c93d4,_0x238070){_0x238070=_0x238070||0x1f4;return function(_0x55badd){logger['error'](_0x55badd[_0x1820('0x23')]);if(_0x55badd['name']){delete _0x55badd['name'];}_0x4c93d4[_0x1820('0x19')](_0x238070)[_0x1820('0x24')](_0x55badd);};}exports[_0x1820('0x25')]=function(_0x486b99,_0x4b7009){var _0x4f3f6e={},_0x4f5405={},_0x22eb1a={'count':0x0,'rows':[]};var _0x5e0581=_[_0x1820('0x26')](db[_0x1820('0x27')][_0x1820('0x28')],function(_0x12aa88){return{'name':_0x12aa88[_0x1820('0x29')],'type':_0x12aa88[_0x1820('0x2a')]['key']};});_0x4f5405[_0x1820('0x2b')]=_[_0x1820('0x26')](_0x5e0581,_0x1820('0x2c'));_0x4f5405['query']=_[_0x1820('0x2d')](_0x486b99['query']);_0x4f5405[_0x1820('0x2e')]=_['intersection'](_0x4f5405[_0x1820('0x2b')],_0x4f5405['query']);_0x4f3f6e[_0x1820('0x2f')]=_[_0x1820('0x30')](_0x4f5405['model'],qs[_0x1820('0x31')](_0x486b99['query'][_0x1820('0x31')]));_0x4f3f6e['attributes']=_0x4f3f6e[_0x1820('0x2f')][_0x1820('0x32')]?_0x4f3f6e[_0x1820('0x2f')]:_0x4f5405[_0x1820('0x2b')];if(!_0x486b99['query'][_0x1820('0x33')]('nolimit')){_0x4f3f6e[_0x1820('0x1b')]=qs[_0x1820('0x1b')](_0x486b99[_0x1820('0x34')]['limit']);_0x4f3f6e[_0x1820('0x1a')]=qs[_0x1820('0x1a')](_0x486b99[_0x1820('0x34')]['offset']);}_0x4f3f6e[_0x1820('0x35')]=qs[_0x1820('0x36')](_0x486b99['query']['sort']);_0x4f3f6e[_0x1820('0x37')]=qs[_0x1820('0x2e')](_[_0x1820('0x38')](_0x486b99[_0x1820('0x34')],_0x4f5405['filters']),_0x5e0581);if(_0x486b99[_0x1820('0x34')][_0x1820('0x39')]){_0x4f3f6e[_0x1820('0x37')]=_[_0x1820('0x3a')](_0x4f3f6e[_0x1820('0x37')],{'$or':_[_0x1820('0x26')](_0x5e0581,function(_0x7a83b7){if(_0x7a83b7['type']!==_0x1820('0x3b')){var _0x107b82={};_0x107b82[_0x7a83b7[_0x1820('0x2c')]]={'$like':'%'+_0x486b99[_0x1820('0x34')]['filter']+'%'};return _0x107b82;}})});}_0x4f3f6e=_[_0x1820('0x3a')]({},_0x4f3f6e,_0x486b99[_0x1820('0x3c')]);var _0x5b4656={'where':_0x4f3f6e[_0x1820('0x37')]};return db['SquareMessage']['count'](_0x5b4656)['then'](function(_0x53047b){_0x22eb1a[_0x1820('0x3d')]=_0x53047b;if(_0x486b99[_0x1820('0x34')]['includeAll']){_0x4f3f6e[_0x1820('0x3e')]=[{'all':!![]}];}return db[_0x1820('0x27')][_0x1820('0x3f')](_0x4f3f6e);})[_0x1820('0x22')](function(_0x5381de){_0x22eb1a['rows']=_0x5381de;return _0x22eb1a;})[_0x1820('0x22')](respondWithFilteredResult(_0x4b7009,_0x4f3f6e))[_0x1820('0x40')](handleError(_0x4b7009,null));};exports[_0x1820('0x41')]=function(_0x133b03,_0x3bf571){var _0x2c13bc={'raw':!![],'where':{'id':_0x133b03['params']['id']}},_0x3cb55c={};_0x3cb55c[_0x1820('0x2b')]=_[_0x1820('0x2d')](db[_0x1820('0x27')][_0x1820('0x28')]);_0x3cb55c['query']=_[_0x1820('0x2d')](_0x133b03[_0x1820('0x34')]);_0x3cb55c[_0x1820('0x2e')]=_[_0x1820('0x30')](_0x3cb55c[_0x1820('0x2b')],_0x3cb55c[_0x1820('0x34')]);_0x2c13bc[_0x1820('0x2f')]=_[_0x1820('0x30')](_0x3cb55c[_0x1820('0x2b')],qs['fields'](_0x133b03[_0x1820('0x34')][_0x1820('0x31')]));_0x2c13bc['attributes']=_0x2c13bc[_0x1820('0x2f')][_0x1820('0x32')]?_0x2c13bc[_0x1820('0x2f')]:_0x3cb55c[_0x1820('0x2b')];if(_0x133b03[_0x1820('0x34')][_0x1820('0x42')]){_0x2c13bc[_0x1820('0x3e')]=[{'all':!![]}];}_0x2c13bc=_[_0x1820('0x3a')]({},_0x2c13bc,_0x133b03[_0x1820('0x3c')]);return db['SquareMessage'][_0x1820('0x43')](_0x2c13bc)[_0x1820('0x22')](handleEntityNotFound(_0x3bf571,null))[_0x1820('0x22')](respondWithResult(_0x3bf571,null))['catch'](handleError(_0x3bf571,null));};exports[_0x1820('0x44')]=function(_0x157ea3,_0x35cd3a){return db['SquareMessage']['create'](_0x157ea3[_0x1820('0x45')],{})[_0x1820('0x22')](respondWithResult(_0x35cd3a,0xc9))[_0x1820('0x40')](handleError(_0x35cd3a,null));};exports[_0x1820('0x21')]=function(_0x58cd0b,_0x4adb28){if(_0x58cd0b[_0x1820('0x45')]['id']){delete _0x58cd0b['body']['id'];}return db[_0x1820('0x27')][_0x1820('0x43')]({'where':{'id':_0x58cd0b[_0x1820('0x46')]['id']}})[_0x1820('0x22')](handleEntityNotFound(_0x4adb28,null))['then'](saveUpdates(_0x58cd0b[_0x1820('0x45')],null))[_0x1820('0x22')](respondWithResult(_0x4adb28,null))[_0x1820('0x40')](handleError(_0x4adb28,null));};exports[_0x1820('0x47')]=function(_0x1dba08,_0x24607e){return db[_0x1820('0x27')][_0x1820('0x43')]({'where':{'id':_0x1dba08[_0x1820('0x46')]['id']}})[_0x1820('0x22')](handleEntityNotFound(_0x24607e,null))[_0x1820('0x22')](removeEntity(_0x24607e,null))[_0x1820('0x40')](handleError(_0x24607e,null));};