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