Built motion from commit 753c950e.|2.5.42
[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 _0x648e=['findAll','rows','catch','show','params','fields','find','create','body','eml-format','rimraf','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','index','SquareMessage','rawAttributes','type','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','filter','options','includeAll','include'];(function(_0x2112d4,_0x3c863c){var _0x434972=function(_0x477020){while(--_0x477020){_0x2112d4['push'](_0x2112d4['shift']());}};_0x434972(++_0x3c863c);}(_0x648e,0xa3));var _0xe648=function(_0x4d6a14,_0x2693c7){_0x4d6a14=_0x4d6a14-0x0;var _0x489dcb=_0x648e[_0x4d6a14];return _0x489dcb;};'use strict';var emlformat=require(_0xe648('0x0'));var rimraf=require(_0xe648('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xe648('0x2'));var rp=require('request-promise');var moment=require(_0xe648('0x3'));var BPromise=require(_0xe648('0x4'));var Mustache=require(_0xe648('0x5'));var util=require(_0xe648('0x6'));var path=require(_0xe648('0x7'));var sox=require(_0xe648('0x8'));var csv=require(_0xe648('0x9'));var ejs=require(_0xe648('0xa'));var fs=require('fs');var fs_extra=require(_0xe648('0xb'));var _=require(_0xe648('0xc'));var squel=require(_0xe648('0xd'));var crypto=require(_0xe648('0xe'));var jsforce=require(_0xe648('0xf'));var deskjs=require(_0xe648('0x10'));var toCsv=require(_0xe648('0x9'));var querystring=require('querystring');var Papa=require(_0xe648('0x11'));var Redis=require(_0xe648('0x12'));var authService=require('../../components/auth/service');var qs=require(_0xe648('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xe648('0x14'));var logger=require(_0xe648('0x15'))(_0xe648('0x16'));var utils=require(_0xe648('0x17'));var config=require(_0xe648('0x18'));var licenseUtil=require(_0xe648('0x19'));var db=require(_0xe648('0x1a'))['db'];function respondWithStatusCode(_0x1fe296,_0x2abc2c){_0x2abc2c=_0x2abc2c||0xcc;return function(_0xd25ab4){if(_0xd25ab4){return _0x1fe296[_0xe648('0x1b')](_0x2abc2c);}return _0x1fe296['status'](_0x2abc2c)[_0xe648('0x1c')]();};}function respondWithResult(_0x32f0e7,_0x2f6c75){_0x2f6c75=_0x2f6c75||0xc8;return function(_0x45162b){if(_0x45162b){return _0x32f0e7[_0xe648('0x1d')](_0x2f6c75)[_0xe648('0x1e')](_0x45162b);}};}function respondWithFilteredResult(_0x4464a1,_0x2cf799){return function(_0x355b6c){if(_0x355b6c){var _0x26d4f4=typeof _0x2cf799[_0xe648('0x1f')]===_0xe648('0x20')&&typeof _0x2cf799['limit']===_0xe648('0x20');var _0x2fbff5=_0x355b6c[_0xe648('0x21')];var _0x4c48cb=_0x26d4f4?0x0:_0x2cf799[_0xe648('0x1f')];var _0x1a066b=_0x26d4f4?_0x355b6c['count']:_0x2cf799[_0xe648('0x1f')]+_0x2cf799[_0xe648('0x22')];var _0x5a8bd5;if(_0x1a066b>=_0x2fbff5){_0x1a066b=_0x2fbff5;_0x5a8bd5=0xc8;}else{_0x5a8bd5=0xce;}_0x4464a1[_0xe648('0x1d')](_0x5a8bd5);return _0x4464a1[_0xe648('0x23')](_0xe648('0x24'),_0x4c48cb+'-'+_0x1a066b+'/'+_0x2fbff5)[_0xe648('0x1e')](_0x355b6c);}return null;};}function patchUpdates(_0x15abab){return function(_0x247b40){try{jsonpatch[_0xe648('0x25')](_0x247b40,_0x15abab,!![]);}catch(_0x4845f7){return BPromise[_0xe648('0x26')](_0x4845f7);}return _0x247b40[_0xe648('0x27')]();};}function saveUpdates(_0x1af9c4,_0x48ebf2){return function(_0x78b2db){if(_0x78b2db){return _0x78b2db[_0xe648('0x28')](_0x1af9c4)[_0xe648('0x29')](function(_0x2ea0bd){return _0x2ea0bd;});}return null;};}function removeEntity(_0x3fe09f,_0x583a3b){return function(_0x12469d){if(_0x12469d){return _0x12469d[_0xe648('0x2a')]()['then'](function(){_0x3fe09f['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x5e3e03,_0x2c68df){return function(_0x3cdb52){if(!_0x3cdb52){_0x5e3e03['sendStatus'](0x194);}return _0x3cdb52;};}function handleError(_0x4ff73d,_0x422441){_0x422441=_0x422441||0x1f4;return function(_0x1e265c){logger[_0xe648('0x2b')](_0x1e265c[_0xe648('0x2c')]);if(_0x1e265c[_0xe648('0x2d')]){delete _0x1e265c[_0xe648('0x2d')];}_0x4ff73d[_0xe648('0x1d')](_0x422441)['send'](_0x1e265c);};}exports[_0xe648('0x2e')]=function(_0x4835b9,_0x4715a5){var _0xe83a32={},_0x39c1c2={},_0x4e25b0={'count':0x0,'rows':[]};var _0x496a4c=_['map'](db[_0xe648('0x2f')][_0xe648('0x30')],function(_0xd2591c){return{'name':_0xd2591c['fieldName'],'type':_0xd2591c[_0xe648('0x31')]['key']};});_0x39c1c2[_0xe648('0x32')]=_['map'](_0x496a4c,_0xe648('0x2d'));_0x39c1c2[_0xe648('0x33')]=_[_0xe648('0x34')](_0x4835b9[_0xe648('0x33')]);_0x39c1c2[_0xe648('0x35')]=_['intersection'](_0x39c1c2[_0xe648('0x32')],_0x39c1c2[_0xe648('0x33')]);_0xe83a32['attributes']=_[_0xe648('0x36')](_0x39c1c2[_0xe648('0x32')],qs['fields'](_0x4835b9['query']['fields']));_0xe83a32[_0xe648('0x37')]=_0xe83a32[_0xe648('0x37')][_0xe648('0x38')]?_0xe83a32['attributes']:_0x39c1c2[_0xe648('0x32')];if(!_0x4835b9['query'][_0xe648('0x39')](_0xe648('0x3a'))){_0xe83a32[_0xe648('0x22')]=qs[_0xe648('0x22')](_0x4835b9[_0xe648('0x33')][_0xe648('0x22')]);_0xe83a32[_0xe648('0x1f')]=qs[_0xe648('0x1f')](_0x4835b9['query'][_0xe648('0x1f')]);}_0xe83a32[_0xe648('0x3b')]=qs[_0xe648('0x3c')](_0x4835b9['query'][_0xe648('0x3c')]);_0xe83a32[_0xe648('0x3d')]=qs[_0xe648('0x35')](_[_0xe648('0x3e')](_0x4835b9['query'],_0x39c1c2[_0xe648('0x35')]),_0x496a4c);if(_0x4835b9[_0xe648('0x33')]['filter']){_0xe83a32[_0xe648('0x3d')]=_[_0xe648('0x3f')](_0xe83a32['where'],{'$or':_['map'](_0x496a4c,function(_0x2165dd){if(_0x2165dd['type']!=='VIRTUAL'){var _0x1e79e1={};_0x1e79e1[_0x2165dd['name']]={'$like':'%'+_0x4835b9['query'][_0xe648('0x40')]+'%'};return _0x1e79e1;}})});}_0xe83a32=_[_0xe648('0x3f')]({},_0xe83a32,_0x4835b9[_0xe648('0x41')]);var _0x5a475d={'where':_0xe83a32[_0xe648('0x3d')]};return db[_0xe648('0x2f')][_0xe648('0x21')](_0x5a475d)[_0xe648('0x29')](function(_0x5860a4){_0x4e25b0[_0xe648('0x21')]=_0x5860a4;if(_0x4835b9[_0xe648('0x33')][_0xe648('0x42')]){_0xe83a32[_0xe648('0x43')]=[{'all':!![]}];}return db['SquareMessage'][_0xe648('0x44')](_0xe83a32);})[_0xe648('0x29')](function(_0x56be0a){_0x4e25b0[_0xe648('0x45')]=_0x56be0a;return _0x4e25b0;})[_0xe648('0x29')](respondWithFilteredResult(_0x4715a5,_0xe83a32))[_0xe648('0x46')](handleError(_0x4715a5,null));};exports[_0xe648('0x47')]=function(_0x5ac909,_0xd215b0){var _0x549e2c={'raw':!![],'where':{'id':_0x5ac909[_0xe648('0x48')]['id']}},_0x1bbe7b={};_0x1bbe7b[_0xe648('0x32')]=_[_0xe648('0x34')](db[_0xe648('0x2f')][_0xe648('0x30')]);_0x1bbe7b['query']=_[_0xe648('0x34')](_0x5ac909[_0xe648('0x33')]);_0x1bbe7b[_0xe648('0x35')]=_[_0xe648('0x36')](_0x1bbe7b['model'],_0x1bbe7b[_0xe648('0x33')]);_0x549e2c[_0xe648('0x37')]=_[_0xe648('0x36')](_0x1bbe7b['model'],qs['fields'](_0x5ac909['query'][_0xe648('0x49')]));_0x549e2c['attributes']=_0x549e2c[_0xe648('0x37')][_0xe648('0x38')]?_0x549e2c['attributes']:_0x1bbe7b['model'];if(_0x5ac909[_0xe648('0x33')]['includeAll']){_0x549e2c[_0xe648('0x43')]=[{'all':!![]}];}_0x549e2c=_[_0xe648('0x3f')]({},_0x549e2c,_0x5ac909[_0xe648('0x41')]);return db[_0xe648('0x2f')][_0xe648('0x4a')](_0x549e2c)[_0xe648('0x29')](handleEntityNotFound(_0xd215b0,null))[_0xe648('0x29')](respondWithResult(_0xd215b0,null))['catch'](handleError(_0xd215b0,null));};exports[_0xe648('0x4b')]=function(_0x1aa060,_0x461642){return db[_0xe648('0x2f')][_0xe648('0x4b')](_0x1aa060[_0xe648('0x4c')],{})[_0xe648('0x29')](respondWithResult(_0x461642,0xc9))[_0xe648('0x46')](handleError(_0x461642,null));};exports['update']=function(_0x37885d,_0x2750c7){if(_0x37885d[_0xe648('0x4c')]['id']){delete _0x37885d[_0xe648('0x4c')]['id'];}return db[_0xe648('0x2f')][_0xe648('0x4a')]({'where':{'id':_0x37885d[_0xe648('0x48')]['id']}})[_0xe648('0x29')](handleEntityNotFound(_0x2750c7,null))[_0xe648('0x29')](saveUpdates(_0x37885d[_0xe648('0x4c')],null))[_0xe648('0x29')](respondWithResult(_0x2750c7,null))['catch'](handleError(_0x2750c7,null));};exports['destroy']=function(_0x92bc1f,_0x5dc398){return db[_0xe648('0x2f')][_0xe648('0x4a')]({'where':{'id':_0x92bc1f[_0xe648('0x48')]['id']}})[_0xe648('0x29')](handleEntityNotFound(_0x5dc398,null))['then'](removeEntity(_0x5dc398,null))[_0xe648('0x46')](handleError(_0x5dc398,null));};