Built motion from commit (unavailable).|2.4.17
[motion2.git] / server / api / faxApplication / faxApplication.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 _0x1f63=['api','../../config/utils','../../mysqldb','sendStatus','status','end','offset','set','Content-Range','json','apply','reject','update','then','destroy','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','limit','sort','filters','where','VIRTUAL','filter','merge','options','FaxApplication','count','include','findAll','rows','params','includeAll','find','catch','create','body','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','sox','to-csv','ejs','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger'];(function(_0x2641f9,_0x26715f){var _0x585741=function(_0x2d1462){while(--_0x2d1462){_0x2641f9['push'](_0x2641f9['shift']());}};_0x585741(++_0x26715f);}(_0x1f63,0x7a));var _0x31f6=function(_0x36567d,_0x426fc8){_0x36567d=_0x36567d-0x0;var _0x47e178=_0x1f63[_0x36567d];return _0x47e178;};'use strict';var pdf=require(_0x31f6('0x0'));var emlformat=require(_0x31f6('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x31f6('0x2'));var jsonpatch=require(_0x31f6('0x3'));var rp=require(_0x31f6('0x4'));var moment=require('moment');var BPromise=require(_0x31f6('0x5'));var Mustache=require(_0x31f6('0x6'));var util=require('util');var path=require('path');var sox=require(_0x31f6('0x7'));var csv=require(_0x31f6('0x8'));var ejs=require(_0x31f6('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0x31f6('0xa'));var crypto=require(_0x31f6('0xb'));var jsforce=require(_0x31f6('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x31f6('0xd'));var Papa=require('papaparse');var Redis=require(_0x31f6('0xe'));var authService=require(_0x31f6('0xf'));var qs=require(_0x31f6('0x10'));var as=require(_0x31f6('0x11'));var hardwareService=require(_0x31f6('0x12'));var logger=require(_0x31f6('0x13'))(_0x31f6('0x14'));var utils=require(_0x31f6('0x15'));var config=require('../../config/environment');var db=require(_0x31f6('0x16'))['db'];function respondWithStatusCode(_0x29dc39,_0x47308d){_0x47308d=_0x47308d||0xcc;return function(_0x380f07){if(_0x380f07){return _0x29dc39[_0x31f6('0x17')](_0x47308d);}return _0x29dc39[_0x31f6('0x18')](_0x47308d)[_0x31f6('0x19')]();};}function respondWithResult(_0x2f1755,_0x2a1550){_0x2a1550=_0x2a1550||0xc8;return function(_0x535bca){if(_0x535bca){return _0x2f1755[_0x31f6('0x18')](_0x2a1550)['json'](_0x535bca);}};}function respondWithFilteredResult(_0x1b11b7,_0x5dba49){return function(_0x3642ef){if(_0x3642ef){var _0xd8c7a7=_0x3642ef['count'],_0x142833=_0x5dba49[_0x31f6('0x1a')],_0xb42717=_0x5dba49[_0x31f6('0x1a')]+_0x5dba49['limit'],_0x1af6d2;if(_0xb42717>=_0xd8c7a7){_0xb42717=_0xd8c7a7;_0x1af6d2=0xc8;}else{_0x1af6d2=0xce;}_0x1b11b7[_0x31f6('0x18')](_0x1af6d2);return _0x1b11b7[_0x31f6('0x1b')](_0x31f6('0x1c'),_0x142833+'-'+_0xb42717+'/'+_0xd8c7a7)[_0x31f6('0x1d')](_0x3642ef);}return null;};}function patchUpdates(_0xe7b2d9){return function(_0x5af106){try{jsonpatch[_0x31f6('0x1e')](_0x5af106,_0xe7b2d9,!![]);}catch(_0x374be3){return BPromise[_0x31f6('0x1f')](_0x374be3);}return _0x5af106['save']();};}function saveUpdates(_0x457184,_0x581387){return function(_0x12b584){if(_0x12b584){return _0x12b584[_0x31f6('0x20')](_0x457184)[_0x31f6('0x21')](function(_0x2612c7){return _0x2612c7;});}return null;};}function removeEntity(_0x10f7b6,_0x362750){return function(_0x4ba18c){if(_0x4ba18c){return _0x4ba18c[_0x31f6('0x22')]()[_0x31f6('0x21')](function(){_0x10f7b6['status'](0xcc)[_0x31f6('0x19')]();});}};}function handleEntityNotFound(_0x12232e,_0x4806d8){return function(_0xb47f15){if(!_0xb47f15){_0x12232e[_0x31f6('0x17')](0x194);}return _0xb47f15;};}function handleError(_0x51ce0a,_0x560d44){_0x560d44=_0x560d44||0x1f4;return function(_0x4c8794){logger['error'](_0x4c8794['stack']);if(_0x4c8794['name']){delete _0x4c8794[_0x31f6('0x23')];}_0x51ce0a['status'](_0x560d44)[_0x31f6('0x24')](_0x4c8794);};}exports[_0x31f6('0x25')]=function(_0x514ce4,_0x2940f1){var _0x1f334f={},_0x313ae1={},_0x322e55={'count':0x0,'rows':[]};var _0xf3a033=_[_0x31f6('0x26')](db['FaxApplication'][_0x31f6('0x27')],function(_0x30a2f2){return{'name':_0x30a2f2[_0x31f6('0x28')],'type':_0x30a2f2[_0x31f6('0x29')][_0x31f6('0x2a')]};});_0x313ae1[_0x31f6('0x2b')]=_['map'](_0xf3a033,_0x31f6('0x23'));_0x313ae1[_0x31f6('0x2c')]=_[_0x31f6('0x2d')](_0x514ce4[_0x31f6('0x2c')]);_0x313ae1['filters']=_['intersection'](_0x313ae1[_0x31f6('0x2b')],_0x313ae1[_0x31f6('0x2c')]);_0x1f334f['attributes']=_[_0x31f6('0x2e')](_0x313ae1[_0x31f6('0x2b')],qs['fields'](_0x514ce4[_0x31f6('0x2c')][_0x31f6('0x2f')]));_0x1f334f[_0x31f6('0x30')]=_0x1f334f[_0x31f6('0x30')][_0x31f6('0x31')]?_0x1f334f['attributes']:_0x313ae1[_0x31f6('0x2b')];if(!_0x514ce4[_0x31f6('0x2c')][_0x31f6('0x32')](_0x31f6('0x33'))){_0x1f334f[_0x31f6('0x34')]=qs[_0x31f6('0x34')](_0x514ce4[_0x31f6('0x2c')][_0x31f6('0x34')]);_0x1f334f[_0x31f6('0x1a')]=qs[_0x31f6('0x1a')](_0x514ce4['query'][_0x31f6('0x1a')]);}_0x1f334f['order']=qs[_0x31f6('0x35')](_0x514ce4['query'][_0x31f6('0x35')]);_0x1f334f['where']=qs['filters'](_['pick'](_0x514ce4['query'],_0x313ae1[_0x31f6('0x36')]));if(_0x514ce4[_0x31f6('0x2c')]['filter']){_0x1f334f[_0x31f6('0x37')]=_['merge'](_0x1f334f[_0x31f6('0x37')],{'$or':_[_0x31f6('0x26')](_0xf3a033,function(_0x4ec6b7){if(_0x4ec6b7['type']!==_0x31f6('0x38')){var _0x3da93c={};_0x3da93c[_0x4ec6b7[_0x31f6('0x23')]]={'$like':'%'+_0x514ce4[_0x31f6('0x2c')][_0x31f6('0x39')]+'%'};return _0x3da93c;}})});}_0x1f334f=_[_0x31f6('0x3a')]({},_0x1f334f,_0x514ce4[_0x31f6('0x3b')]);var _0x876db1={'where':_0x1f334f['where']};return db[_0x31f6('0x3c')]['count'](_0x876db1)[_0x31f6('0x21')](function(_0x39fa11){_0x322e55[_0x31f6('0x3d')]=_0x39fa11;if(_0x514ce4[_0x31f6('0x2c')]['includeAll']){_0x1f334f[_0x31f6('0x3e')]=[{'all':!![]}];}return db[_0x31f6('0x3c')][_0x31f6('0x3f')](_0x1f334f);})[_0x31f6('0x21')](function(_0x54ee65){_0x322e55[_0x31f6('0x40')]=_0x54ee65;return _0x322e55;})[_0x31f6('0x21')](respondWithFilteredResult(_0x2940f1,_0x1f334f))['catch'](handleError(_0x2940f1,null));};exports['show']=function(_0x1cb345,_0x1702b5){var _0x1cc31f={'raw':!![],'where':{'id':_0x1cb345[_0x31f6('0x41')]['id']}},_0xada0ea={};_0xada0ea[_0x31f6('0x2b')]=_['keys'](db[_0x31f6('0x3c')][_0x31f6('0x27')]);_0xada0ea[_0x31f6('0x2c')]=_[_0x31f6('0x2d')](_0x1cb345[_0x31f6('0x2c')]);_0xada0ea[_0x31f6('0x36')]=_[_0x31f6('0x2e')](_0xada0ea[_0x31f6('0x2b')],_0xada0ea[_0x31f6('0x2c')]);_0x1cc31f[_0x31f6('0x30')]=_[_0x31f6('0x2e')](_0xada0ea['model'],qs[_0x31f6('0x2f')](_0x1cb345[_0x31f6('0x2c')][_0x31f6('0x2f')]));_0x1cc31f[_0x31f6('0x30')]=_0x1cc31f['attributes'][_0x31f6('0x31')]?_0x1cc31f[_0x31f6('0x30')]:_0xada0ea[_0x31f6('0x2b')];if(_0x1cb345[_0x31f6('0x2c')][_0x31f6('0x42')]){_0x1cc31f[_0x31f6('0x3e')]=[{'all':!![]}];}_0x1cc31f=_[_0x31f6('0x3a')]({},_0x1cc31f,_0x1cb345[_0x31f6('0x3b')]);return db[_0x31f6('0x3c')][_0x31f6('0x43')](_0x1cc31f)[_0x31f6('0x21')](handleEntityNotFound(_0x1702b5,null))[_0x31f6('0x21')](respondWithResult(_0x1702b5,null))[_0x31f6('0x44')](handleError(_0x1702b5,null));};exports[_0x31f6('0x45')]=function(_0x1ec451,_0x2dfa80){return db[_0x31f6('0x3c')][_0x31f6('0x45')](_0x1ec451[_0x31f6('0x46')],{})[_0x31f6('0x21')](respondWithResult(_0x2dfa80,0xc9))[_0x31f6('0x44')](handleError(_0x2dfa80,null));};exports['update']=function(_0xefe6c9,_0x9f1875){if(_0xefe6c9[_0x31f6('0x46')]['id']){delete _0xefe6c9[_0x31f6('0x46')]['id'];}return db[_0x31f6('0x3c')][_0x31f6('0x43')]({'where':{'id':_0xefe6c9[_0x31f6('0x41')]['id']}})[_0x31f6('0x21')](handleEntityNotFound(_0x9f1875,null))[_0x31f6('0x21')](saveUpdates(_0xefe6c9[_0x31f6('0x46')],null))[_0x31f6('0x21')](respondWithResult(_0x9f1875,null))['catch'](handleError(_0x9f1875,null));};exports[_0x31f6('0x22')]=function(_0x513a09,_0xab4408){return db[_0x31f6('0x3c')]['find']({'where':{'id':_0x513a09[_0x31f6('0x41')]['id']}})[_0x31f6('0x21')](handleEntityNotFound(_0xab4408,null))[_0x31f6('0x21')](removeEntity(_0xab4408,null))[_0x31f6('0x44')](handleError(_0xab4408,null));};