Skip to content

Commit

Permalink
add bookmark users to cancel event
Browse files Browse the repository at this point in the history
  • Loading branch information
wholespace214 committed Nov 4, 2021
1 parent d79986b commit c1cfc66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
4 changes: 3 additions & 1 deletion services/bet-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { onBetPlaced } = require('./quote-storage-service');
const { BetContract } = require('@wallfair.io/smart_contract_mock');
const { toScaledBigInt, fromScaledBigInt } = require('../util/number-helper');
const { calculateAllBetsStatus, filterPublishedBets } = require('../services/event-service');
const _ = require('lodash');

exports.listBets = async (q) => {
return Bet.find(q).populate('event').map(calculateAllBetsStatus).map(filterPublishedBets);
Expand Down Expand Up @@ -366,7 +367,8 @@ exports.cancel = async (bet, cancellationReason) => {

if (dbBet) {
const event = await eventService.getEvent(dbBet.event);

// add also the bookmarked user to event notification
userIds = _.union(userIds, event.bookmarks);
for (const userId of userIds) {
amqp.send('universal_events', 'event.event_cancel', JSON.stringify({
event: notificationEvents.EVENT_CANCEL,
Expand Down
13 changes: 2 additions & 11 deletions services/chat-message-service.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
const mongoose = require('mongoose');
const { ChatMessage } = require('@wallfair.io/wallfair-commons').models;
const notificationsTypes = require('@wallfair.io/wallfair-commons').constants.events.notification;
const { ForbiddenError, NotFoundError } = require('../util/error-handler');

const notificationTypes = {
EVENT_START: 'Notification/EVENT_START',
EVENT_RESOLVE: 'Notification/EVENT_RESOLVE',
EVENT_CANCEL: 'Notification/EVENT_CANCEL',
BET_STARTED: 'Notification/BET_STARTED',
USER_AWARD: 'Notification/USER_AWARD',
};

exports.NotificationTypes = notificationTypes;

exports.getLatestChatMessagesByRoom = async (roomId, limit = 100, skip = 0) =>
ChatMessage.aggregate([
{
Expand Down Expand Up @@ -89,7 +80,7 @@ exports.getLatestChatMessagesByUserId = async (userId, limit = 100, skip = 0) =>
$match: {
userId: mongoose.Types.ObjectId(userId),
read: { $exists: false },
type: { $in: Object.values(notificationTypes) },
type: { $in: Object.values(notificationsTypes) },
},
},
{ $sort: { date: -1 } },
Expand Down

0 comments on commit c1cfc66

Please sign in to comment.