From 7e67a441cd9fb4b928203a5b2215126616139754 Mon Sep 17 00:00:00 2001 From: SachaG <358832+SachaG@users.noreply.github.com> Date: Mon, 20 Aug 2018 15:20:51 +0900 Subject: [PATCH] Backwards compatibility with documentId --- packages/vulcan-lib/lib/server/mutators.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/vulcan-lib/lib/server/mutators.js b/packages/vulcan-lib/lib/server/mutators.js index d5e0b3546..026951ddb 100644 --- a/packages/vulcan-lib/lib/server/mutators.js +++ b/packages/vulcan-lib/lib/server/mutators.js @@ -144,13 +144,14 @@ export const createMutator = async ({ collection, document, data, currentUser, v } -export const updateMutator = async ({ collection, selector, data, set = {}, unset = {}, currentUser, validate, context, document }) => { +export const updateMutator = async ({ collection, documentId, selector, data, set = {}, unset = {}, currentUser, validate, context, document }) => { const { collectionName, typeName } = collection.options; const schema = collection.simpleSchema()._schema; // OpenCRUD backwards compatibility + selector = selector || { _id: documentId }; data = data || modifierToData({ $set: set, $unset: unset }); if (isEmpty(selector)) { @@ -265,7 +266,7 @@ export const updateMutator = async ({ collection, selector, data, set = {}, unse return { data: newDocument }; } -export const deleteMutator = async ({ collection, selector, currentUser, validate, context, document }) => { +export const deleteMutator = async ({ collection, documentId, selector, currentUser, validate, context, document }) => { const { collectionName, typeName } = collection.options; @@ -276,6 +277,9 @@ export const deleteMutator = async ({ collection, selector, currentUser, validat const schema = collection.simpleSchema()._schema; + // OpenCRUD backwards compatibility + selector = selector || { _id: documentId }; + if (isEmpty(selector)) { throw new Error(`Selector cannot be empty`); }