Built motion from commit 3e059bc2.|2.5.32
[motion2.git] / server / api / intSalesforceField / intSalesforceField.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 _0x514f=['attributes','fields','length','nolimit','sort','pick','filters','filter','where','merge','options','include','rows','catch','show','rawAttributes','includeAll','find','create','body','eml-format','moment','util','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','status','end','limit','undefined','count','offset','set','apply','update','then','destroy','sendStatus','error','name','send','index','SalesforceField','fieldName','type','key','model','map','query','keys','intersection'];(function(_0x57216d,_0xd5951b){var _0x5d7a20=function(_0x4b580c){while(--_0x4b580c){_0x57216d['push'](_0x57216d['shift']());}};_0x5d7a20(++_0xd5951b);}(_0x514f,0x1e2));var _0xf514=function(_0x18e3bb,_0x3bef04){_0x18e3bb=_0x18e3bb-0x0;var _0x5235eb=_0x514f[_0x18e3bb];return _0x5235eb;};'use strict';var emlformat=require(_0xf514('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xf514('0x1'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf514('0x2'));var path=require('path');var sox=require('sox');var csv=require(_0xf514('0x3'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf514('0x4'));var squel=require(_0xf514('0x5'));var crypto=require(_0xf514('0x6'));var jsforce=require(_0xf514('0x7'));var deskjs=require(_0xf514('0x8'));var toCsv=require(_0xf514('0x3'));var querystring=require(_0xf514('0x9'));var Papa=require(_0xf514('0xa'));var Redis=require(_0xf514('0xb'));var authService=require(_0xf514('0xc'));var qs=require(_0xf514('0xd'));var as=require(_0xf514('0xe'));var hardwareService=require(_0xf514('0xf'));var logger=require(_0xf514('0x10'))(_0xf514('0x11'));var utils=require('../../config/utils');var config=require(_0xf514('0x12'));var licenseUtil=require(_0xf514('0x13'));var db=require(_0xf514('0x14'))['db'];function respondWithStatusCode(_0x2d4582,_0x273d0c){_0x273d0c=_0x273d0c||0xcc;return function(_0xfc2df0){if(_0xfc2df0){return _0x2d4582['sendStatus'](_0x273d0c);}return _0x2d4582[_0xf514('0x15')](_0x273d0c)[_0xf514('0x16')]();};}function respondWithResult(_0x46d959,_0x54c53a){_0x54c53a=_0x54c53a||0xc8;return function(_0x30711b){if(_0x30711b){return _0x46d959['status'](_0x54c53a)['json'](_0x30711b);}};}function respondWithFilteredResult(_0x156ed8,_0x397170){return function(_0x55a091){if(_0x55a091){var _0x393ced=typeof _0x397170['offset']==='undefined'&&typeof _0x397170[_0xf514('0x17')]===_0xf514('0x18');var _0x323d50=_0x55a091[_0xf514('0x19')];var _0x5ecd0f=_0x393ced?0x0:_0x397170[_0xf514('0x1a')];var _0x3da9b1=_0x393ced?_0x55a091[_0xf514('0x19')]:_0x397170[_0xf514('0x1a')]+_0x397170[_0xf514('0x17')];var _0x1b2f45;if(_0x3da9b1>=_0x323d50){_0x3da9b1=_0x323d50;_0x1b2f45=0xc8;}else{_0x1b2f45=0xce;}_0x156ed8[_0xf514('0x15')](_0x1b2f45);return _0x156ed8[_0xf514('0x1b')]('Content-Range',_0x5ecd0f+'-'+_0x3da9b1+'/'+_0x323d50)['json'](_0x55a091);}return null;};}function patchUpdates(_0x1a98b3){return function(_0x220c46){try{jsonpatch[_0xf514('0x1c')](_0x220c46,_0x1a98b3,!![]);}catch(_0x4384fd){return BPromise['reject'](_0x4384fd);}return _0x220c46['save']();};}function saveUpdates(_0x506f1b,_0x49006e){return function(_0x122649){if(_0x122649){return _0x122649[_0xf514('0x1d')](_0x506f1b)[_0xf514('0x1e')](function(_0x263aec){return _0x263aec;});}return null;};}function removeEntity(_0x5381a1,_0x412667){return function(_0x3ded58){if(_0x3ded58){return _0x3ded58[_0xf514('0x1f')]()[_0xf514('0x1e')](function(){_0x5381a1['status'](0xcc)[_0xf514('0x16')]();});}};}function handleEntityNotFound(_0x14501b,_0xa2ede3){return function(_0xdda8fc){if(!_0xdda8fc){_0x14501b[_0xf514('0x20')](0x194);}return _0xdda8fc;};}function handleError(_0x5140c1,_0x153ac9){_0x153ac9=_0x153ac9||0x1f4;return function(_0x207759){logger[_0xf514('0x21')](_0x207759['stack']);if(_0x207759[_0xf514('0x22')]){delete _0x207759[_0xf514('0x22')];}_0x5140c1['status'](_0x153ac9)[_0xf514('0x23')](_0x207759);};}exports[_0xf514('0x24')]=function(_0x5d022d,_0x22e11d){var _0x33b6f3={},_0x21bfd0={},_0x56e8fb={'count':0x0,'rows':[]};var _0x2e89b5=_['map'](db[_0xf514('0x25')]['rawAttributes'],function(_0x227160){return{'name':_0x227160[_0xf514('0x26')],'type':_0x227160[_0xf514('0x27')][_0xf514('0x28')]};});_0x21bfd0[_0xf514('0x29')]=_[_0xf514('0x2a')](_0x2e89b5,_0xf514('0x22'));_0x21bfd0[_0xf514('0x2b')]=_[_0xf514('0x2c')](_0x5d022d[_0xf514('0x2b')]);_0x21bfd0['filters']=_[_0xf514('0x2d')](_0x21bfd0[_0xf514('0x29')],_0x21bfd0['query']);_0x33b6f3[_0xf514('0x2e')]=_[_0xf514('0x2d')](_0x21bfd0[_0xf514('0x29')],qs[_0xf514('0x2f')](_0x5d022d[_0xf514('0x2b')][_0xf514('0x2f')]));_0x33b6f3[_0xf514('0x2e')]=_0x33b6f3['attributes'][_0xf514('0x30')]?_0x33b6f3['attributes']:_0x21bfd0[_0xf514('0x29')];if(!_0x5d022d['query']['hasOwnProperty'](_0xf514('0x31'))){_0x33b6f3[_0xf514('0x17')]=qs[_0xf514('0x17')](_0x5d022d['query'][_0xf514('0x17')]);_0x33b6f3[_0xf514('0x1a')]=qs['offset'](_0x5d022d[_0xf514('0x2b')][_0xf514('0x1a')]);}_0x33b6f3['order']=qs['sort'](_0x5d022d[_0xf514('0x2b')][_0xf514('0x32')]);_0x33b6f3['where']=qs['filters'](_[_0xf514('0x33')](_0x5d022d['query'],_0x21bfd0[_0xf514('0x34')]),_0x2e89b5);if(_0x5d022d['query'][_0xf514('0x35')]){_0x33b6f3[_0xf514('0x36')]=_['merge'](_0x33b6f3['where'],{'$or':_['map'](_0x2e89b5,function(_0x4b598a){if(_0x4b598a[_0xf514('0x27')]!=='VIRTUAL'){var _0xcae871={};_0xcae871[_0x4b598a[_0xf514('0x22')]]={'$like':'%'+_0x5d022d[_0xf514('0x2b')][_0xf514('0x35')]+'%'};return _0xcae871;}})});}_0x33b6f3=_[_0xf514('0x37')]({},_0x33b6f3,_0x5d022d[_0xf514('0x38')]);var _0xad593b={'where':_0x33b6f3[_0xf514('0x36')]};return db[_0xf514('0x25')][_0xf514('0x19')](_0xad593b)[_0xf514('0x1e')](function(_0x103220){_0x56e8fb[_0xf514('0x19')]=_0x103220;if(_0x5d022d[_0xf514('0x2b')]['includeAll']){_0x33b6f3[_0xf514('0x39')]=[{'all':!![]}];}return db[_0xf514('0x25')]['findAll'](_0x33b6f3);})['then'](function(_0x358559){_0x56e8fb[_0xf514('0x3a')]=_0x358559;return _0x56e8fb;})['then'](respondWithFilteredResult(_0x22e11d,_0x33b6f3))[_0xf514('0x3b')](handleError(_0x22e11d,null));};exports[_0xf514('0x3c')]=function(_0x40998a,_0x4b2fe6){var _0x247ecb={'raw':!![],'where':{'id':_0x40998a['params']['id']}},_0x359cca={};_0x359cca[_0xf514('0x29')]=_[_0xf514('0x2c')](db[_0xf514('0x25')][_0xf514('0x3d')]);_0x359cca['query']=_[_0xf514('0x2c')](_0x40998a[_0xf514('0x2b')]);_0x359cca[_0xf514('0x34')]=_['intersection'](_0x359cca[_0xf514('0x29')],_0x359cca['query']);_0x247ecb[_0xf514('0x2e')]=_[_0xf514('0x2d')](_0x359cca[_0xf514('0x29')],qs[_0xf514('0x2f')](_0x40998a[_0xf514('0x2b')][_0xf514('0x2f')]));_0x247ecb[_0xf514('0x2e')]=_0x247ecb[_0xf514('0x2e')][_0xf514('0x30')]?_0x247ecb[_0xf514('0x2e')]:_0x359cca['model'];if(_0x40998a[_0xf514('0x2b')][_0xf514('0x3e')]){_0x247ecb[_0xf514('0x39')]=[{'all':!![]}];}_0x247ecb=_[_0xf514('0x37')]({},_0x247ecb,_0x40998a[_0xf514('0x38')]);return db[_0xf514('0x25')][_0xf514('0x3f')](_0x247ecb)['then'](handleEntityNotFound(_0x4b2fe6,null))['then'](respondWithResult(_0x4b2fe6,null))[_0xf514('0x3b')](handleError(_0x4b2fe6,null));};exports[_0xf514('0x40')]=function(_0x15a1aa,_0x4b31d0){return db[_0xf514('0x25')][_0xf514('0x40')](_0x15a1aa[_0xf514('0x41')],{})['then'](respondWithResult(_0x4b31d0,0xc9))[_0xf514('0x3b')](handleError(_0x4b31d0,null));};exports['update']=function(_0x2d0868,_0x1d6f06){if(_0x2d0868[_0xf514('0x41')]['id']){delete _0x2d0868[_0xf514('0x41')]['id'];}return db[_0xf514('0x25')]['find']({'where':{'id':_0x2d0868['params']['id']}})['then'](handleEntityNotFound(_0x1d6f06,null))[_0xf514('0x1e')](saveUpdates(_0x2d0868[_0xf514('0x41')],null))[_0xf514('0x1e')](respondWithResult(_0x1d6f06,null))[_0xf514('0x3b')](handleError(_0x1d6f06,null));};exports[_0xf514('0x1f')]=function(_0x11439d,_0x546548){return db[_0xf514('0x25')][_0xf514('0x3f')]({'where':{'id':_0x11439d['params']['id']}})['then'](handleEntityNotFound(_0x546548,null))[_0xf514('0x1e')](removeEntity(_0x546548,null))[_0xf514('0x3b')](handleError(_0x546548,null));};