1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports["default"] = void 0;
|
9 | exports.userImpressionInChat = userImpressionInChat;
|
10 |
|
11 | var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
12 |
|
13 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
14 |
|
15 | function userImpressionInChat(_x) {
|
16 | return _userImpressionInChat.apply(this, arguments);
|
17 | }
|
18 |
|
19 | function _userImpressionInChat() {
|
20 | _userImpressionInChat = (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee(_ref) {
|
21 | var telegramUserId, telegramChatId, botsModule, type, _ref$time, time, BotsTelegramImpressionModel, BotsTelegramChatModel, BotsTelegramUserModel, user, chat, data, impression;
|
22 |
|
23 | return _regenerator["default"].wrap(function _callee$(_context) {
|
24 | while (1) {
|
25 | switch (_context.prev = _context.next) {
|
26 | case 0:
|
27 | telegramUserId = _ref.telegramUserId, telegramChatId = _ref.telegramChatId, botsModule = _ref.botsModule, type = _ref.type, _ref$time = _ref.time, time = _ref$time === void 0 ? new Date().getTime() - 24 * 60 * 60 * 1000 : _ref$time;
|
28 | _context.next = 3;
|
29 | return botsModule.module('models.BotsTelegramImpressionModel');
|
30 |
|
31 | case 3:
|
32 | BotsTelegramImpressionModel = _context.sent;
|
33 | _context.next = 6;
|
34 | return botsModule.module('models.BotsTelegramChatModel');
|
35 |
|
36 | case 6:
|
37 | BotsTelegramChatModel = _context.sent;
|
38 | _context.next = 9;
|
39 | return botsModule.module('models.BotsTelegramUserModel');
|
40 |
|
41 | case 9:
|
42 | BotsTelegramUserModel = _context.sent;
|
43 | _context.next = 12;
|
44 | return BotsTelegramUserModel.findOne({
|
45 | id: telegramUserId
|
46 | }).select('_id').lean();
|
47 |
|
48 | case 12:
|
49 | user = _context.sent;
|
50 | _context.next = 15;
|
51 | return BotsTelegramChatModel.findOne({
|
52 | id: telegramChatId
|
53 | }).select('_id').lean();
|
54 |
|
55 | case 15:
|
56 | chat = _context.sent;
|
57 |
|
58 | if (!(!user || !chat)) {
|
59 | _context.next = 18;
|
60 | break;
|
61 | }
|
62 |
|
63 | return _context.abrupt("return", false);
|
64 |
|
65 | case 18:
|
66 | data = {
|
67 | userId: user._id,
|
68 | chatId: chat._id,
|
69 | updatedAt: {
|
70 | $gte: new Date(time)
|
71 | }
|
72 | };
|
73 | if (type) data.type = type;
|
74 | _context.next = 22;
|
75 | return BotsTelegramImpressionModel.findOne(data);
|
76 |
|
77 | case 22:
|
78 | impression = _context.sent;
|
79 | return _context.abrupt("return", !!impression);
|
80 |
|
81 | case 24:
|
82 | case "end":
|
83 | return _context.stop();
|
84 | }
|
85 | }
|
86 | }, _callee);
|
87 | }));
|
88 | return _userImpressionInChat.apply(this, arguments);
|
89 | }
|
90 |
|
91 | var _default = userImpressionInChat;
|
92 | exports["default"] = _default;
|
93 |
|
\ | No newline at end of file |