Built motion from commit (unavailable).|2.4.18
[motion2.git] / server / api / squareMessage / squareMessage.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 _0x1f84=['keys','create','body','find','html-pdf','eml-format','rimraf','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','count','offset','Content-Range','apply','update','then','destroy','error','stack','name','send','map','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','SquareMessage','includeAll','include','findAll','rows','catch','show','params'];(function(_0x5d6a1d,_0x4d8ef7){var _0x35d834=function(_0x2cd66e){while(--_0x2cd66e){_0x5d6a1d['push'](_0x5d6a1d['shift']());}};_0x35d834(++_0x4d8ef7);}(_0x1f84,0x98));var _0x41f8=function(_0x520cb2,_0xdab1aa){_0x520cb2=_0x520cb2-0x0;var _0x307bd9=_0x1f84[_0x520cb2];return _0x307bd9;};'use strict';var pdf=require(_0x41f8('0x0'));var emlformat=require(_0x41f8('0x1'));var rimraf=require(_0x41f8('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x41f8('0x3'));var moment=require(_0x41f8('0x4'));var BPromise=require(_0x41f8('0x5'));var Mustache=require(_0x41f8('0x6'));var util=require('util');var path=require(_0x41f8('0x7'));var sox=require(_0x41f8('0x8'));var csv=require(_0x41f8('0x9'));var ejs=require(_0x41f8('0xa'));var fs=require('fs');var _=require(_0x41f8('0xb'));var squel=require(_0x41f8('0xc'));var crypto=require(_0x41f8('0xd'));var jsforce=require(_0x41f8('0xe'));var deskjs=require(_0x41f8('0xf'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x41f8('0x10'));var qs=require(_0x41f8('0x11'));var as=require(_0x41f8('0x12'));var hardwareService=require(_0x41f8('0x13'));var logger=require(_0x41f8('0x14'))(_0x41f8('0x15'));var utils=require(_0x41f8('0x16'));var config=require(_0x41f8('0x17'));var db=require(_0x41f8('0x18'))['db'];function respondWithStatusCode(_0x3ab453,_0x5e2359){_0x5e2359=_0x5e2359||0xcc;return function(_0x167d06){if(_0x167d06){return _0x3ab453[_0x41f8('0x19')](_0x5e2359);}return _0x3ab453[_0x41f8('0x1a')](_0x5e2359)['end']();};}function respondWithResult(_0x1ffcbc,_0x3f3620){_0x3f3620=_0x3f3620||0xc8;return function(_0xf23d5c){if(_0xf23d5c){return _0x1ffcbc[_0x41f8('0x1a')](_0x3f3620)[_0x41f8('0x1b')](_0xf23d5c);}};}function respondWithFilteredResult(_0x4e6ff3,_0x14ed56){return function(_0x2784a9){if(_0x2784a9){var _0x45b5b3=_0x2784a9[_0x41f8('0x1c')],_0x15ae81=_0x14ed56[_0x41f8('0x1d')],_0x49ba00=_0x14ed56[_0x41f8('0x1d')]+_0x14ed56['limit'],_0x5e0fc4;if(_0x49ba00>=_0x45b5b3){_0x49ba00=_0x45b5b3;_0x5e0fc4=0xc8;}else{_0x5e0fc4=0xce;}_0x4e6ff3['status'](_0x5e0fc4);return _0x4e6ff3['set'](_0x41f8('0x1e'),_0x15ae81+'-'+_0x49ba00+'/'+_0x45b5b3)[_0x41f8('0x1b')](_0x2784a9);}return null;};}function patchUpdates(_0xbc9ff1){return function(_0x2f52d6){try{jsonpatch[_0x41f8('0x1f')](_0x2f52d6,_0xbc9ff1,!![]);}catch(_0xae1657){return BPromise['reject'](_0xae1657);}return _0x2f52d6['save']();};}function saveUpdates(_0x4cd339,_0x26a314){return function(_0x4fcdb6){if(_0x4fcdb6){return _0x4fcdb6[_0x41f8('0x20')](_0x4cd339)[_0x41f8('0x21')](function(_0x103fe1){return _0x103fe1;});}return null;};}function removeEntity(_0x897ba5,_0x171d36){return function(_0x217b75){if(_0x217b75){return _0x217b75[_0x41f8('0x22')]()['then'](function(){_0x897ba5[_0x41f8('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0xe8bc49,_0x1622f7){return function(_0x4a6169){if(!_0x4a6169){_0xe8bc49[_0x41f8('0x19')](0x194);}return _0x4a6169;};}function handleError(_0x400869,_0x583599){_0x583599=_0x583599||0x1f4;return function(_0x4e1aa1){logger[_0x41f8('0x23')](_0x4e1aa1[_0x41f8('0x24')]);if(_0x4e1aa1[_0x41f8('0x25')]){delete _0x4e1aa1[_0x41f8('0x25')];}_0x400869['status'](_0x583599)[_0x41f8('0x26')](_0x4e1aa1);};}exports['index']=function(_0xe62d87,_0x3e06bd){var _0x4a4224={},_0x17f629={},_0x3f7cb3={'count':0x0,'rows':[]};var _0xa8acfc=_[_0x41f8('0x27')](db['SquareMessage'][_0x41f8('0x28')],function(_0x56b147){return{'name':_0x56b147[_0x41f8('0x29')],'type':_0x56b147[_0x41f8('0x2a')][_0x41f8('0x2b')]};});_0x17f629[_0x41f8('0x2c')]=_[_0x41f8('0x27')](_0xa8acfc,_0x41f8('0x25'));_0x17f629[_0x41f8('0x2d')]=_['keys'](_0xe62d87[_0x41f8('0x2d')]);_0x17f629[_0x41f8('0x2e')]=_[_0x41f8('0x2f')](_0x17f629['model'],_0x17f629[_0x41f8('0x2d')]);_0x4a4224[_0x41f8('0x30')]=_['intersection'](_0x17f629['model'],qs[_0x41f8('0x31')](_0xe62d87[_0x41f8('0x2d')][_0x41f8('0x31')]));_0x4a4224['attributes']=_0x4a4224[_0x41f8('0x30')][_0x41f8('0x32')]?_0x4a4224[_0x41f8('0x30')]:_0x17f629[_0x41f8('0x2c')];if(!_0xe62d87[_0x41f8('0x2d')][_0x41f8('0x33')](_0x41f8('0x34'))){_0x4a4224[_0x41f8('0x35')]=qs[_0x41f8('0x35')](_0xe62d87['query'][_0x41f8('0x35')]);_0x4a4224[_0x41f8('0x1d')]=qs['offset'](_0xe62d87[_0x41f8('0x2d')][_0x41f8('0x1d')]);}_0x4a4224[_0x41f8('0x36')]=qs['sort'](_0xe62d87[_0x41f8('0x2d')][_0x41f8('0x37')]);_0x4a4224[_0x41f8('0x38')]=qs[_0x41f8('0x2e')](_[_0x41f8('0x39')](_0xe62d87[_0x41f8('0x2d')],_0x17f629[_0x41f8('0x2e')]));if(_0xe62d87[_0x41f8('0x2d')][_0x41f8('0x3a')]){_0x4a4224[_0x41f8('0x38')]=_[_0x41f8('0x3b')](_0x4a4224['where'],{'$or':_[_0x41f8('0x27')](_0xa8acfc,function(_0x37c248){if(_0x37c248['type']!==_0x41f8('0x3c')){var _0xa1152e={};_0xa1152e[_0x37c248['name']]={'$like':'%'+_0xe62d87['query'][_0x41f8('0x3a')]+'%'};return _0xa1152e;}})});}_0x4a4224=_['merge']({},_0x4a4224,_0xe62d87[_0x41f8('0x3d')]);var _0x353ed4={'where':_0x4a4224['where']};return db[_0x41f8('0x3e')][_0x41f8('0x1c')](_0x353ed4)[_0x41f8('0x21')](function(_0x122254){_0x3f7cb3['count']=_0x122254;if(_0xe62d87[_0x41f8('0x2d')][_0x41f8('0x3f')]){_0x4a4224[_0x41f8('0x40')]=[{'all':!![]}];}return db[_0x41f8('0x3e')][_0x41f8('0x41')](_0x4a4224);})['then'](function(_0x38736e){_0x3f7cb3[_0x41f8('0x42')]=_0x38736e;return _0x3f7cb3;})[_0x41f8('0x21')](respondWithFilteredResult(_0x3e06bd,_0x4a4224))[_0x41f8('0x43')](handleError(_0x3e06bd,null));};exports[_0x41f8('0x44')]=function(_0x5a5c34,_0x36db35){var _0x5a94da={'raw':!![],'where':{'id':_0x5a5c34[_0x41f8('0x45')]['id']}},_0x1e0009={};_0x1e0009[_0x41f8('0x2c')]=_[_0x41f8('0x46')](db['SquareMessage']['rawAttributes']);_0x1e0009[_0x41f8('0x2d')]=_['keys'](_0x5a5c34[_0x41f8('0x2d')]);_0x1e0009['filters']=_[_0x41f8('0x2f')](_0x1e0009[_0x41f8('0x2c')],_0x1e0009[_0x41f8('0x2d')]);_0x5a94da[_0x41f8('0x30')]=_[_0x41f8('0x2f')](_0x1e0009[_0x41f8('0x2c')],qs[_0x41f8('0x31')](_0x5a5c34[_0x41f8('0x2d')]['fields']));_0x5a94da[_0x41f8('0x30')]=_0x5a94da[_0x41f8('0x30')][_0x41f8('0x32')]?_0x5a94da['attributes']:_0x1e0009[_0x41f8('0x2c')];if(_0x5a5c34[_0x41f8('0x2d')][_0x41f8('0x3f')]){_0x5a94da[_0x41f8('0x40')]=[{'all':!![]}];}_0x5a94da=_[_0x41f8('0x3b')]({},_0x5a94da,_0x5a5c34[_0x41f8('0x3d')]);return db['SquareMessage']['find'](_0x5a94da)[_0x41f8('0x21')](handleEntityNotFound(_0x36db35,null))['then'](respondWithResult(_0x36db35,null))['catch'](handleError(_0x36db35,null));};exports[_0x41f8('0x47')]=function(_0x5bc7f8,_0x43a327){return db[_0x41f8('0x3e')][_0x41f8('0x47')](_0x5bc7f8['body'],{})[_0x41f8('0x21')](respondWithResult(_0x43a327,0xc9))['catch'](handleError(_0x43a327,null));};exports[_0x41f8('0x20')]=function(_0x22627,_0x3fbf63){if(_0x22627[_0x41f8('0x48')]['id']){delete _0x22627['body']['id'];}return db[_0x41f8('0x3e')][_0x41f8('0x49')]({'where':{'id':_0x22627[_0x41f8('0x45')]['id']}})['then'](handleEntityNotFound(_0x3fbf63,null))[_0x41f8('0x21')](saveUpdates(_0x22627[_0x41f8('0x48')],null))[_0x41f8('0x21')](respondWithResult(_0x3fbf63,null))[_0x41f8('0x43')](handleError(_0x3fbf63,null));};exports['destroy']=function(_0x409d3b,_0x1dfdcf){return db[_0x41f8('0x3e')][_0x41f8('0x49')]({'where':{'id':_0x409d3b[_0x41f8('0x45')]['id']}})['then'](handleEntityNotFound(_0x1dfdcf,null))[_0x41f8('0x21')](removeEntity(_0x1dfdcf,null))[_0x41f8('0x43')](handleError(_0x1dfdcf,null));};