Built motion from commit (unavailable).|2.5.7
[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 _0x9384=['includeAll','include','findAll','rows','catch','show','params','length','options','create','body','find','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','index','FreshsalesField','rawAttributes','fieldName','type','key','map','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','limit','sort','where','pick','filter','merge','count'];(function(_0x4f7618,_0x243df2){var _0x20ba5f=function(_0x1bfe65){while(--_0x1bfe65){_0x4f7618['push'](_0x4f7618['shift']());}};_0x20ba5f(++_0x243df2);}(_0x9384,0xea));var _0x4938=function(_0xaa6a4,_0x64b067){_0xaa6a4=_0xaa6a4-0x0;var _0xdc31a4=_0x9384[_0xaa6a4];return _0xdc31a4;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x4938('0x0'));var rimraf=require(_0x4938('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x4938('0x2'));var rp=require(_0x4938('0x3'));var moment=require(_0x4938('0x4'));var BPromise=require(_0x4938('0x5'));var Mustache=require(_0x4938('0x6'));var util=require(_0x4938('0x7'));var path=require(_0x4938('0x8'));var sox=require(_0x4938('0x9'));var csv=require(_0x4938('0xa'));var ejs=require(_0x4938('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0x4938('0xc'));var crypto=require('crypto');var jsforce=require(_0x4938('0xd'));var deskjs=require(_0x4938('0xe'));var toCsv=require(_0x4938('0xa'));var querystring=require(_0x4938('0xf'));var Papa=require(_0x4938('0x10'));var Redis=require(_0x4938('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x4938('0x12'));var as=require(_0x4938('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x4938('0x14'));var utils=require(_0x4938('0x15'));var config=require(_0x4938('0x16'));var licenseUtil=require(_0x4938('0x17'));var db=require(_0x4938('0x18'))['db'];function respondWithStatusCode(_0x3aff71,_0x30c72c){_0x30c72c=_0x30c72c||0xcc;return function(_0x4e96c4){if(_0x4e96c4){return _0x3aff71[_0x4938('0x19')](_0x30c72c);}return _0x3aff71[_0x4938('0x1a')](_0x30c72c)[_0x4938('0x1b')]();};}function respondWithResult(_0x3da94a,_0x4ac447){_0x4ac447=_0x4ac447||0xc8;return function(_0x3ff1d6){if(_0x3ff1d6){return _0x3da94a[_0x4938('0x1a')](_0x4ac447)[_0x4938('0x1c')](_0x3ff1d6);}};}function respondWithFilteredResult(_0x26ddf6,_0x204783){return function(_0x3243b1){if(_0x3243b1){var _0x1e1108=_0x3243b1['count'],_0x14dcf2=_0x204783['offset'],_0x1f2153=_0x204783[_0x4938('0x1d')]+_0x204783['limit'],_0x27a8a3;if(_0x1f2153>=_0x1e1108){_0x1f2153=_0x1e1108;_0x27a8a3=0xc8;}else{_0x27a8a3=0xce;}_0x26ddf6[_0x4938('0x1a')](_0x27a8a3);return _0x26ddf6['set'](_0x4938('0x1e'),_0x14dcf2+'-'+_0x1f2153+'/'+_0x1e1108)['json'](_0x3243b1);}return null;};}function patchUpdates(_0x806c07){return function(_0x30b690){try{jsonpatch[_0x4938('0x1f')](_0x30b690,_0x806c07,!![]);}catch(_0x2f1597){return BPromise[_0x4938('0x20')](_0x2f1597);}return _0x30b690[_0x4938('0x21')]();};}function saveUpdates(_0x116e44,_0x4b6895){return function(_0x4af6df){if(_0x4af6df){return _0x4af6df[_0x4938('0x22')](_0x116e44)[_0x4938('0x23')](function(_0x5378d8){return _0x5378d8;});}return null;};}function removeEntity(_0x4d67f8,_0x2b86c9){return function(_0x1cbd9f){if(_0x1cbd9f){return _0x1cbd9f[_0x4938('0x24')]()[_0x4938('0x23')](function(){_0x4d67f8[_0x4938('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3e9b36,_0x3c0245){return function(_0x1ce3f0){if(!_0x1ce3f0){_0x3e9b36[_0x4938('0x19')](0x194);}return _0x1ce3f0;};}function handleError(_0x12966f,_0x5c08fd){_0x5c08fd=_0x5c08fd||0x1f4;return function(_0x110c37){logger[_0x4938('0x25')](_0x110c37[_0x4938('0x26')]);if(_0x110c37[_0x4938('0x27')]){delete _0x110c37[_0x4938('0x27')];}_0x12966f['status'](_0x5c08fd)['send'](_0x110c37);};}exports[_0x4938('0x28')]=function(_0x3de423,_0xc695a8){var _0x2fa826={},_0x2d9e31={},_0x2e73ab={'count':0x0,'rows':[]};var _0x1d0fe4=_['map'](db[_0x4938('0x29')][_0x4938('0x2a')],function(_0x5c4747){return{'name':_0x5c4747[_0x4938('0x2b')],'type':_0x5c4747[_0x4938('0x2c')][_0x4938('0x2d')]};});_0x2d9e31['model']=_[_0x4938('0x2e')](_0x1d0fe4,_0x4938('0x27'));_0x2d9e31[_0x4938('0x2f')]=_[_0x4938('0x30')](_0x3de423[_0x4938('0x2f')]);_0x2d9e31[_0x4938('0x31')]=_[_0x4938('0x32')](_0x2d9e31[_0x4938('0x33')],_0x2d9e31[_0x4938('0x2f')]);_0x2fa826[_0x4938('0x34')]=_[_0x4938('0x32')](_0x2d9e31[_0x4938('0x33')],qs['fields'](_0x3de423[_0x4938('0x2f')][_0x4938('0x35')]));_0x2fa826[_0x4938('0x34')]=_0x2fa826['attributes']['length']?_0x2fa826[_0x4938('0x34')]:_0x2d9e31[_0x4938('0x33')];if(!_0x3de423['query'][_0x4938('0x36')]('nolimit')){_0x2fa826['limit']=qs[_0x4938('0x37')](_0x3de423[_0x4938('0x2f')][_0x4938('0x37')]);_0x2fa826[_0x4938('0x1d')]=qs[_0x4938('0x1d')](_0x3de423['query'][_0x4938('0x1d')]);}_0x2fa826['order']=qs[_0x4938('0x38')](_0x3de423['query'][_0x4938('0x38')]);_0x2fa826[_0x4938('0x39')]=qs[_0x4938('0x31')](_[_0x4938('0x3a')](_0x3de423[_0x4938('0x2f')],_0x2d9e31[_0x4938('0x31')]),_0x1d0fe4);if(_0x3de423[_0x4938('0x2f')][_0x4938('0x3b')]){_0x2fa826[_0x4938('0x39')]=_[_0x4938('0x3c')](_0x2fa826[_0x4938('0x39')],{'$or':_[_0x4938('0x2e')](_0x1d0fe4,function(_0x5e57ba){if(_0x5e57ba['type']!=='VIRTUAL'){var _0x253d47={};_0x253d47[_0x5e57ba[_0x4938('0x27')]]={'$like':'%'+_0x3de423['query'][_0x4938('0x3b')]+'%'};return _0x253d47;}})});}_0x2fa826=_['merge']({},_0x2fa826,_0x3de423['options']);var _0x3104b2={'where':_0x2fa826['where']};return db[_0x4938('0x29')][_0x4938('0x3d')](_0x3104b2)[_0x4938('0x23')](function(_0x16f67f){_0x2e73ab[_0x4938('0x3d')]=_0x16f67f;if(_0x3de423[_0x4938('0x2f')][_0x4938('0x3e')]){_0x2fa826[_0x4938('0x3f')]=[{'all':!![]}];}return db['FreshsalesField'][_0x4938('0x40')](_0x2fa826);})['then'](function(_0x5e1974){_0x2e73ab[_0x4938('0x41')]=_0x5e1974;return _0x2e73ab;})[_0x4938('0x23')](respondWithFilteredResult(_0xc695a8,_0x2fa826))[_0x4938('0x42')](handleError(_0xc695a8,null));};exports[_0x4938('0x43')]=function(_0x59bef7,_0x25bc96){var _0x3794f2={'raw':!![],'where':{'id':_0x59bef7[_0x4938('0x44')]['id']}},_0x7f76f2={};_0x7f76f2[_0x4938('0x33')]=_['keys'](db['FreshsalesField']['rawAttributes']);_0x7f76f2[_0x4938('0x2f')]=_['keys'](_0x59bef7[_0x4938('0x2f')]);_0x7f76f2[_0x4938('0x31')]=_[_0x4938('0x32')](_0x7f76f2[_0x4938('0x33')],_0x7f76f2[_0x4938('0x2f')]);_0x3794f2[_0x4938('0x34')]=_['intersection'](_0x7f76f2[_0x4938('0x33')],qs[_0x4938('0x35')](_0x59bef7[_0x4938('0x2f')][_0x4938('0x35')]));_0x3794f2[_0x4938('0x34')]=_0x3794f2[_0x4938('0x34')][_0x4938('0x45')]?_0x3794f2[_0x4938('0x34')]:_0x7f76f2[_0x4938('0x33')];if(_0x59bef7['query']['includeAll']){_0x3794f2[_0x4938('0x3f')]=[{'all':!![]}];}_0x3794f2=_[_0x4938('0x3c')]({},_0x3794f2,_0x59bef7[_0x4938('0x46')]);return db[_0x4938('0x29')]['find'](_0x3794f2)[_0x4938('0x23')](handleEntityNotFound(_0x25bc96,null))[_0x4938('0x23')](respondWithResult(_0x25bc96,null))[_0x4938('0x42')](handleError(_0x25bc96,null));};exports[_0x4938('0x47')]=function(_0x46b8d2,_0x4c74c8){return db['FreshsalesField'][_0x4938('0x47')](_0x46b8d2['body'],{})[_0x4938('0x23')](respondWithResult(_0x4c74c8,0xc9))[_0x4938('0x42')](handleError(_0x4c74c8,null));};exports[_0x4938('0x22')]=function(_0x1640a1,_0x24bbbc){if(_0x1640a1[_0x4938('0x48')]['id']){delete _0x1640a1['body']['id'];}return db[_0x4938('0x29')][_0x4938('0x49')]({'where':{'id':_0x1640a1[_0x4938('0x44')]['id']}})[_0x4938('0x23')](handleEntityNotFound(_0x24bbbc,null))[_0x4938('0x23')](saveUpdates(_0x1640a1[_0x4938('0x48')],null))[_0x4938('0x23')](respondWithResult(_0x24bbbc,null))[_0x4938('0x42')](handleError(_0x24bbbc,null));};exports[_0x4938('0x24')]=function(_0x429d78,_0x27a278){return db[_0x4938('0x29')][_0x4938('0x49')]({'where':{'id':_0x429d78[_0x4938('0x44')]['id']}})['then'](handleEntityNotFound(_0x27a278,null))['then'](removeEntity(_0x27a278,null))[_0x4938('0x42')](handleError(_0x27a278,null));};