import { addCallback } from 'meteor/vulcan:core';
import { Subscriptions } from './collection'

async function deleteOldSubscriptions(subscription) {
  const { userId, documentId, collectionName, type } = subscription
  Subscriptions.update({userId, documentId, collectionName, type}, {$set: {deleted: true}}, {multi: true})
}

addCallback("subscription.create.async", deleteOldSubscriptions);
import { addCallback } from 'meteor/vulcan:core';
import { Subscriptions } from './collection'

async function deleteOldSubscriptions(subscription) {
  const { userId, documentId, collectionName, type } = subscription
  Subscriptions.update({userId, documentId, collectionName, type}, {$set: {deleted: true}}, {multi: true})
  return subscription;
}

addCallback("subscription.create.before", deleteOldSubscriptions);
Fix run-order issue where callback that was supposed to delete old sub, deleted new sub too
deleteOldSubscriptions: Fix run-order issue where callback that was supposed to delete old sub, deleted new sub too
