b9e1e13b17c847dba049d035aac1fa44b33932c5
[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 _0x1f28=['update','then','destroy','sendStatus','error','name','send','index','map','SalesforceField','fieldName','type','key','keys','filters','intersection','model','query','attributes','fields','nolimit','order','sort','pick','where','filter','merge','options','includeAll','findAll','rows','catch','show','params','rawAttributes','find','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','end','status','json','count','offset','limit','set','Content-Range','save'];(function(_0xf0f95d,_0x3c8d2b){var _0x2443ab=function(_0xa4fb0b){while(--_0xa4fb0b){_0xf0f95d['push'](_0xf0f95d['shift']());}};_0x2443ab(++_0x3c8d2b);}(_0x1f28,0x1d5));var _0x81f2=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0x1f28[_0x2641f9];return _0x585741;};'use strict';var pdf=require(_0x81f2('0x0'));var emlformat=require(_0x81f2('0x1'));var rimraf=require(_0x81f2('0x2'));var zipdir=require(_0x81f2('0x3'));var jsonpatch=require(_0x81f2('0x4'));var rp=require(_0x81f2('0x5'));var moment=require(_0x81f2('0x6'));var BPromise=require(_0x81f2('0x7'));var Mustache=require(_0x81f2('0x8'));var util=require('util');var path=require(_0x81f2('0x9'));var sox=require(_0x81f2('0xa'));var csv=require(_0x81f2('0xb'));var ejs=require(_0x81f2('0xc'));var fs=require('fs');var _=require(_0x81f2('0xd'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x81f2('0xe'));var deskjs=require(_0x81f2('0xf'));var toCsv=require('to-csv');var querystring=require(_0x81f2('0x10'));var Papa=require(_0x81f2('0x11'));var Redis=require(_0x81f2('0x12'));var authService=require(_0x81f2('0x13'));var qs=require(_0x81f2('0x14'));var as=require(_0x81f2('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x81f2('0x16'))(_0x81f2('0x17'));var utils=require(_0x81f2('0x18'));var config=require(_0x81f2('0x19'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1031b4,_0x503f36){_0x503f36=_0x503f36||0xcc;return function(_0xf67e7f){if(_0xf67e7f){return _0x1031b4['sendStatus'](_0x503f36);}return _0x1031b4['status'](_0x503f36)[_0x81f2('0x1a')]();};}function respondWithResult(_0x3ffc56,_0x489c8a){_0x489c8a=_0x489c8a||0xc8;return function(_0x3aefb2){if(_0x3aefb2){return _0x3ffc56[_0x81f2('0x1b')](_0x489c8a)[_0x81f2('0x1c')](_0x3aefb2);}};}function respondWithFilteredResult(_0x5d7299,_0xc4caa8){return function(_0x538968){if(_0x538968){var _0x3525c0=_0x538968[_0x81f2('0x1d')],_0x393e2e=_0xc4caa8[_0x81f2('0x1e')],_0x398adf=_0xc4caa8[_0x81f2('0x1e')]+_0xc4caa8[_0x81f2('0x1f')],_0x23f353;if(_0x398adf>=_0x3525c0){_0x398adf=_0x3525c0;_0x23f353=0xc8;}else{_0x23f353=0xce;}_0x5d7299[_0x81f2('0x1b')](_0x23f353);return _0x5d7299[_0x81f2('0x20')](_0x81f2('0x21'),_0x393e2e+'-'+_0x398adf+'/'+_0x3525c0)[_0x81f2('0x1c')](_0x538968);}return null;};}function patchUpdates(_0x55afc1){return function(_0x442df3){try{jsonpatch['apply'](_0x442df3,_0x55afc1,!![]);}catch(_0x983290){return BPromise['reject'](_0x983290);}return _0x442df3[_0x81f2('0x22')]();};}function saveUpdates(_0x200e2f,_0x5acec3){return function(_0x17e09c){if(_0x17e09c){return _0x17e09c[_0x81f2('0x23')](_0x200e2f)[_0x81f2('0x24')](function(_0x28485e){return _0x28485e;});}return null;};}function removeEntity(_0x1755c5,_0x5c28c5){return function(_0x2bfd0d){if(_0x2bfd0d){return _0x2bfd0d[_0x81f2('0x25')]()[_0x81f2('0x24')](function(){_0x1755c5[_0x81f2('0x1b')](0xcc)[_0x81f2('0x1a')]();});}};}function handleEntityNotFound(_0x126c53,_0x35088b){return function(_0x387796){if(!_0x387796){_0x126c53[_0x81f2('0x26')](0x194);}return _0x387796;};}function handleError(_0x598baf,_0x3a0a7e){_0x3a0a7e=_0x3a0a7e||0x1f4;return function(_0xa34bb0){logger[_0x81f2('0x27')](_0xa34bb0['stack']);if(_0xa34bb0[_0x81f2('0x28')]){delete _0xa34bb0[_0x81f2('0x28')];}_0x598baf['status'](_0x3a0a7e)[_0x81f2('0x29')](_0xa34bb0);};}exports[_0x81f2('0x2a')]=function(_0x10b333,_0x5b57c0){var _0x234380={},_0x2009be={},_0x295842={'count':0x0,'rows':[]};var _0x22ae5c=_[_0x81f2('0x2b')](db[_0x81f2('0x2c')]['rawAttributes'],function(_0x556275){return{'name':_0x556275[_0x81f2('0x2d')],'type':_0x556275[_0x81f2('0x2e')][_0x81f2('0x2f')]};});_0x2009be['model']=_[_0x81f2('0x2b')](_0x22ae5c,_0x81f2('0x28'));_0x2009be['query']=_[_0x81f2('0x30')](_0x10b333['query']);_0x2009be[_0x81f2('0x31')]=_[_0x81f2('0x32')](_0x2009be[_0x81f2('0x33')],_0x2009be[_0x81f2('0x34')]);_0x234380[_0x81f2('0x35')]=_[_0x81f2('0x32')](_0x2009be[_0x81f2('0x33')],qs[_0x81f2('0x36')](_0x10b333['query'][_0x81f2('0x36')]));_0x234380['attributes']=_0x234380[_0x81f2('0x35')]['length']?_0x234380['attributes']:_0x2009be[_0x81f2('0x33')];if(!_0x10b333[_0x81f2('0x34')]['hasOwnProperty'](_0x81f2('0x37'))){_0x234380[_0x81f2('0x1f')]=qs['limit'](_0x10b333[_0x81f2('0x34')][_0x81f2('0x1f')]);_0x234380[_0x81f2('0x1e')]=qs['offset'](_0x10b333['query'][_0x81f2('0x1e')]);}_0x234380[_0x81f2('0x38')]=qs[_0x81f2('0x39')](_0x10b333[_0x81f2('0x34')][_0x81f2('0x39')]);_0x234380['where']=qs[_0x81f2('0x31')](_[_0x81f2('0x3a')](_0x10b333[_0x81f2('0x34')],_0x2009be[_0x81f2('0x31')]),_0x22ae5c);if(_0x10b333[_0x81f2('0x34')]['filter']){_0x234380[_0x81f2('0x3b')]=_['merge'](_0x234380[_0x81f2('0x3b')],{'$or':_[_0x81f2('0x2b')](_0x22ae5c,function(_0x35aa2c){if(_0x35aa2c[_0x81f2('0x2e')]!=='VIRTUAL'){var _0x50f5a2={};_0x50f5a2[_0x35aa2c[_0x81f2('0x28')]]={'$like':'%'+_0x10b333['query'][_0x81f2('0x3c')]+'%'};return _0x50f5a2;}})});}_0x234380=_[_0x81f2('0x3d')]({},_0x234380,_0x10b333[_0x81f2('0x3e')]);var _0x24e4f9={'where':_0x234380['where']};return db['SalesforceField']['count'](_0x24e4f9)[_0x81f2('0x24')](function(_0x4ee944){_0x295842[_0x81f2('0x1d')]=_0x4ee944;if(_0x10b333[_0x81f2('0x34')][_0x81f2('0x3f')]){_0x234380['include']=[{'all':!![]}];}return db['SalesforceField'][_0x81f2('0x40')](_0x234380);})[_0x81f2('0x24')](function(_0x330e33){_0x295842[_0x81f2('0x41')]=_0x330e33;return _0x295842;})['then'](respondWithFilteredResult(_0x5b57c0,_0x234380))[_0x81f2('0x42')](handleError(_0x5b57c0,null));};exports[_0x81f2('0x43')]=function(_0x8f7351,_0x8a6007){var _0x1f3176={'raw':!![],'where':{'id':_0x8f7351[_0x81f2('0x44')]['id']}},_0x145759={};_0x145759[_0x81f2('0x33')]=_[_0x81f2('0x30')](db[_0x81f2('0x2c')][_0x81f2('0x45')]);_0x145759[_0x81f2('0x34')]=_[_0x81f2('0x30')](_0x8f7351[_0x81f2('0x34')]);_0x145759[_0x81f2('0x31')]=_['intersection'](_0x145759['model'],_0x145759[_0x81f2('0x34')]);_0x1f3176[_0x81f2('0x35')]=_['intersection'](_0x145759['model'],qs[_0x81f2('0x36')](_0x8f7351[_0x81f2('0x34')][_0x81f2('0x36')]));_0x1f3176['attributes']=_0x1f3176[_0x81f2('0x35')]['length']?_0x1f3176[_0x81f2('0x35')]:_0x145759[_0x81f2('0x33')];if(_0x8f7351[_0x81f2('0x34')][_0x81f2('0x3f')]){_0x1f3176['include']=[{'all':!![]}];}_0x1f3176=_[_0x81f2('0x3d')]({},_0x1f3176,_0x8f7351[_0x81f2('0x3e')]);return db[_0x81f2('0x2c')][_0x81f2('0x46')](_0x1f3176)[_0x81f2('0x24')](handleEntityNotFound(_0x8a6007,null))[_0x81f2('0x24')](respondWithResult(_0x8a6007,null))[_0x81f2('0x42')](handleError(_0x8a6007,null));};exports['create']=function(_0x1af9a4,_0x1269a6){return db['SalesforceField']['create'](_0x1af9a4[_0x81f2('0x47')],{})['then'](respondWithResult(_0x1269a6,0xc9))['catch'](handleError(_0x1269a6,null));};exports[_0x81f2('0x23')]=function(_0x416755,_0x37b5db){if(_0x416755[_0x81f2('0x47')]['id']){delete _0x416755[_0x81f2('0x47')]['id'];}return db[_0x81f2('0x2c')][_0x81f2('0x46')]({'where':{'id':_0x416755[_0x81f2('0x44')]['id']}})['then'](handleEntityNotFound(_0x37b5db,null))[_0x81f2('0x24')](saveUpdates(_0x416755[_0x81f2('0x47')],null))[_0x81f2('0x24')](respondWithResult(_0x37b5db,null))[_0x81f2('0x42')](handleError(_0x37b5db,null));};exports[_0x81f2('0x25')]=function(_0x1d5302,_0x47b015){return db[_0x81f2('0x2c')]['find']({'where':{'id':_0x1d5302[_0x81f2('0x44')]['id']}})[_0x81f2('0x24')](handleEntityNotFound(_0x47b015,null))[_0x81f2('0x24')](removeEntity(_0x47b015,null))[_0x81f2('0x42')](handleError(_0x47b015,null));};