Built motion from commit (unavailable).|2.5.10
[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 _0x09cb=['util','sox','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','status','end','json','offset','limit','set','Content-Range','apply','reject','update','then','sendStatus','stack','name','index','FreshsalesField','rawAttributes','fieldName','key','map','query','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','type','options','count','includeAll','include','findAll','rows','show','params','keys','find','catch','create','body','destroy','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache'];(function(_0x3eaae5,_0x9fdfa2){var _0xf2e02=function(_0x4b7c69){while(--_0x4b7c69){_0x3eaae5['push'](_0x3eaae5['shift']());}};_0xf2e02(++_0x9fdfa2);}(_0x09cb,0x1a9));var _0xb09c=function(_0x2f873f,_0x5274ac){_0x2f873f=_0x2f873f-0x0;var _0x49dbcb=_0x09cb[_0x2f873f];return _0x49dbcb;};'use strict';var pdf=require(_0xb09c('0x0'));var emlformat=require(_0xb09c('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xb09c('0x2'));var jsonpatch=require(_0xb09c('0x3'));var rp=require(_0xb09c('0x4'));var moment=require(_0xb09c('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xb09c('0x6'));var util=require(_0xb09c('0x7'));var path=require('path');var sox=require(_0xb09c('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xb09c('0x9'));var crypto=require(_0xb09c('0xa'));var jsforce=require(_0xb09c('0xb'));var deskjs=require(_0xb09c('0xc'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xb09c('0xd'));var Redis=require(_0xb09c('0xe'));var authService=require(_0xb09c('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xb09c('0x10'));var hardwareService=require(_0xb09c('0x11'));var logger=require(_0xb09c('0x12'))(_0xb09c('0x13'));var utils=require(_0xb09c('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0xb09c('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1cbb79,_0x25f8dd){_0x25f8dd=_0x25f8dd||0xcc;return function(_0x244379){if(_0x244379){return _0x1cbb79['sendStatus'](_0x25f8dd);}return _0x1cbb79[_0xb09c('0x16')](_0x25f8dd)[_0xb09c('0x17')]();};}function respondWithResult(_0x5ce468,_0x182f9a){_0x182f9a=_0x182f9a||0xc8;return function(_0x150d70){if(_0x150d70){return _0x5ce468[_0xb09c('0x16')](_0x182f9a)[_0xb09c('0x18')](_0x150d70);}};}function respondWithFilteredResult(_0x583861,_0x3a6e22){return function(_0x98ce53){if(_0x98ce53){var _0x5c889a=_0x98ce53['count'],_0xaaa5ae=_0x3a6e22[_0xb09c('0x19')],_0x5b345d=_0x3a6e22[_0xb09c('0x19')]+_0x3a6e22[_0xb09c('0x1a')],_0x1d7958;if(_0x5b345d>=_0x5c889a){_0x5b345d=_0x5c889a;_0x1d7958=0xc8;}else{_0x1d7958=0xce;}_0x583861[_0xb09c('0x16')](_0x1d7958);return _0x583861[_0xb09c('0x1b')](_0xb09c('0x1c'),_0xaaa5ae+'-'+_0x5b345d+'/'+_0x5c889a)[_0xb09c('0x18')](_0x98ce53);}return null;};}function patchUpdates(_0x25e7fc){return function(_0x66bdba){try{jsonpatch[_0xb09c('0x1d')](_0x66bdba,_0x25e7fc,!![]);}catch(_0x5592bc){return BPromise[_0xb09c('0x1e')](_0x5592bc);}return _0x66bdba['save']();};}function saveUpdates(_0x2997b7,_0x22feda){return function(_0x43afaf){if(_0x43afaf){return _0x43afaf[_0xb09c('0x1f')](_0x2997b7)[_0xb09c('0x20')](function(_0x5b3570){return _0x5b3570;});}return null;};}function removeEntity(_0x108def,_0x19d3a4){return function(_0x33a185){if(_0x33a185){return _0x33a185['destroy']()[_0xb09c('0x20')](function(){_0x108def['status'](0xcc)[_0xb09c('0x17')]();});}};}function handleEntityNotFound(_0x36a5ec,_0x4c6f23){return function(_0x236432){if(!_0x236432){_0x36a5ec[_0xb09c('0x21')](0x194);}return _0x236432;};}function handleError(_0x48fdf0,_0xefd185){_0xefd185=_0xefd185||0x1f4;return function(_0x429c90){logger['error'](_0x429c90[_0xb09c('0x22')]);if(_0x429c90[_0xb09c('0x23')]){delete _0x429c90[_0xb09c('0x23')];}_0x48fdf0['status'](_0xefd185)['send'](_0x429c90);};}exports[_0xb09c('0x24')]=function(_0x11791f,_0x17fc59){var _0x36a676={},_0x53de54={},_0x20fc96={'count':0x0,'rows':[]};var _0x23f4c8=_['map'](db[_0xb09c('0x25')][_0xb09c('0x26')],function(_0x59ee6c){return{'name':_0x59ee6c[_0xb09c('0x27')],'type':_0x59ee6c['type'][_0xb09c('0x28')]};});_0x53de54['model']=_[_0xb09c('0x29')](_0x23f4c8,_0xb09c('0x23'));_0x53de54['query']=_['keys'](_0x11791f[_0xb09c('0x2a')]);_0x53de54['filters']=_[_0xb09c('0x2b')](_0x53de54['model'],_0x53de54[_0xb09c('0x2a')]);_0x36a676['attributes']=_[_0xb09c('0x2b')](_0x53de54[_0xb09c('0x2c')],qs[_0xb09c('0x2d')](_0x11791f[_0xb09c('0x2a')][_0xb09c('0x2d')]));_0x36a676[_0xb09c('0x2e')]=_0x36a676[_0xb09c('0x2e')][_0xb09c('0x2f')]?_0x36a676['attributes']:_0x53de54[_0xb09c('0x2c')];if(!_0x11791f[_0xb09c('0x2a')][_0xb09c('0x30')](_0xb09c('0x31'))){_0x36a676[_0xb09c('0x1a')]=qs[_0xb09c('0x1a')](_0x11791f[_0xb09c('0x2a')][_0xb09c('0x1a')]);_0x36a676[_0xb09c('0x19')]=qs[_0xb09c('0x19')](_0x11791f['query'][_0xb09c('0x19')]);}_0x36a676[_0xb09c('0x32')]=qs[_0xb09c('0x33')](_0x11791f[_0xb09c('0x2a')][_0xb09c('0x33')]);_0x36a676[_0xb09c('0x34')]=qs[_0xb09c('0x35')](_[_0xb09c('0x36')](_0x11791f['query'],_0x53de54[_0xb09c('0x35')]),_0x23f4c8);if(_0x11791f[_0xb09c('0x2a')][_0xb09c('0x37')]){_0x36a676[_0xb09c('0x34')]=_[_0xb09c('0x38')](_0x36a676[_0xb09c('0x34')],{'$or':_[_0xb09c('0x29')](_0x23f4c8,function(_0x1ffe1d){if(_0x1ffe1d[_0xb09c('0x39')]!=='VIRTUAL'){var _0x3c4123={};_0x3c4123[_0x1ffe1d[_0xb09c('0x23')]]={'$like':'%'+_0x11791f['query'][_0xb09c('0x37')]+'%'};return _0x3c4123;}})});}_0x36a676=_[_0xb09c('0x38')]({},_0x36a676,_0x11791f[_0xb09c('0x3a')]);var _0x2de147={'where':_0x36a676[_0xb09c('0x34')]};return db[_0xb09c('0x25')][_0xb09c('0x3b')](_0x2de147)[_0xb09c('0x20')](function(_0x6bf72f){_0x20fc96['count']=_0x6bf72f;if(_0x11791f[_0xb09c('0x2a')][_0xb09c('0x3c')]){_0x36a676[_0xb09c('0x3d')]=[{'all':!![]}];}return db['FreshsalesField'][_0xb09c('0x3e')](_0x36a676);})['then'](function(_0x56cf41){_0x20fc96[_0xb09c('0x3f')]=_0x56cf41;return _0x20fc96;})[_0xb09c('0x20')](respondWithFilteredResult(_0x17fc59,_0x36a676))['catch'](handleError(_0x17fc59,null));};exports[_0xb09c('0x40')]=function(_0x5b6695,_0x3c2649){var _0x4e2048={'raw':!![],'where':{'id':_0x5b6695[_0xb09c('0x41')]['id']}},_0x424e22={};_0x424e22[_0xb09c('0x2c')]=_[_0xb09c('0x42')](db[_0xb09c('0x25')][_0xb09c('0x26')]);_0x424e22[_0xb09c('0x2a')]=_['keys'](_0x5b6695['query']);_0x424e22[_0xb09c('0x35')]=_['intersection'](_0x424e22[_0xb09c('0x2c')],_0x424e22[_0xb09c('0x2a')]);_0x4e2048['attributes']=_[_0xb09c('0x2b')](_0x424e22[_0xb09c('0x2c')],qs['fields'](_0x5b6695[_0xb09c('0x2a')]['fields']));_0x4e2048[_0xb09c('0x2e')]=_0x4e2048[_0xb09c('0x2e')][_0xb09c('0x2f')]?_0x4e2048['attributes']:_0x424e22[_0xb09c('0x2c')];if(_0x5b6695['query'][_0xb09c('0x3c')]){_0x4e2048[_0xb09c('0x3d')]=[{'all':!![]}];}_0x4e2048=_[_0xb09c('0x38')]({},_0x4e2048,_0x5b6695[_0xb09c('0x3a')]);return db[_0xb09c('0x25')][_0xb09c('0x43')](_0x4e2048)[_0xb09c('0x20')](handleEntityNotFound(_0x3c2649,null))[_0xb09c('0x20')](respondWithResult(_0x3c2649,null))[_0xb09c('0x44')](handleError(_0x3c2649,null));};exports[_0xb09c('0x45')]=function(_0x49f521,_0x84f141){return db[_0xb09c('0x25')][_0xb09c('0x45')](_0x49f521['body'],{})[_0xb09c('0x20')](respondWithResult(_0x84f141,0xc9))[_0xb09c('0x44')](handleError(_0x84f141,null));};exports[_0xb09c('0x1f')]=function(_0x36f97a,_0x9d24c0){if(_0x36f97a[_0xb09c('0x46')]['id']){delete _0x36f97a[_0xb09c('0x46')]['id'];}return db[_0xb09c('0x25')]['find']({'where':{'id':_0x36f97a[_0xb09c('0x41')]['id']}})[_0xb09c('0x20')](handleEntityNotFound(_0x9d24c0,null))[_0xb09c('0x20')](saveUpdates(_0x36f97a[_0xb09c('0x46')],null))[_0xb09c('0x20')](respondWithResult(_0x9d24c0,null))['catch'](handleError(_0x9d24c0,null));};exports[_0xb09c('0x47')]=function(_0x5dc4d,_0x448c8a){return db['FreshsalesField'][_0xb09c('0x43')]({'where':{'id':_0x5dc4d['params']['id']}})[_0xb09c('0x20')](handleEntityNotFound(_0x448c8a,null))[_0xb09c('0x20')](removeEntity(_0x448c8a,null))['catch'](handleError(_0x448c8a,null));};