188748e30ac6eb4c8172cafeae4d41f4eae60fd6
[motion2.git] / server / api / crmTask / crmTask.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 _0x2b13=['CrmTask','includeAll','include','findAll','rows','catch','show','params','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','squel','jsforce','desk.js','querystring','papaparse','../../config/license/hardware','../../config/utils','../../mysqldb','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','rawAttributes','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','map','type','VIRTUAL','field','merge','options'];(function(_0x457197,_0x3ba6aa){var _0x299ff8=function(_0x13b068){while(--_0x13b068){_0x457197['push'](_0x457197['shift']());}};_0x299ff8(++_0x3ba6aa);}(_0x2b13,0x1bc));var _0x32b1=function(_0x26f7ec,_0x5707d4){_0x26f7ec=_0x26f7ec-0x0;var _0x1ba3eb=_0x2b13[_0x26f7ec];return _0x1ba3eb;};'use strict';var pdf=require(_0x32b1('0x0'));var emlformat=require(_0x32b1('0x1'));var rimraf=require(_0x32b1('0x2'));var zipdir=require(_0x32b1('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x32b1('0x4'));var moment=require('moment');var BPromise=require(_0x32b1('0x5'));var Mustache=require(_0x32b1('0x6'));var util=require(_0x32b1('0x7'));var path=require(_0x32b1('0x8'));var sox=require(_0x32b1('0x9'));var csv=require(_0x32b1('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x32b1('0xb'));var crypto=require('crypto');var jsforce=require(_0x32b1('0xc'));var deskjs=require(_0x32b1('0xd'));var toCsv=require(_0x32b1('0xa'));var querystring=require(_0x32b1('0xe'));var Papa=require(_0x32b1('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var hardwareService=require(_0x32b1('0x10'));var logger=require('../../config/logger')('api');var utils=require(_0x32b1('0x11'));var config=require('../../config/environment');var db=require(_0x32b1('0x12'))['db'];function respondWithStatusCode(_0x31dc95,_0x4c1fb9){_0x4c1fb9=_0x4c1fb9||0xcc;return function(_0x29acf9){if(_0x29acf9){return _0x31dc95[_0x32b1('0x13')](_0x4c1fb9);}return _0x31dc95[_0x32b1('0x14')](_0x4c1fb9)[_0x32b1('0x15')]();};}function respondWithResult(_0x1b2f3f,_0x1d61d1){_0x1d61d1=_0x1d61d1||0xc8;return function(_0x3f1a47){if(_0x3f1a47){return _0x1b2f3f[_0x32b1('0x14')](_0x1d61d1)[_0x32b1('0x16')](_0x3f1a47);}};}function respondWithFilteredResult(_0x1ffb39,_0x455b2b){return function(_0xc0a4f2){if(_0xc0a4f2){var _0x44bc0f=_0xc0a4f2[_0x32b1('0x17')],_0x464890=_0x455b2b[_0x32b1('0x18')],_0x472037=_0x455b2b[_0x32b1('0x18')]+_0x455b2b[_0x32b1('0x19')],_0x2002fb;if(_0x472037>=_0x44bc0f){_0x472037=_0x44bc0f;_0x2002fb=0xc8;}else{_0x2002fb=0xce;}_0x1ffb39['status'](_0x2002fb);return _0x1ffb39['set'](_0x32b1('0x1a'),_0x464890+'-'+_0x472037+'/'+_0x44bc0f)['json'](_0xc0a4f2);}return null;};}function patchUpdates(_0x248287){return function(_0x478bfe){try{jsonpatch[_0x32b1('0x1b')](_0x478bfe,_0x248287,!![]);}catch(_0x1b70b3){return BPromise[_0x32b1('0x1c')](_0x1b70b3);}return _0x478bfe[_0x32b1('0x1d')]();};}function saveUpdates(_0x1dcf5d,_0x3ff99e){return function(_0x38c9c7){if(_0x38c9c7){return _0x38c9c7[_0x32b1('0x1e')](_0x1dcf5d)[_0x32b1('0x1f')](function(_0xb7bae4){return _0xb7bae4;});}return null;};}function removeEntity(_0x124edf,_0x2e7c15){return function(_0x43d510){if(_0x43d510){return _0x43d510[_0x32b1('0x20')]()[_0x32b1('0x1f')](function(){_0x124edf['status'](0xcc)[_0x32b1('0x15')]();});}};}function handleEntityNotFound(_0x11c1f5,_0x43bafe){return function(_0xc8a71a){if(!_0xc8a71a){_0x11c1f5[_0x32b1('0x13')](0x194);}return _0xc8a71a;};}function handleError(_0x26815f,_0x3c4490){_0x3c4490=_0x3c4490||0x1f4;return function(_0x23f04d){logger[_0x32b1('0x21')](_0x23f04d[_0x32b1('0x22')]);if(_0x23f04d[_0x32b1('0x23')]){delete _0x23f04d[_0x32b1('0x23')];}_0x26815f[_0x32b1('0x14')](_0x3c4490)[_0x32b1('0x24')](_0x23f04d);};}exports[_0x32b1('0x25')]=function(_0x2bec57,_0x2f335b){var _0x5e1e0a={},_0x54d796={},_0x49ec2a={'count':0x0,'rows':[]};var _0x1da9e7=db['CrmTask'][_0x32b1('0x26')];_0x54d796['model']=_[_0x32b1('0x27')](_0x1da9e7);_0x54d796[_0x32b1('0x28')]=_['keys'](_0x2bec57['query']);_0x54d796[_0x32b1('0x29')]=_[_0x32b1('0x2a')](_0x54d796[_0x32b1('0x2b')],_0x54d796[_0x32b1('0x28')]);_0x5e1e0a[_0x32b1('0x2c')]=_[_0x32b1('0x2a')](_0x54d796[_0x32b1('0x2b')],qs[_0x32b1('0x2d')](_0x2bec57[_0x32b1('0x28')][_0x32b1('0x2d')]));_0x5e1e0a[_0x32b1('0x2c')]=_0x5e1e0a[_0x32b1('0x2c')][_0x32b1('0x2e')]?_0x5e1e0a[_0x32b1('0x2c')]:_0x54d796[_0x32b1('0x2b')];if(!_0x2bec57[_0x32b1('0x28')][_0x32b1('0x2f')](_0x32b1('0x30'))){_0x5e1e0a[_0x32b1('0x19')]=qs[_0x32b1('0x19')](_0x2bec57[_0x32b1('0x28')][_0x32b1('0x19')]);_0x5e1e0a[_0x32b1('0x18')]=qs[_0x32b1('0x18')](_0x2bec57[_0x32b1('0x28')][_0x32b1('0x18')]);}_0x5e1e0a[_0x32b1('0x31')]=qs[_0x32b1('0x32')](_0x2bec57['query']['sort']);_0x5e1e0a[_0x32b1('0x33')]=qs[_0x32b1('0x29')](_[_0x32b1('0x34')](_0x2bec57[_0x32b1('0x28')],_0x54d796[_0x32b1('0x29')]));if(_0x2bec57['query'][_0x32b1('0x35')]){_0x5e1e0a[_0x32b1('0x33')]=_['merge'](_0x5e1e0a[_0x32b1('0x33')],{'$or':_[_0x32b1('0x36')](_0x1da9e7,function(_0x32849f){if(_0x32849f[_0x32b1('0x37')]['key']!==_0x32b1('0x38')){var _0xf1732b={};_0xf1732b[_0x32849f[_0x32b1('0x39')]]={'$like':'%'+_0x2bec57[_0x32b1('0x28')]['filter']+'%'};return _0xf1732b;}})});}_0x5e1e0a=_[_0x32b1('0x3a')]({},_0x5e1e0a,_0x2bec57[_0x32b1('0x3b')]);var _0x2532db={'where':_0x5e1e0a['where']};return db[_0x32b1('0x3c')][_0x32b1('0x17')](_0x2532db)[_0x32b1('0x1f')](function(_0x303313){_0x49ec2a['count']=_0x303313;if(_0x2bec57[_0x32b1('0x28')][_0x32b1('0x3d')]){_0x5e1e0a[_0x32b1('0x3e')]=[{'all':!![]}];}return db['CrmTask'][_0x32b1('0x3f')](_0x5e1e0a);})[_0x32b1('0x1f')](function(_0x325ffd){_0x49ec2a[_0x32b1('0x40')]=_0x325ffd;return _0x49ec2a;})[_0x32b1('0x1f')](respondWithFilteredResult(_0x2f335b,_0x5e1e0a))[_0x32b1('0x41')](handleError(_0x2f335b,null));};exports[_0x32b1('0x42')]=function(_0x29ec68,_0x1c01e1){var _0x3ba62f={'raw':![],'where':{'id':_0x29ec68[_0x32b1('0x43')]['id']}},_0x20162b={};_0x20162b[_0x32b1('0x2b')]=_[_0x32b1('0x27')](db[_0x32b1('0x3c')]['rawAttributes']);_0x20162b[_0x32b1('0x28')]=_['keys'](_0x29ec68[_0x32b1('0x28')]);_0x20162b['filters']=_[_0x32b1('0x2a')](_0x20162b['model'],_0x20162b[_0x32b1('0x28')]);_0x3ba62f[_0x32b1('0x2c')]=_[_0x32b1('0x2a')](_0x20162b['model'],qs['fields'](_0x29ec68[_0x32b1('0x28')]['fields']));_0x3ba62f[_0x32b1('0x2c')]=_0x3ba62f['attributes'][_0x32b1('0x2e')]?_0x3ba62f[_0x32b1('0x2c')]:_0x20162b['model'];if(_0x29ec68['query']['includeAll']){_0x3ba62f[_0x32b1('0x3e')]=[{'all':!![]}];}_0x3ba62f=_[_0x32b1('0x3a')]({},_0x3ba62f,_0x29ec68[_0x32b1('0x3b')]);return db[_0x32b1('0x3c')][_0x32b1('0x44')](_0x3ba62f)[_0x32b1('0x1f')](handleEntityNotFound(_0x1c01e1,null))[_0x32b1('0x1f')](respondWithResult(_0x1c01e1,null))[_0x32b1('0x41')](handleError(_0x1c01e1,null));};exports[_0x32b1('0x45')]=function(_0x5394ed,_0x49157a){return db[_0x32b1('0x3c')]['create'](_0x5394ed[_0x32b1('0x46')],{})['then'](respondWithResult(_0x49157a,0xc9))[_0x32b1('0x41')](handleError(_0x49157a,null));};exports[_0x32b1('0x1e')]=function(_0x458af4,_0x229763){if(_0x458af4['body']['id']){delete _0x458af4['body']['id'];}return db[_0x32b1('0x3c')][_0x32b1('0x44')]({'where':{'id':_0x458af4['params']['id']}})['then'](handleEntityNotFound(_0x229763,null))[_0x32b1('0x1f')](saveUpdates(_0x458af4[_0x32b1('0x46')],null))['then'](respondWithResult(_0x229763,null))[_0x32b1('0x41')](handleError(_0x229763,null));};exports[_0x32b1('0x20')]=function(_0x2807b9,_0x51eb13){return db[_0x32b1('0x3c')][_0x32b1('0x44')]({'where':{'id':_0x2807b9[_0x32b1('0x43')]['id']}})[_0x32b1('0x1f')](handleEntityNotFound(_0x51eb13,null))[_0x32b1('0x1f')](removeEntity(_0x51eb13,null))[_0x32b1('0x41')](handleError(_0x51eb13,null));};exports[_0x32b1('0x47')]=function(_0x154c2e,_0x31177f){return db[_0x32b1('0x3c')][_0x32b1('0x47')]()[_0x32b1('0x1f')](respondWithResult(_0x31177f,null))[_0x32b1('0x41')](handleError(_0x31177f,null));};