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);
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);
--- 
+++ 
@@ -4,7 +4,6 @@
 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);
+addCallback("subscription.create.async", deleteOldSubscriptions);
deleteOldSubscriptions: Fix run-order issue where callback that was supposed to delete old sub, deleted new sub too
