Built motion from commit (unavailable).|2.0.71
[motion2.git] / server / api / integrationReport / integrationReport.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 _0xbf3e=['filters','pick','add','day','filter','where','map','options','includeAll','findAll','rows','params','include','merge','find','catch','create','body','describe','fast-json-patch','mustache','util','path','sox','to-csv','lodash','squel','jsforce','desk.js','querystring','papaparse','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','end','json','count','offset','status','set','Content-Range','apply','reject','save','update','destroy','then','sendStatus','error','stack','name','send','IntegrationReport','rawAttributes','keys','query','dateStart','dateEnd','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','limit','order','sort'];(function(_0x56da86,_0x21b697){var _0xd5c69=function(_0x1352cc){while(--_0x1352cc){_0x56da86['push'](_0x56da86['shift']());}};_0xd5c69(++_0x21b697);}(_0xbf3e,0x9f));var _0xebf3=function(_0xa376c0,_0x45a998){_0xa376c0=_0xa376c0-0x0;var _0x10dd1a=_0xbf3e[_0xa376c0];return _0x10dd1a;};'use strict';var jsonpatch=require(_0xebf3('0x0'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xebf3('0x1'));var util=require(_0xebf3('0x2'));var path=require(_0xebf3('0x3'));var sox=require(_0xebf3('0x4'));var csv=require(_0xebf3('0x5'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xebf3('0x6'));var squel=require(_0xebf3('0x7'));var crypto=require('crypto');var jsforce=require(_0xebf3('0x8'));var deskjs=require(_0xebf3('0x9'));var toCsv=require(_0xebf3('0x5'));var querystring=require(_0xebf3('0xa'));var Papa=require(_0xebf3('0xb'));var qs=require('../../components/parsers/qs');var logger=require(_0xebf3('0xc'))(_0xebf3('0xd'));var utils=require(_0xebf3('0xe'));var config=require(_0xebf3('0xf'));var db=require(_0xebf3('0x10'))['db'];function respondWithStatusCode(_0x559e0a,_0x14c1b3){_0x14c1b3=_0x14c1b3||0xcc;return function(_0x325785){if(_0x325785){return _0x559e0a['sendStatus'](_0x14c1b3);}return _0x559e0a['status'](_0x14c1b3)[_0xebf3('0x11')]();};}function respondWithResult(_0x80939e,_0x3b375e){_0x3b375e=_0x3b375e||0xc8;return function(_0x3d86d5){if(_0x3d86d5){return _0x80939e['status'](_0x3b375e)[_0xebf3('0x12')](_0x3d86d5);}};}function respondWithFilteredResult(_0x108e58,_0x5d19f0){return function(_0x3cd9f4){if(_0x3cd9f4){var _0x51d5af=_0x3cd9f4[_0xebf3('0x13')],_0x2ba114=_0x5d19f0['offset'],_0x1791c3=_0x5d19f0[_0xebf3('0x14')]+_0x5d19f0['limit'],_0x5ce775;if(_0x1791c3>=_0x51d5af){_0x1791c3=_0x51d5af;_0x5ce775=0xc8;}else{_0x5ce775=0xce;}_0x108e58[_0xebf3('0x15')](_0x5ce775);return _0x108e58[_0xebf3('0x16')](_0xebf3('0x17'),_0x2ba114+'-'+_0x1791c3+'/'+_0x51d5af)[_0xebf3('0x12')](_0x3cd9f4);}return null;};}function patchUpdates(_0x13b440){return function(_0x3285ea){try{jsonpatch[_0xebf3('0x18')](_0x3285ea,_0x13b440,!![]);}catch(_0x58b17a){return BPromise[_0xebf3('0x19')](_0x58b17a);}return _0x3285ea[_0xebf3('0x1a')]();};}function saveUpdates(_0x31bde7,_0x35bcb9){return function(_0x421eb5){if(_0x421eb5){return _0x421eb5[_0xebf3('0x1b')](_0x31bde7)['then'](function(_0xe8db56){return _0xe8db56;});}return null;};}function removeEntity(_0x505f6d,_0xb29cb){return function(_0x58c5de){if(_0x58c5de){return _0x58c5de[_0xebf3('0x1c')]()[_0xebf3('0x1d')](function(){_0x505f6d['status'](0xcc)[_0xebf3('0x11')]();});}};}function handleEntityNotFound(_0x40125c,_0x1c4c29){return function(_0x1a7c19){if(!_0x1a7c19){_0x40125c[_0xebf3('0x1e')](0x194);}return _0x1a7c19;};}function handleError(_0x49c242,_0x2a9a42){_0x2a9a42=_0x2a9a42||0x1f4;return function(_0x3cea98){logger[_0xebf3('0x1f')](_0x3cea98[_0xebf3('0x20')]);if(_0x3cea98[_0xebf3('0x21')]){delete _0x3cea98[_0xebf3('0x21')];}_0x49c242[_0xebf3('0x15')](_0x2a9a42)[_0xebf3('0x22')](_0x3cea98);};}exports['index']=function(_0xb023c0,_0x16db5c){var _0x2331df={},_0x4201b1={},_0x1a5cff={'count':0x0,'rows':[]};var _0x143e70=db[_0xebf3('0x23')][_0xebf3('0x24')];_0x4201b1['model']=_[_0xebf3('0x25')](_0x143e70);var _0x4ef38e={'dateStart':_0xb023c0[_0xebf3('0x26')][_0xebf3('0x27')],'dateEnd':_0xb023c0['query']['dateEnd']};delete _0xb023c0[_0xebf3('0x26')][_0xebf3('0x27')];delete _0xb023c0[_0xebf3('0x26')][_0xebf3('0x28')];_0x4201b1[_0xebf3('0x26')]=_[_0xebf3('0x25')](_0xb023c0[_0xebf3('0x26')]);_0x4201b1['filters']=_[_0xebf3('0x29')](_0x4201b1[_0xebf3('0x2a')],_0x4201b1[_0xebf3('0x26')]);_0x2331df['attributes']=_[_0xebf3('0x29')](_0x4201b1[_0xebf3('0x2a')],qs['fields'](_0xb023c0['query'][_0xebf3('0x2b')]));_0x2331df[_0xebf3('0x2c')]=_0x2331df[_0xebf3('0x2c')][_0xebf3('0x2d')]?_0x2331df['attributes']:_0x4201b1[_0xebf3('0x2a')];if(!_0xb023c0[_0xebf3('0x26')][_0xebf3('0x2e')](_0xebf3('0x2f'))){_0x2331df[_0xebf3('0x30')]=qs[_0xebf3('0x30')](_0xb023c0[_0xebf3('0x26')]['limit']);_0x2331df[_0xebf3('0x14')]=qs['offset'](_0xb023c0['query'][_0xebf3('0x14')]);}_0x2331df[_0xebf3('0x31')]=qs[_0xebf3('0x32')](_0xb023c0[_0xebf3('0x26')][_0xebf3('0x32')]);_0x2331df['where']=qs[_0xebf3('0x33')](_[_0xebf3('0x34')](_0xb023c0[_0xebf3('0x26')],_0x4201b1['filters']));if(_0x4ef38e[_0xebf3('0x27')]){if(_0x4ef38e[_0xebf3('0x28')]){_0x4ef38e[_0xebf3('0x28')]=moment(_0x4ef38e['dateEnd'])[_0xebf3('0x35')](0x1,_0xebf3('0x36'));}else{_0x4ef38e[_0xebf3('0x28')]=moment(_0x4ef38e[_0xebf3('0x27')])['add'](0x1,_0xebf3('0x36'));}_['merge'](_0x2331df['where'],{'createdAt':{'$gte':_0x4ef38e[_0xebf3('0x27')],'$lte':_0x4ef38e[_0xebf3('0x28')]}});}if(_0xb023c0[_0xebf3('0x26')][_0xebf3('0x37')]){_0x2331df[_0xebf3('0x38')]=_['merge'](_0x2331df['where'],{'$or':_[_0xebf3('0x39')](_0x2331df['attributes'],function(_0x328d5e){var _0x5a3c27={};_0x5a3c27[_0x328d5e]={'$like':'%'+_0xb023c0['query'][_0xebf3('0x37')]+'%'};return _0x5a3c27;})});}_0x2331df=_['merge']({},_0x2331df,_0xb023c0[_0xebf3('0x3a')]);var _0x43e419={'where':_0x2331df[_0xebf3('0x38')]};return db['IntegrationReport'][_0xebf3('0x13')](_0x43e419)[_0xebf3('0x1d')](function(_0x37f926){_0x1a5cff['count']=_0x37f926;if(_0xb023c0['query'][_0xebf3('0x3b')]){_0x2331df['include']=[{'all':!![]}];}return db[_0xebf3('0x23')][_0xebf3('0x3c')](_0x2331df);})[_0xebf3('0x1d')](function(_0x2ab54d){_0x1a5cff[_0xebf3('0x3d')]=_0x2ab54d;return _0x1a5cff;})[_0xebf3('0x1d')](respondWithFilteredResult(_0x16db5c,_0x2331df))['catch'](handleError(_0x16db5c,null));};exports['show']=function(_0x41de08,_0x1c279e){var _0x10cbb8={'raw':![],'where':{'id':_0x41de08[_0xebf3('0x3e')]['id']}},_0x39c13f={};_0x39c13f[_0xebf3('0x2a')]=_[_0xebf3('0x25')](db[_0xebf3('0x23')]['rawAttributes']);_0x39c13f[_0xebf3('0x26')]=_[_0xebf3('0x25')](_0x41de08[_0xebf3('0x26')]);_0x39c13f[_0xebf3('0x33')]=_[_0xebf3('0x29')](_0x39c13f[_0xebf3('0x2a')],_0x39c13f[_0xebf3('0x26')]);_0x10cbb8[_0xebf3('0x2c')]=_[_0xebf3('0x29')](_0x39c13f[_0xebf3('0x2a')],qs['fields'](_0x41de08['query'][_0xebf3('0x2b')]));_0x10cbb8[_0xebf3('0x2c')]=_0x10cbb8[_0xebf3('0x2c')][_0xebf3('0x2d')]?_0x10cbb8[_0xebf3('0x2c')]:_0x39c13f[_0xebf3('0x2a')];if(_0x41de08[_0xebf3('0x26')][_0xebf3('0x3b')]){_0x10cbb8[_0xebf3('0x3f')]=[{'all':!![]}];}_0x10cbb8=_[_0xebf3('0x40')]({},_0x10cbb8,_0x41de08[_0xebf3('0x3a')]);return db['IntegrationReport'][_0xebf3('0x41')](_0x10cbb8)[_0xebf3('0x1d')](handleEntityNotFound(_0x1c279e,null))[_0xebf3('0x1d')](respondWithResult(_0x1c279e,null))[_0xebf3('0x42')](handleError(_0x1c279e,null));};exports['create']=function(_0x59f41a,_0xf2041d){return db[_0xebf3('0x23')][_0xebf3('0x43')](_0x59f41a[_0xebf3('0x44')],{})[_0xebf3('0x1d')](respondWithResult(_0xf2041d,0xc9))[_0xebf3('0x42')](handleError(_0xf2041d,null));};exports['update']=function(_0x4a3c4d,_0x10a1fb){if(_0x4a3c4d[_0xebf3('0x44')]['id']){delete _0x4a3c4d[_0xebf3('0x44')]['id'];}return db[_0xebf3('0x23')][_0xebf3('0x41')]({'where':{'id':_0x4a3c4d[_0xebf3('0x3e')]['id']}})[_0xebf3('0x1d')](handleEntityNotFound(_0x10a1fb,null))['then'](saveUpdates(_0x4a3c4d[_0xebf3('0x44')],null))[_0xebf3('0x1d')](respondWithResult(_0x10a1fb,null))['catch'](handleError(_0x10a1fb,null));};exports['destroy']=function(_0x212458,_0x27eb8c){return db[_0xebf3('0x23')][_0xebf3('0x41')]({'where':{'id':_0x212458[_0xebf3('0x3e')]['id']}})[_0xebf3('0x1d')](handleEntityNotFound(_0x27eb8c,null))['then'](removeEntity(_0x27eb8c,null))[_0xebf3('0x42')](handleError(_0x27eb8c,null));};exports[_0xebf3('0x45')]=function(_0x567f8f,_0x2c79a3){return db[_0xebf3('0x23')][_0xebf3('0x45')]()[_0xebf3('0x1d')](respondWithResult(_0x2c79a3,null))['catch'](handleError(_0x2c79a3,null));};