Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / api / intFreshsalesField / intFreshsalesField.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 _0xf5d8=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','count','offset','set','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','map','FreshsalesField','rawAttributes','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','limit','where','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','params','find','catch','create','body','eml-format','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs'];(function(_0x39096d,_0x51f8a0){var _0x13da4f=function(_0x11e6b2){while(--_0x11e6b2){_0x39096d['push'](_0x39096d['shift']());}};_0x13da4f(++_0x51f8a0);}(_0xf5d8,0x1d8));var _0x8f5d=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xf5d8[_0x321bb2];return _0x9c12ed;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x8f5d('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x8f5d('0x1'));var rp=require(_0x8f5d('0x2'));var moment=require('moment');var BPromise=require(_0x8f5d('0x3'));var Mustache=require(_0x8f5d('0x4'));var util=require(_0x8f5d('0x5'));var path=require(_0x8f5d('0x6'));var sox=require(_0x8f5d('0x7'));var csv=require(_0x8f5d('0x8'));var ejs=require(_0x8f5d('0x9'));var fs=require('fs');var _=require(_0x8f5d('0xa'));var squel=require(_0x8f5d('0xb'));var crypto=require(_0x8f5d('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x8f5d('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x8f5d('0xe'));var Redis=require(_0x8f5d('0xf'));var authService=require(_0x8f5d('0x10'));var qs=require(_0x8f5d('0x11'));var as=require(_0x8f5d('0x12'));var hardwareService=require(_0x8f5d('0x13'));var logger=require(_0x8f5d('0x14'))(_0x8f5d('0x15'));var utils=require(_0x8f5d('0x16'));var config=require(_0x8f5d('0x17'));var licenseUtil=require(_0x8f5d('0x18'));var db=require(_0x8f5d('0x19'))['db'];function respondWithStatusCode(_0x395c1d,_0x474a4c){_0x474a4c=_0x474a4c||0xcc;return function(_0x11857e){if(_0x11857e){return _0x395c1d['sendStatus'](_0x474a4c);}return _0x395c1d['status'](_0x474a4c)[_0x8f5d('0x1a')]();};}function respondWithResult(_0x19eb54,_0x13428a){_0x13428a=_0x13428a||0xc8;return function(_0xb98b1c){if(_0xb98b1c){return _0x19eb54[_0x8f5d('0x1b')](_0x13428a)[_0x8f5d('0x1c')](_0xb98b1c);}};}function respondWithFilteredResult(_0x561006,_0x27587b){return function(_0x4a4db2){if(_0x4a4db2){var _0x2d8fac=_0x4a4db2[_0x8f5d('0x1d')],_0x5099df=_0x27587b[_0x8f5d('0x1e')],_0x156ed3=_0x27587b[_0x8f5d('0x1e')]+_0x27587b['limit'],_0x3d6eaf;if(_0x156ed3>=_0x2d8fac){_0x156ed3=_0x2d8fac;_0x3d6eaf=0xc8;}else{_0x3d6eaf=0xce;}_0x561006['status'](_0x3d6eaf);return _0x561006[_0x8f5d('0x1f')]('Content-Range',_0x5099df+'-'+_0x156ed3+'/'+_0x2d8fac)[_0x8f5d('0x1c')](_0x4a4db2);}return null;};}function patchUpdates(_0x58c93e){return function(_0xbb5289){try{jsonpatch[_0x8f5d('0x20')](_0xbb5289,_0x58c93e,!![]);}catch(_0x46c526){return BPromise[_0x8f5d('0x21')](_0x46c526);}return _0xbb5289[_0x8f5d('0x22')]();};}function saveUpdates(_0x5d2ace,_0x278364){return function(_0x5aa2fd){if(_0x5aa2fd){return _0x5aa2fd[_0x8f5d('0x23')](_0x5d2ace)[_0x8f5d('0x24')](function(_0x172801){return _0x172801;});}return null;};}function removeEntity(_0xb732c3,_0x27afc8){return function(_0x3ed9f0){if(_0x3ed9f0){return _0x3ed9f0[_0x8f5d('0x25')]()[_0x8f5d('0x24')](function(){_0xb732c3['status'](0xcc)[_0x8f5d('0x1a')]();});}};}function handleEntityNotFound(_0x3207eb,_0x53a4ac){return function(_0x553a52){if(!_0x553a52){_0x3207eb[_0x8f5d('0x26')](0x194);}return _0x553a52;};}function handleError(_0x41f4d1,_0x414953){_0x414953=_0x414953||0x1f4;return function(_0x18e6ec){logger[_0x8f5d('0x27')](_0x18e6ec[_0x8f5d('0x28')]);if(_0x18e6ec[_0x8f5d('0x29')]){delete _0x18e6ec['name'];}_0x41f4d1[_0x8f5d('0x1b')](_0x414953)['send'](_0x18e6ec);};}exports['index']=function(_0x4fc815,_0x4fd071){var _0x110444={},_0x43e91e={},_0x501849={'count':0x0,'rows':[]};var _0x3a0082=_[_0x8f5d('0x2a')](db[_0x8f5d('0x2b')][_0x8f5d('0x2c')],function(_0x3c3295){return{'name':_0x3c3295['fieldName'],'type':_0x3c3295['type'][_0x8f5d('0x2d')]};});_0x43e91e[_0x8f5d('0x2e')]=_['map'](_0x3a0082,_0x8f5d('0x29'));_0x43e91e[_0x8f5d('0x2f')]=_[_0x8f5d('0x30')](_0x4fc815[_0x8f5d('0x2f')]);_0x43e91e[_0x8f5d('0x31')]=_[_0x8f5d('0x32')](_0x43e91e[_0x8f5d('0x2e')],_0x43e91e[_0x8f5d('0x2f')]);_0x110444[_0x8f5d('0x33')]=_[_0x8f5d('0x32')](_0x43e91e[_0x8f5d('0x2e')],qs[_0x8f5d('0x34')](_0x4fc815['query'][_0x8f5d('0x34')]));_0x110444['attributes']=_0x110444[_0x8f5d('0x33')]['length']?_0x110444[_0x8f5d('0x33')]:_0x43e91e[_0x8f5d('0x2e')];if(!_0x4fc815[_0x8f5d('0x2f')][_0x8f5d('0x35')]('nolimit')){_0x110444[_0x8f5d('0x36')]=qs['limit'](_0x4fc815[_0x8f5d('0x2f')]['limit']);_0x110444[_0x8f5d('0x1e')]=qs['offset'](_0x4fc815[_0x8f5d('0x2f')][_0x8f5d('0x1e')]);}_0x110444['order']=qs['sort'](_0x4fc815[_0x8f5d('0x2f')]['sort']);_0x110444[_0x8f5d('0x37')]=qs['filters'](_['pick'](_0x4fc815[_0x8f5d('0x2f')],_0x43e91e[_0x8f5d('0x31')]),_0x3a0082);if(_0x4fc815['query'][_0x8f5d('0x38')]){_0x110444['where']=_[_0x8f5d('0x39')](_0x110444['where'],{'$or':_[_0x8f5d('0x2a')](_0x3a0082,function(_0x246607){if(_0x246607[_0x8f5d('0x3a')]!==_0x8f5d('0x3b')){var _0x208305={};_0x208305[_0x246607[_0x8f5d('0x29')]]={'$like':'%'+_0x4fc815[_0x8f5d('0x2f')]['filter']+'%'};return _0x208305;}})});}_0x110444=_[_0x8f5d('0x39')]({},_0x110444,_0x4fc815[_0x8f5d('0x3c')]);var _0x52fea1={'where':_0x110444['where']};return db[_0x8f5d('0x2b')][_0x8f5d('0x1d')](_0x52fea1)[_0x8f5d('0x24')](function(_0x3e68b4){_0x501849[_0x8f5d('0x1d')]=_0x3e68b4;if(_0x4fc815[_0x8f5d('0x2f')][_0x8f5d('0x3d')]){_0x110444[_0x8f5d('0x3e')]=[{'all':!![]}];}return db[_0x8f5d('0x2b')][_0x8f5d('0x3f')](_0x110444);})[_0x8f5d('0x24')](function(_0x34cc77){_0x501849[_0x8f5d('0x40')]=_0x34cc77;return _0x501849;})[_0x8f5d('0x24')](respondWithFilteredResult(_0x4fd071,_0x110444))['catch'](handleError(_0x4fd071,null));};exports['show']=function(_0x1746c8,_0x4e4add){var _0xfd2934={'raw':!![],'where':{'id':_0x1746c8[_0x8f5d('0x41')]['id']}},_0x2a68c0={};_0x2a68c0[_0x8f5d('0x2e')]=_['keys'](db[_0x8f5d('0x2b')][_0x8f5d('0x2c')]);_0x2a68c0[_0x8f5d('0x2f')]=_[_0x8f5d('0x30')](_0x1746c8[_0x8f5d('0x2f')]);_0x2a68c0[_0x8f5d('0x31')]=_[_0x8f5d('0x32')](_0x2a68c0[_0x8f5d('0x2e')],_0x2a68c0[_0x8f5d('0x2f')]);_0xfd2934[_0x8f5d('0x33')]=_[_0x8f5d('0x32')](_0x2a68c0[_0x8f5d('0x2e')],qs['fields'](_0x1746c8[_0x8f5d('0x2f')][_0x8f5d('0x34')]));_0xfd2934[_0x8f5d('0x33')]=_0xfd2934[_0x8f5d('0x33')]['length']?_0xfd2934['attributes']:_0x2a68c0['model'];if(_0x1746c8['query'][_0x8f5d('0x3d')]){_0xfd2934[_0x8f5d('0x3e')]=[{'all':!![]}];}_0xfd2934=_[_0x8f5d('0x39')]({},_0xfd2934,_0x1746c8['options']);return db['FreshsalesField'][_0x8f5d('0x42')](_0xfd2934)[_0x8f5d('0x24')](handleEntityNotFound(_0x4e4add,null))[_0x8f5d('0x24')](respondWithResult(_0x4e4add,null))[_0x8f5d('0x43')](handleError(_0x4e4add,null));};exports[_0x8f5d('0x44')]=function(_0x3a19c4,_0x331966){return db['FreshsalesField'][_0x8f5d('0x44')](_0x3a19c4[_0x8f5d('0x45')],{})[_0x8f5d('0x24')](respondWithResult(_0x331966,0xc9))[_0x8f5d('0x43')](handleError(_0x331966,null));};exports[_0x8f5d('0x23')]=function(_0x3681e9,_0x331c10){if(_0x3681e9[_0x8f5d('0x45')]['id']){delete _0x3681e9['body']['id'];}return db[_0x8f5d('0x2b')][_0x8f5d('0x42')]({'where':{'id':_0x3681e9[_0x8f5d('0x41')]['id']}})['then'](handleEntityNotFound(_0x331c10,null))[_0x8f5d('0x24')](saveUpdates(_0x3681e9[_0x8f5d('0x45')],null))['then'](respondWithResult(_0x331c10,null))[_0x8f5d('0x43')](handleError(_0x331c10,null));};exports[_0x8f5d('0x25')]=function(_0x276da4,_0x498b47){return db[_0x8f5d('0x2b')][_0x8f5d('0x42')]({'where':{'id':_0x276da4[_0x8f5d('0x41')]['id']}})['then'](handleEntityNotFound(_0x498b47,null))[_0x8f5d('0x24')](removeEntity(_0x498b47,null))['catch'](handleError(_0x498b47,null));};