Built motion from commit (unavailable).|2.5.26
[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 _0x2fd6=['fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','../../config/environment','../../config/license/util','sendStatus','end','status','json','count','offset','limit','set','apply','reject','update','then','destroy','error','stack','name','send','index','map','SquareMessage','rawAttributes','fieldName','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','filter','where','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','rimraf','zip-dir'];(function(_0x4a0c33,_0x5686bb){var _0x6488f9=function(_0x3bbd97){while(--_0x3bbd97){_0x4a0c33['push'](_0x4a0c33['shift']());}};_0x6488f9(++_0x5686bb);}(_0x2fd6,0x166));var _0x62fd=function(_0x392d62,_0x297b0a){_0x392d62=_0x392d62-0x0;var _0x2b69f6=_0x2fd6[_0x392d62];return _0x2b69f6;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x62fd('0x0'));var zipdir=require(_0x62fd('0x1'));var jsonpatch=require(_0x62fd('0x2'));var rp=require(_0x62fd('0x3'));var moment=require(_0x62fd('0x4'));var BPromise=require(_0x62fd('0x5'));var Mustache=require(_0x62fd('0x6'));var util=require(_0x62fd('0x7'));var path=require('path');var sox=require(_0x62fd('0x8'));var csv=require(_0x62fd('0x9'));var ejs=require(_0x62fd('0xa'));var fs=require('fs');var fs_extra=require(_0x62fd('0xb'));var _=require(_0x62fd('0xc'));var squel=require(_0x62fd('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x62fd('0xe'));var toCsv=require(_0x62fd('0x9'));var querystring=require('querystring');var Papa=require(_0x62fd('0xf'));var Redis=require(_0x62fd('0x10'));var authService=require(_0x62fd('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x62fd('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x62fd('0x13'))('api');var utils=require('../../config/utils');var config=require(_0x62fd('0x14'));var licenseUtil=require(_0x62fd('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x54f02e,_0x182825){_0x182825=_0x182825||0xcc;return function(_0x1bdf6f){if(_0x1bdf6f){return _0x54f02e[_0x62fd('0x16')](_0x182825);}return _0x54f02e['status'](_0x182825)[_0x62fd('0x17')]();};}function respondWithResult(_0x3649f5,_0x30e7c0){_0x30e7c0=_0x30e7c0||0xc8;return function(_0x4f17f4){if(_0x4f17f4){return _0x3649f5[_0x62fd('0x18')](_0x30e7c0)[_0x62fd('0x19')](_0x4f17f4);}};}function respondWithFilteredResult(_0x5384bb,_0x19f179){return function(_0x3d4c56){if(_0x3d4c56){var _0xb8e85a=_0x3d4c56[_0x62fd('0x1a')],_0xa70685=_0x19f179['offset'],_0x2d09a7=_0x19f179[_0x62fd('0x1b')]+_0x19f179[_0x62fd('0x1c')],_0x46a085;if(_0x2d09a7>=_0xb8e85a){_0x2d09a7=_0xb8e85a;_0x46a085=0xc8;}else{_0x46a085=0xce;}_0x5384bb['status'](_0x46a085);return _0x5384bb[_0x62fd('0x1d')]('Content-Range',_0xa70685+'-'+_0x2d09a7+'/'+_0xb8e85a)['json'](_0x3d4c56);}return null;};}function patchUpdates(_0x21d329){return function(_0x271483){try{jsonpatch[_0x62fd('0x1e')](_0x271483,_0x21d329,!![]);}catch(_0x453579){return BPromise[_0x62fd('0x1f')](_0x453579);}return _0x271483['save']();};}function saveUpdates(_0x4659ae,_0x2896f7){return function(_0x21bc21){if(_0x21bc21){return _0x21bc21[_0x62fd('0x20')](_0x4659ae)[_0x62fd('0x21')](function(_0x4451a5){return _0x4451a5;});}return null;};}function removeEntity(_0xadccd9,_0x4d1c30){return function(_0x26a36b){if(_0x26a36b){return _0x26a36b[_0x62fd('0x22')]()[_0x62fd('0x21')](function(){_0xadccd9[_0x62fd('0x18')](0xcc)[_0x62fd('0x17')]();});}};}function handleEntityNotFound(_0x2dcf26,_0xc06b59){return function(_0x515a70){if(!_0x515a70){_0x2dcf26[_0x62fd('0x16')](0x194);}return _0x515a70;};}function handleError(_0x42f30d,_0x1382e8){_0x1382e8=_0x1382e8||0x1f4;return function(_0x8a9142){logger[_0x62fd('0x23')](_0x8a9142[_0x62fd('0x24')]);if(_0x8a9142[_0x62fd('0x25')]){delete _0x8a9142['name'];}_0x42f30d[_0x62fd('0x18')](_0x1382e8)[_0x62fd('0x26')](_0x8a9142);};}exports[_0x62fd('0x27')]=function(_0x4db008,_0x23f563){var _0x12a6d2={},_0x15f9d8={},_0x35f8ee={'count':0x0,'rows':[]};var _0x5701fd=_[_0x62fd('0x28')](db[_0x62fd('0x29')][_0x62fd('0x2a')],function(_0xaa1fe2){return{'name':_0xaa1fe2[_0x62fd('0x2b')],'type':_0xaa1fe2['type'][_0x62fd('0x2c')]};});_0x15f9d8[_0x62fd('0x2d')]=_[_0x62fd('0x28')](_0x5701fd,_0x62fd('0x25'));_0x15f9d8['query']=_[_0x62fd('0x2e')](_0x4db008[_0x62fd('0x2f')]);_0x15f9d8[_0x62fd('0x30')]=_[_0x62fd('0x31')](_0x15f9d8[_0x62fd('0x2d')],_0x15f9d8[_0x62fd('0x2f')]);_0x12a6d2[_0x62fd('0x32')]=_[_0x62fd('0x31')](_0x15f9d8['model'],qs['fields'](_0x4db008['query'][_0x62fd('0x33')]));_0x12a6d2['attributes']=_0x12a6d2[_0x62fd('0x32')][_0x62fd('0x34')]?_0x12a6d2['attributes']:_0x15f9d8[_0x62fd('0x2d')];if(!_0x4db008[_0x62fd('0x2f')][_0x62fd('0x35')]('nolimit')){_0x12a6d2[_0x62fd('0x1c')]=qs[_0x62fd('0x1c')](_0x4db008[_0x62fd('0x2f')]['limit']);_0x12a6d2[_0x62fd('0x1b')]=qs[_0x62fd('0x1b')](_0x4db008[_0x62fd('0x2f')]['offset']);}_0x12a6d2[_0x62fd('0x36')]=qs[_0x62fd('0x37')](_0x4db008[_0x62fd('0x2f')]['sort']);_0x12a6d2['where']=qs[_0x62fd('0x30')](_['pick'](_0x4db008[_0x62fd('0x2f')],_0x15f9d8[_0x62fd('0x30')]),_0x5701fd);if(_0x4db008[_0x62fd('0x2f')][_0x62fd('0x38')]){_0x12a6d2[_0x62fd('0x39')]=_[_0x62fd('0x3a')](_0x12a6d2[_0x62fd('0x39')],{'$or':_[_0x62fd('0x28')](_0x5701fd,function(_0x1a7d47){if(_0x1a7d47[_0x62fd('0x3b')]!==_0x62fd('0x3c')){var _0x3597b1={};_0x3597b1[_0x1a7d47[_0x62fd('0x25')]]={'$like':'%'+_0x4db008['query'][_0x62fd('0x38')]+'%'};return _0x3597b1;}})});}_0x12a6d2=_[_0x62fd('0x3a')]({},_0x12a6d2,_0x4db008[_0x62fd('0x3d')]);var _0xc6559e={'where':_0x12a6d2[_0x62fd('0x39')]};return db['SquareMessage'][_0x62fd('0x1a')](_0xc6559e)[_0x62fd('0x21')](function(_0x52d358){_0x35f8ee['count']=_0x52d358;if(_0x4db008[_0x62fd('0x2f')][_0x62fd('0x3e')]){_0x12a6d2[_0x62fd('0x3f')]=[{'all':!![]}];}return db[_0x62fd('0x29')][_0x62fd('0x40')](_0x12a6d2);})[_0x62fd('0x21')](function(_0x452586){_0x35f8ee[_0x62fd('0x41')]=_0x452586;return _0x35f8ee;})[_0x62fd('0x21')](respondWithFilteredResult(_0x23f563,_0x12a6d2))[_0x62fd('0x42')](handleError(_0x23f563,null));};exports[_0x62fd('0x43')]=function(_0x591175,_0x1ee317){var _0x21bd69={'raw':!![],'where':{'id':_0x591175[_0x62fd('0x44')]['id']}},_0x3e0023={};_0x3e0023[_0x62fd('0x2d')]=_[_0x62fd('0x2e')](db[_0x62fd('0x29')][_0x62fd('0x2a')]);_0x3e0023[_0x62fd('0x2f')]=_[_0x62fd('0x2e')](_0x591175[_0x62fd('0x2f')]);_0x3e0023[_0x62fd('0x30')]=_[_0x62fd('0x31')](_0x3e0023['model'],_0x3e0023[_0x62fd('0x2f')]);_0x21bd69[_0x62fd('0x32')]=_[_0x62fd('0x31')](_0x3e0023['model'],qs[_0x62fd('0x33')](_0x591175[_0x62fd('0x2f')][_0x62fd('0x33')]));_0x21bd69[_0x62fd('0x32')]=_0x21bd69[_0x62fd('0x32')]['length']?_0x21bd69[_0x62fd('0x32')]:_0x3e0023['model'];if(_0x591175[_0x62fd('0x2f')][_0x62fd('0x3e')]){_0x21bd69[_0x62fd('0x3f')]=[{'all':!![]}];}_0x21bd69=_[_0x62fd('0x3a')]({},_0x21bd69,_0x591175[_0x62fd('0x3d')]);return db[_0x62fd('0x29')][_0x62fd('0x45')](_0x21bd69)[_0x62fd('0x21')](handleEntityNotFound(_0x1ee317,null))[_0x62fd('0x21')](respondWithResult(_0x1ee317,null))[_0x62fd('0x42')](handleError(_0x1ee317,null));};exports[_0x62fd('0x46')]=function(_0x5192c5,_0x1d2c22){return db[_0x62fd('0x29')][_0x62fd('0x46')](_0x5192c5[_0x62fd('0x47')],{})[_0x62fd('0x21')](respondWithResult(_0x1d2c22,0xc9))[_0x62fd('0x42')](handleError(_0x1d2c22,null));};exports[_0x62fd('0x20')]=function(_0x5dd7ce,_0x210c79){if(_0x5dd7ce[_0x62fd('0x47')]['id']){delete _0x5dd7ce[_0x62fd('0x47')]['id'];}return db['SquareMessage'][_0x62fd('0x45')]({'where':{'id':_0x5dd7ce[_0x62fd('0x44')]['id']}})[_0x62fd('0x21')](handleEntityNotFound(_0x210c79,null))[_0x62fd('0x21')](saveUpdates(_0x5dd7ce['body'],null))[_0x62fd('0x21')](respondWithResult(_0x210c79,null))[_0x62fd('0x42')](handleError(_0x210c79,null));};exports[_0x62fd('0x22')]=function(_0x560d60,_0x2fbb95){return db[_0x62fd('0x29')][_0x62fd('0x45')]({'where':{'id':_0x560d60[_0x62fd('0x44')]['id']}})['then'](handleEntityNotFound(_0x2fbb95,null))[_0x62fd('0x21')](removeEntity(_0x2fbb95,null))[_0x62fd('0x42')](handleError(_0x2fbb95,null));};