c0273406323463d555ddc8eadf8461e9b60cb3ec
[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 _0x40fb=['order','sort','where','pick','filter','merge','map','VIRTUAL','options','includeAll','findAll','rows','catch','show','rawAttributes','include','find','create','body','update','params','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','end','status','count','offset','limit','Content-Range','json','apply','reject','save','then','destroy','sendStatus','error','stack','name','index','SquareMessage','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit'];(function(_0x426362,_0x318cba){var _0x561eb6=function(_0x396f4e){while(--_0x396f4e){_0x426362['push'](_0x426362['shift']());}};_0x561eb6(++_0x318cba);}(_0x40fb,0xb1));var _0xb40f=function(_0x4c912e,_0x27299d){_0x4c912e=_0x4c912e-0x0;var _0x2fa424=_0x40fb[_0x4c912e];return _0x2fa424;};'use strict';var pdf=require(_0xb40f('0x0'));var emlformat=require(_0xb40f('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xb40f('0x2'));var jsonpatch=require(_0xb40f('0x3'));var rp=require(_0xb40f('0x4'));var moment=require(_0xb40f('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xb40f('0x6'));var util=require('util');var path=require(_0xb40f('0x7'));var sox=require(_0xb40f('0x8'));var csv=require(_0xb40f('0x9'));var ejs=require(_0xb40f('0xa'));var fs=require('fs');var _=require(_0xb40f('0xb'));var squel=require(_0xb40f('0xc'));var crypto=require(_0xb40f('0xd'));var jsforce=require(_0xb40f('0xe'));var deskjs=require(_0xb40f('0xf'));var toCsv=require('to-csv');var querystring=require(_0xb40f('0x10'));var Papa=require('papaparse');var Redis=require(_0xb40f('0x11'));var authService=require(_0xb40f('0x12'));var qs=require(_0xb40f('0x13'));var as=require(_0xb40f('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb40f('0x15'))(_0xb40f('0x16'));var utils=require(_0xb40f('0x17'));var config=require(_0xb40f('0x18'));var db=require(_0xb40f('0x19'))['db'];function respondWithStatusCode(_0x48f6ae,_0x939c6d){_0x939c6d=_0x939c6d||0xcc;return function(_0x56d650){if(_0x56d650){return _0x48f6ae['sendStatus'](_0x939c6d);}return _0x48f6ae['status'](_0x939c6d)[_0xb40f('0x1a')]();};}function respondWithResult(_0x8d722f,_0x3a89bd){_0x3a89bd=_0x3a89bd||0xc8;return function(_0x149b84){if(_0x149b84){return _0x8d722f[_0xb40f('0x1b')](_0x3a89bd)['json'](_0x149b84);}};}function respondWithFilteredResult(_0x33262a,_0x2bce56){return function(_0x2221b4){if(_0x2221b4){var _0x36a8b4=_0x2221b4[_0xb40f('0x1c')],_0xd98d12=_0x2bce56['offset'],_0x3845e0=_0x2bce56[_0xb40f('0x1d')]+_0x2bce56[_0xb40f('0x1e')],_0x102e72;if(_0x3845e0>=_0x36a8b4){_0x3845e0=_0x36a8b4;_0x102e72=0xc8;}else{_0x102e72=0xce;}_0x33262a[_0xb40f('0x1b')](_0x102e72);return _0x33262a['set'](_0xb40f('0x1f'),_0xd98d12+'-'+_0x3845e0+'/'+_0x36a8b4)[_0xb40f('0x20')](_0x2221b4);}return null;};}function patchUpdates(_0x434883){return function(_0x565f38){try{jsonpatch[_0xb40f('0x21')](_0x565f38,_0x434883,!![]);}catch(_0x424576){return BPromise[_0xb40f('0x22')](_0x424576);}return _0x565f38[_0xb40f('0x23')]();};}function saveUpdates(_0x3a74e2,_0x8a2572){return function(_0x3a062e){if(_0x3a062e){return _0x3a062e['update'](_0x3a74e2)[_0xb40f('0x24')](function(_0x2eac36){return _0x2eac36;});}return null;};}function removeEntity(_0x42bcb1,_0x540441){return function(_0x266573){if(_0x266573){return _0x266573[_0xb40f('0x25')]()['then'](function(){_0x42bcb1[_0xb40f('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3dac5b,_0x8dba75){return function(_0x33eb19){if(!_0x33eb19){_0x3dac5b[_0xb40f('0x26')](0x194);}return _0x33eb19;};}function handleError(_0x3d791f,_0x8df9ef){_0x8df9ef=_0x8df9ef||0x1f4;return function(_0x29bc1b){logger[_0xb40f('0x27')](_0x29bc1b[_0xb40f('0x28')]);if(_0x29bc1b[_0xb40f('0x29')]){delete _0x29bc1b[_0xb40f('0x29')];}_0x3d791f[_0xb40f('0x1b')](_0x8df9ef)['send'](_0x29bc1b);};}exports[_0xb40f('0x2a')]=function(_0x1c087b,_0xc83fc8){var _0x3bce2b={},_0x2ea78f={},_0x3c67b5={'count':0x0,'rows':[]};var _0x48adfb=_['map'](db[_0xb40f('0x2b')]['rawAttributes'],function(_0x5543ca){return{'name':_0x5543ca[_0xb40f('0x2c')],'type':_0x5543ca[_0xb40f('0x2d')][_0xb40f('0x2e')]};});_0x2ea78f[_0xb40f('0x2f')]=_['map'](_0x48adfb,_0xb40f('0x29'));_0x2ea78f[_0xb40f('0x30')]=_[_0xb40f('0x31')](_0x1c087b['query']);_0x2ea78f[_0xb40f('0x32')]=_[_0xb40f('0x33')](_0x2ea78f['model'],_0x2ea78f[_0xb40f('0x30')]);_0x3bce2b[_0xb40f('0x34')]=_['intersection'](_0x2ea78f[_0xb40f('0x2f')],qs[_0xb40f('0x35')](_0x1c087b[_0xb40f('0x30')]['fields']));_0x3bce2b[_0xb40f('0x34')]=_0x3bce2b[_0xb40f('0x34')][_0xb40f('0x36')]?_0x3bce2b[_0xb40f('0x34')]:_0x2ea78f[_0xb40f('0x2f')];if(!_0x1c087b[_0xb40f('0x30')][_0xb40f('0x37')](_0xb40f('0x38'))){_0x3bce2b['limit']=qs['limit'](_0x1c087b[_0xb40f('0x30')][_0xb40f('0x1e')]);_0x3bce2b[_0xb40f('0x1d')]=qs['offset'](_0x1c087b[_0xb40f('0x30')][_0xb40f('0x1d')]);}_0x3bce2b[_0xb40f('0x39')]=qs['sort'](_0x1c087b[_0xb40f('0x30')][_0xb40f('0x3a')]);_0x3bce2b[_0xb40f('0x3b')]=qs[_0xb40f('0x32')](_[_0xb40f('0x3c')](_0x1c087b[_0xb40f('0x30')],_0x2ea78f[_0xb40f('0x32')]));if(_0x1c087b[_0xb40f('0x30')][_0xb40f('0x3d')]){_0x3bce2b[_0xb40f('0x3b')]=_[_0xb40f('0x3e')](_0x3bce2b[_0xb40f('0x3b')],{'$or':_[_0xb40f('0x3f')](_0x48adfb,function(_0x2ecc14){if(_0x2ecc14[_0xb40f('0x2d')]!==_0xb40f('0x40')){var _0x3c0d51={};_0x3c0d51[_0x2ecc14['name']]={'$like':'%'+_0x1c087b[_0xb40f('0x30')][_0xb40f('0x3d')]+'%'};return _0x3c0d51;}})});}_0x3bce2b=_[_0xb40f('0x3e')]({},_0x3bce2b,_0x1c087b[_0xb40f('0x41')]);var _0x257b67={'where':_0x3bce2b[_0xb40f('0x3b')]};return db['SquareMessage'][_0xb40f('0x1c')](_0x257b67)['then'](function(_0x3ca4f7){_0x3c67b5[_0xb40f('0x1c')]=_0x3ca4f7;if(_0x1c087b[_0xb40f('0x30')][_0xb40f('0x42')]){_0x3bce2b['include']=[{'all':!![]}];}return db[_0xb40f('0x2b')][_0xb40f('0x43')](_0x3bce2b);})['then'](function(_0x28f34a){_0x3c67b5[_0xb40f('0x44')]=_0x28f34a;return _0x3c67b5;})[_0xb40f('0x24')](respondWithFilteredResult(_0xc83fc8,_0x3bce2b))[_0xb40f('0x45')](handleError(_0xc83fc8,null));};exports[_0xb40f('0x46')]=function(_0x1d72ee,_0xfac8cf){var _0xc24e0b={'raw':!![],'where':{'id':_0x1d72ee['params']['id']}},_0x355a9a={};_0x355a9a[_0xb40f('0x2f')]=_[_0xb40f('0x31')](db[_0xb40f('0x2b')][_0xb40f('0x47')]);_0x355a9a[_0xb40f('0x30')]=_['keys'](_0x1d72ee['query']);_0x355a9a[_0xb40f('0x32')]=_[_0xb40f('0x33')](_0x355a9a[_0xb40f('0x2f')],_0x355a9a[_0xb40f('0x30')]);_0xc24e0b[_0xb40f('0x34')]=_[_0xb40f('0x33')](_0x355a9a[_0xb40f('0x2f')],qs[_0xb40f('0x35')](_0x1d72ee[_0xb40f('0x30')][_0xb40f('0x35')]));_0xc24e0b['attributes']=_0xc24e0b[_0xb40f('0x34')][_0xb40f('0x36')]?_0xc24e0b['attributes']:_0x355a9a[_0xb40f('0x2f')];if(_0x1d72ee[_0xb40f('0x30')]['includeAll']){_0xc24e0b[_0xb40f('0x48')]=[{'all':!![]}];}_0xc24e0b=_['merge']({},_0xc24e0b,_0x1d72ee['options']);return db[_0xb40f('0x2b')][_0xb40f('0x49')](_0xc24e0b)[_0xb40f('0x24')](handleEntityNotFound(_0xfac8cf,null))[_0xb40f('0x24')](respondWithResult(_0xfac8cf,null))[_0xb40f('0x45')](handleError(_0xfac8cf,null));};exports[_0xb40f('0x4a')]=function(_0x36180b,_0x385bda){return db[_0xb40f('0x2b')]['create'](_0x36180b[_0xb40f('0x4b')],{})['then'](respondWithResult(_0x385bda,0xc9))[_0xb40f('0x45')](handleError(_0x385bda,null));};exports[_0xb40f('0x4c')]=function(_0x479f50,_0x596eba){if(_0x479f50[_0xb40f('0x4b')]['id']){delete _0x479f50[_0xb40f('0x4b')]['id'];}return db[_0xb40f('0x2b')][_0xb40f('0x49')]({'where':{'id':_0x479f50[_0xb40f('0x4d')]['id']}})['then'](handleEntityNotFound(_0x596eba,null))[_0xb40f('0x24')](saveUpdates(_0x479f50[_0xb40f('0x4b')],null))['then'](respondWithResult(_0x596eba,null))[_0xb40f('0x45')](handleError(_0x596eba,null));};exports[_0xb40f('0x25')]=function(_0xbafdf5,_0x14a232){return db[_0xb40f('0x2b')][_0xb40f('0x49')]({'where':{'id':_0xbafdf5['params']['id']}})[_0xb40f('0x24')](handleEntityNotFound(_0x14a232,null))['then'](removeEntity(_0x14a232,null))[_0xb40f('0x45')](handleError(_0x14a232,null));};