5793d5859a0faa50f28e408e0d5b38c3068c1c90
[motion2.git] / server / api / chatMessage / chatMessage.model.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 _0x4b81=['chat_messages','fti_chat_messages','body','FULLTEXT','get','direction','toLowerCase','out','secret','isNil','UserId','ChatInteraction','findOne','then','createdAt','catch','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','bluebird','path','rimraf','../../config/environment','./chatMessage.attributes','ChatMessage'];(function(_0x47bcc9,_0x752673){var _0x55d655=function(_0x5c4ab5){while(--_0x5c4ab5){_0x47bcc9['push'](_0x47bcc9['shift']());}};_0x55d655(++_0x752673);}(_0x4b81,0x9e));var _0x14b8=function(_0x5eae6a,_0x2b886e){_0x5eae6a=_0x5eae6a-0x0;var _0x4fa9e8=_0x4b81[_0x5eae6a];return _0x4fa9e8;};'use strict';var _=require(_0x14b8('0x0'));var util=require('util');var logger=require(_0x14b8('0x1'))(_0x14b8('0x2'));var moment=require(_0x14b8('0x3'));var BPromise=require(_0x14b8('0x4'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x14b8('0x5'));var rimraf=require(_0x14b8('0x6'));var config=require(_0x14b8('0x7'));var attributes=require(_0x14b8('0x8'));module['exports']=function(_0x51f300,_0x1d2c35){return _0x51f300['define'](_0x14b8('0x9'),attributes,{'tableName':_0x14b8('0xa'),'paranoid':![],'indexes':[{'name':_0x14b8('0xb'),'fields':[_0x14b8('0xc')],'type':_0x14b8('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x41328a,_0x2bafd0,_0x18982b){var _0x38cb7d=_0x51f300['models'];var _0x2bb34a=_0x41328a[_0x14b8('0xe')]({'plain':!![]});if(_0x2bb34a[_0x14b8('0xf')][_0x14b8('0x10')]()==='in'||_0x2bb34a[_0x14b8('0xf')]['toLowerCase']()===_0x14b8('0x11')&&!_0x2bb34a[_0x14b8('0x12')]&&!_[_0x14b8('0x13')](_0x2bb34a[_0x14b8('0x14')])){_0x38cb7d[_0x14b8('0x15')][_0x14b8('0x16')]({'where':{'id':_0x2bb34a['ChatInteractionId']}})[_0x14b8('0x17')](function(_0x17de92){if(_0x17de92){_0x17de92['update']({'lastMsgAt':_0x2bb34a[_0x14b8('0x18')],'lastMsgDirection':_0x2bb34a[_0x14b8('0xf')][_0x14b8('0x10')]()});}})[_0x14b8('0x19')](function(_0x85b431){console['error'](_0x85b431);});}_0x18982b();}},'charset':_0x14b8('0x1a'),'collate':_0x14b8('0x1b')});};