2016-11-07 12:59:39 +09:00
|
|
|
/*
|
|
|
|
|
|
|
|
Mutations have four steps:
|
|
|
|
|
|
|
|
1. Validation
|
|
|
|
|
2017-02-06 21:47:27 +08:00
|
|
|
If the mutation call is not trusted (i.e. it comes from a GraphQL mutation),
|
2016-11-14 17:17:44 +09:00
|
|
|
we'll run all validate steps:
|
|
|
|
|
|
|
|
- Check that the current user has permission to insert/edit each field.
|
|
|
|
- Add userId to document (insert only).
|
|
|
|
- Run validation callbacks.
|
2016-11-07 12:59:39 +09:00
|
|
|
|
|
|
|
2. Sync Callbacks
|
|
|
|
|
2017-02-06 21:47:27 +08:00
|
|
|
The second step is to run the mutation argument through all the sync callbacks.
|
2016-11-07 12:59:39 +09:00
|
|
|
|
|
|
|
3. Operation
|
|
|
|
|
|
|
|
We then perform the insert/update/remove operation.
|
|
|
|
|
|
|
|
4. Async Callbacks
|
|
|
|
|
2017-02-06 21:47:27 +08:00
|
|
|
Finally, *after* the operation is performed, we execute any async callbacks.
|
2016-11-07 12:59:39 +09:00
|
|
|
Being async, they won't hold up the mutation and slow down its response time
|
2017-02-06 21:47:27 +08:00
|
|
|
to the client.
|
2016-11-07 12:59:39 +09:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-08-17 10:48:20 +09:00
|
|
|
import { runCallbacks, runCallbacksAsync } from '../modules/index.js';
|
2017-08-16 16:18:40 +09:00
|
|
|
import { createError } from 'apollo-errors';
|
2018-06-19 11:00:20 +09:00
|
|
|
import { validateDocument, validateModifier, validateData, dataToModifier, modifierToData } from '../modules/validation.js';
|
2018-03-03 11:39:56 +09:00
|
|
|
import { registerSetting } from '../modules/settings.js';
|
2018-06-18 10:05:54 +09:00
|
|
|
import { debug, debugGroup, debugGroupEnd } from '../modules/debug.js';
|
2018-02-11 12:57:51 +09:00
|
|
|
import { Connectors } from './connectors.js';
|
2018-06-17 16:23:22 +09:00
|
|
|
import pickBy from 'lodash/pickBy';
|
2018-02-11 12:57:51 +09:00
|
|
|
|
|
|
|
registerSetting('database', 'mongo', 'Which database to use for your back-end');
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2018-06-05 16:39:03 +09:00
|
|
|
export const createMutator = async ({ collection, document, data, currentUser, validate, context }) => {
|
2017-02-06 21:47:27 +08:00
|
|
|
|
2018-06-19 11:00:20 +09:00
|
|
|
const { collectionName, typeName } = collection.options;
|
2018-06-18 10:05:54 +09:00
|
|
|
|
|
|
|
debug('');
|
|
|
|
debugGroup(`--------------- start \x1b[35m${collectionName}\x1b[0m create mutator ---------------`);
|
2017-09-15 11:14:09 +02:00
|
|
|
debug(`validate: ${validate}`);
|
2018-06-06 07:36:25 +09:00
|
|
|
debug(document || data);
|
2017-02-06 21:47:27 +08:00
|
|
|
|
2017-01-11 18:02:12 +01:00
|
|
|
// we don't want to modify the original document
|
2018-06-05 16:39:03 +09:00
|
|
|
let newDocument = Object.assign({}, document || data);
|
2017-08-16 16:18:40 +09:00
|
|
|
|
2016-11-14 17:17:44 +09:00
|
|
|
const schema = collection.simpleSchema()._schema;
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2016-11-07 12:11:02 +09:00
|
|
|
if (validate) {
|
2016-11-14 17:17:44 +09:00
|
|
|
|
2017-08-17 10:48:20 +09:00
|
|
|
const validationErrors = validateDocument(newDocument, collection, context);
|
2016-11-14 17:17:44 +09:00
|
|
|
|
|
|
|
// run validation callbacks
|
2018-06-19 11:00:20 +09:00
|
|
|
newDocument = runCallbacks({ name: `${typeName.toLowerCase()}.create.validate`, iterator: newDocument, properties: { currentUser, validationErrors }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
newDocument = runCallbacks(`${collectionName.toLowerCase()}.new.validate`, newDocument, currentUser, validationErrors);
|
2018-06-02 18:49:53 +09:00
|
|
|
|
2017-08-16 16:18:40 +09:00
|
|
|
if (validationErrors.length) {
|
|
|
|
const NewDocumentValidationError = createError('app.validation_error', {message: 'app.new_document_validation_error'});
|
|
|
|
throw new NewDocumentValidationError({data: {break: true, errors: validationErrors}});
|
|
|
|
}
|
|
|
|
|
2016-11-07 12:11:02 +09:00
|
|
|
}
|
2017-04-03 16:24:19 +09:00
|
|
|
|
2017-12-25 15:39:22 +09:00
|
|
|
// if user is logged in, check if userId field is in the schema and add it to document if needed
|
|
|
|
if (currentUser) {
|
|
|
|
const userIdInSchema = Object.keys(schema).find(key => key === 'userId');
|
|
|
|
if (!!userIdInSchema && !newDocument.userId) newDocument.userId = currentUser._id;
|
|
|
|
}
|
|
|
|
|
2017-04-28 09:24:28 +09:00
|
|
|
// run onInsert step
|
2017-08-30 09:38:05 +09:00
|
|
|
// note: cannot use forEach with async/await.
|
|
|
|
// See https://stackoverflow.com/a/37576787/649299
|
2018-06-17 12:30:37 +09:00
|
|
|
for(let fieldName of Object.keys(schema)) {
|
2018-06-14 15:51:04 +09:00
|
|
|
let autoValue;
|
|
|
|
if (schema[fieldName].onCreate) {
|
|
|
|
autoValue = await schema[fieldName].onCreate({ newDocument, currentUser });
|
2018-06-17 08:00:19 +09:00
|
|
|
} else if (schema[fieldName].onInsert) {
|
2018-06-14 15:51:04 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
|
|
|
autoValue = await schema[fieldName].onInsert(newDocument, currentUser);
|
|
|
|
}
|
|
|
|
if (typeof autoValue !== 'undefined') {
|
|
|
|
newDocument[fieldName] = autoValue;
|
2017-04-03 16:24:19 +09:00
|
|
|
}
|
2017-08-30 09:38:05 +09:00
|
|
|
}
|
2017-04-03 16:24:19 +09:00
|
|
|
|
2016-11-07 11:47:33 +09:00
|
|
|
// TODO: find that info in GraphQL mutations
|
|
|
|
// if (Meteor.isServer && this.connection) {
|
|
|
|
// post.userIP = this.connection.clientAddress;
|
2017-09-14 19:47:35 +02:00
|
|
|
// post.userAgent = this.connection.httpHeaders['user-agent'];
|
2016-11-07 11:47:33 +09:00
|
|
|
// }
|
|
|
|
|
|
|
|
// run sync callbacks
|
2018-06-19 11:00:20 +09:00
|
|
|
newDocument = await runCallbacks({ name: `${typeName}.create.before`, iterator: newDocument, properties: { currentUser }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
newDocument = await runCallbacks(`${collectionName.toLowerCase()}.new.before`, newDocument, currentUser);
|
|
|
|
newDocument = await runCallbacks(`${collectionName.toLowerCase()}.new.sync`, newDocument, currentUser);
|
2016-11-07 11:47:33 +09:00
|
|
|
|
|
|
|
// add _id to document
|
2018-03-03 11:39:56 +09:00
|
|
|
newDocument._id = await Connectors.create(collection, newDocument);
|
2016-11-07 12:59:39 +09:00
|
|
|
|
2017-10-21 12:47:58 +09:00
|
|
|
// run any post-operation sync callbacks
|
2018-06-19 11:00:20 +09:00
|
|
|
newDocument = await runCallbacks({ name: `${typeName.toLowerCase()}.create.after`, iterator: newDocument, properties: { currentUser }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
newDocument = await runCallbacks(`${collectionName.toLowerCase()}.new.after`, newDocument, currentUser);
|
2017-10-21 12:47:58 +09:00
|
|
|
|
2016-11-07 12:59:39 +09:00
|
|
|
// get fresh copy of document from db
|
2017-10-21 12:47:58 +09:00
|
|
|
// TODO: not needed?
|
2018-03-03 11:39:56 +09:00
|
|
|
const insertedDocument = await Connectors.get(collection, newDocument._id);
|
2016-11-07 11:47:33 +09:00
|
|
|
|
|
|
|
// run async callbacks
|
|
|
|
// note: query for document to get fresh document with collection-hooks effects applied
|
2018-06-19 11:00:20 +09:00
|
|
|
await runCallbacksAsync({ name: `${typeName.toLowerCase()}.create.async`, properties: { insertedDocument, currentUser, collection }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
await runCallbacksAsync(`${collectionName.toLowerCase()}.new.async`, insertedDocument, currentUser, collection);
|
2017-02-06 21:47:27 +08:00
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
debug(`\x1b[33m=> created new document: \x1b[0m`);
|
2017-09-14 19:47:35 +02:00
|
|
|
debug(newDocument);
|
2018-06-18 10:05:54 +09:00
|
|
|
debugGroupEnd();
|
|
|
|
debug(`--------------- end \x1b[35m${collectionName}\x1b[0m create mutator ---------------`);
|
|
|
|
debug('');
|
2017-02-06 21:47:27 +08:00
|
|
|
|
2018-06-05 16:39:03 +09:00
|
|
|
return { data: newDocument };
|
2016-11-07 11:47:33 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
export const updateMutator = async ({ collection, documentId, selector, data, set = {}, unset = {}, currentUser, validate, context }) => {
|
|
|
|
|
2018-06-19 11:00:20 +09:00
|
|
|
const { collectionName, typeName } = collection.options;
|
2018-06-08 13:31:15 +09:00
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-08 13:31:15 +09:00
|
|
|
if (!selector) {
|
2018-06-18 10:05:54 +09:00
|
|
|
selector = { documentId };
|
2018-06-08 13:31:15 +09:00
|
|
|
}
|
2017-02-06 21:47:27 +08:00
|
|
|
|
2016-11-14 17:17:44 +09:00
|
|
|
const schema = collection.simpleSchema()._schema;
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2018-06-14 15:51:04 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
data = data || modifierToData({ $set: set, $unset: unset });
|
2018-06-08 13:31:15 +09:00
|
|
|
|
2016-11-07 11:47:33 +09:00
|
|
|
// get original document from database
|
2018-01-20 11:02:11 +09:00
|
|
|
// TODO: avoid fetching document a second time if possible
|
2018-06-08 13:31:15 +09:00
|
|
|
let document = await Connectors.get(collection, selector);
|
2017-08-16 16:18:40 +09:00
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
debug('');
|
|
|
|
debugGroup(`--------------- start \x1b[35m${collectionName}\x1b[0m update mutator ---------------`);
|
|
|
|
debug('// collectionName: ', collectionName);
|
2018-06-08 13:31:15 +09:00
|
|
|
debug('// selector: ', selector);
|
2018-06-17 16:23:22 +09:00
|
|
|
debug('// data: ', data);
|
2016-11-07 12:11:02 +09:00
|
|
|
|
|
|
|
if (validate) {
|
2016-11-14 17:17:44 +09:00
|
|
|
|
2018-06-14 15:51:04 +09:00
|
|
|
let validationErrors;
|
2017-04-03 16:24:19 +09:00
|
|
|
|
2018-06-19 11:00:20 +09:00
|
|
|
validationErrors = validateData(data, document, collection, context);
|
|
|
|
runCallbacks({ name: `${typeName.toLowerCase()}.update.validate`, iterator: data, properties: { document, currentUser, validationErrors }});
|
|
|
|
// OpenCRUD backwards compatibility
|
|
|
|
runCallbacks(`${collectionName.toLowerCase()}.edit.validate`, dataToModifier(data), document, currentUser, validationErrors);
|
2017-08-16 16:18:40 +09:00
|
|
|
|
|
|
|
if (validationErrors.length) {
|
2018-01-25 15:03:03 -06:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log('// validationErrors');
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(validationErrors);
|
2018-06-14 15:51:04 +09:00
|
|
|
const EditDocumentValidationError = createError('app.validation_error', { message: 'app.edit_document_validation_error' });
|
2017-08-16 16:18:40 +09:00
|
|
|
throw new EditDocumentValidationError({data: {break: true, errors: validationErrors}});
|
|
|
|
}
|
2016-11-14 17:17:44 +09:00
|
|
|
|
2016-11-07 12:11:02 +09:00
|
|
|
}
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2018-03-19 14:58:31 +09:00
|
|
|
// get a "preview" of the new document
|
2018-06-17 16:23:22 +09:00
|
|
|
let newDocument = { ...document, ...data};
|
|
|
|
newDocument = pickBy(newDocument, f => f !== null);
|
2018-03-19 14:58:31 +09:00
|
|
|
|
2018-06-17 08:00:19 +09:00
|
|
|
// run onUpdate step
|
2018-06-17 12:30:37 +09:00
|
|
|
for(let fieldName of Object.keys(schema)) {
|
2018-06-14 15:51:04 +09:00
|
|
|
let autoValue;
|
|
|
|
if (schema[fieldName].onUpdate) {
|
|
|
|
autoValue = await schema[fieldName].onUpdate({ data, document, currentUser, newDocument });
|
2018-06-17 08:00:19 +09:00
|
|
|
} else if (schema[fieldName].onEdit) {
|
2018-06-17 16:23:22 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
autoValue = await schema[fieldName].onEdit(dataToModifier(data), document, currentUser, newDocument);
|
|
|
|
}
|
|
|
|
if (typeof autoValue !== 'undefined') {
|
|
|
|
data[fieldName] = autoValue;
|
2017-04-03 16:24:19 +09:00
|
|
|
}
|
2017-08-30 09:38:05 +09:00
|
|
|
}
|
2017-04-03 16:24:19 +09:00
|
|
|
|
2018-06-17 16:23:22 +09:00
|
|
|
// run sync callbacks
|
2018-06-19 11:00:20 +09:00
|
|
|
data = await runCallbacks({ name: `${typeName.toLowerCase()}.update.before`, iterator: data, properties: { document, currentUser, newDocument }});
|
2018-06-14 15:51:04 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
data = modifierToData(await runCallbacks(`${collectionName.toLowerCase()}.edit.before`, dataToModifier(data), document, currentUser, newDocument));
|
|
|
|
data = modifierToData(await runCallbacks(`${collectionName.toLowerCase()}.edit.sync`, dataToModifier(data), document, currentUser, newDocument));
|
2018-06-14 15:51:04 +09:00
|
|
|
|
|
|
|
// update connector requires a modifier, so get it from data
|
2018-06-19 11:00:20 +09:00
|
|
|
const modifier = dataToModifier(data);
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2017-04-03 16:24:19 +09:00
|
|
|
// remove empty modifiers
|
|
|
|
if (_.isEmpty(modifier.$set)) {
|
|
|
|
delete modifier.$set;
|
|
|
|
}
|
|
|
|
if (_.isEmpty(modifier.$unset)) {
|
|
|
|
delete modifier.$unset;
|
|
|
|
}
|
2018-06-14 15:51:04 +09:00
|
|
|
|
2018-05-17 09:53:16 +09:00
|
|
|
if (!_.isEmpty(modifier)) {
|
|
|
|
// update document
|
2018-06-14 15:51:04 +09:00
|
|
|
await Connectors.update(collection, selector, modifier, { removeEmptyStrings: false });
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2018-05-17 09:53:16 +09:00
|
|
|
// get fresh copy of document from db
|
2018-06-08 13:31:15 +09:00
|
|
|
newDocument = await Connectors.get(collection, selector);
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2018-06-08 13:31:15 +09:00
|
|
|
// TODO: add support for caching by other indexes to Dataloader
|
2018-06-15 10:18:20 +09:00
|
|
|
// https://github.com/VulcanJS/Vulcan/issues/2000
|
2018-05-17 09:53:16 +09:00
|
|
|
// clear cache if needed
|
2018-06-08 13:31:15 +09:00
|
|
|
if (selector.documentId && collection.loader) {
|
|
|
|
collection.loader.clear(selector.documentId);
|
2018-05-17 09:53:16 +09:00
|
|
|
}
|
2017-04-25 12:57:08 +09:00
|
|
|
}
|
2017-04-15 21:39:36 +09:00
|
|
|
|
2017-10-21 12:47:58 +09:00
|
|
|
// run any post-operation sync callbacks
|
2018-06-19 11:00:20 +09:00
|
|
|
newDocument = await runCallbacks({ name: `${typeName.toLowerCase()}.update.after`, iterator: newDocument, properties: { document, currentUser }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
newDocument = await runCallbacks(`${collectionName.toLowerCase()}.edit.after`, newDocument, document, currentUser);
|
2017-10-21 12:47:58 +09:00
|
|
|
|
2016-11-07 11:47:33 +09:00
|
|
|
// run async callbacks
|
2018-06-19 11:00:20 +09:00
|
|
|
await runCallbacksAsync({ name: `${typeName.toLowerCase()}.update.async`, properties: { newDocument, document, currentUser, collection }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
await runCallbacksAsync(`${collectionName.toLowerCase()}.edit.async`, newDocument, document, currentUser, collection);
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
debug(`\x1b[33m=> updated document with modifier: \x1b[0m`);
|
2017-10-05 09:14:42 +09:00
|
|
|
debug('// modifier: ', modifier)
|
2018-06-18 10:05:54 +09:00
|
|
|
debugGroupEnd();
|
|
|
|
debug(`--------------- end \x1b[35m${collectionName}\x1b[0m update mutator ---------------`);
|
|
|
|
debug('');
|
2016-11-14 17:17:44 +09:00
|
|
|
|
2018-06-05 16:39:03 +09:00
|
|
|
return { data: newDocument };
|
2016-11-07 11:47:33 +09:00
|
|
|
}
|
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
export const deleteMutator = async ({ collection, selector, documentId, currentUser, validate, context }) => {
|
|
|
|
|
2018-06-19 11:00:20 +09:00
|
|
|
const { collectionName, typeName } = collection.options;
|
2016-11-07 11:47:33 +09:00
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
debug('');
|
|
|
|
debugGroup(`--------------- start \x1b[35m${collectionName}\x1b[0m delete mutator ---------------`);
|
|
|
|
debug('// collectionName: ', collectionName);
|
|
|
|
debug('// selector: ', selector);
|
2017-09-14 19:47:35 +02:00
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-08 13:31:15 +09:00
|
|
|
if (!selector) {
|
2018-06-18 10:05:54 +09:00
|
|
|
selector = { documentId };
|
2018-06-08 13:31:15 +09:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:24:28 +09:00
|
|
|
const schema = collection.simpleSchema()._schema;
|
2016-11-07 12:59:39 +09:00
|
|
|
|
2018-06-08 13:31:15 +09:00
|
|
|
let document = await Connectors.get(collection, selector);
|
2016-11-07 12:59:39 +09:00
|
|
|
|
|
|
|
// if document is not trusted, run validation callbacks
|
|
|
|
if (validate) {
|
2018-06-19 11:00:20 +09:00
|
|
|
document = runCallbacks({ name: `${typeName.toLowerCase()}.delete.validate`, iterator: document, properties: { currentUser }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
document = runCallbacks(`${collectionName.toLowerCase()}.remove.validate`, document, currentUser);
|
2016-11-07 12:59:39 +09:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:24:28 +09:00
|
|
|
// run onRemove step
|
2018-06-17 12:30:37 +09:00
|
|
|
for(let fieldName of Object.keys(schema)) {
|
2018-06-17 08:00:19 +09:00
|
|
|
if (schema[fieldName].onDelete) {
|
|
|
|
await schema[fieldName].onDelete({ document, currentUser });
|
|
|
|
} else if (schema[fieldName].onRemove) {
|
|
|
|
// OpenCRUD backwards compatibility
|
|
|
|
await schema[fieldName].onRemove(document, currentUser);
|
2017-04-28 09:24:28 +09:00
|
|
|
}
|
2017-08-30 09:38:05 +09:00
|
|
|
}
|
2017-04-28 09:24:28 +09:00
|
|
|
|
2018-06-19 11:00:20 +09:00
|
|
|
await runCallbacks({ name: `${typeName.toLowerCase()}.delete.before`, iterator: document, properties: { currentUser }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
await runCallbacks(`${collectionName.toLowerCase()}.remove.before`, document, currentUser);
|
|
|
|
await runCallbacks(`${collectionName.toLowerCase()}.remove.sync`, document, currentUser);
|
2016-11-07 12:59:39 +09:00
|
|
|
|
2018-06-08 13:31:15 +09:00
|
|
|
await Connectors.delete(collection, selector);
|
2016-11-07 12:59:39 +09:00
|
|
|
|
2018-06-08 13:31:15 +09:00
|
|
|
// TODO: add support for caching by other indexes to Dataloader
|
2017-04-25 12:57:08 +09:00
|
|
|
// clear cache if needed
|
2018-06-08 13:31:15 +09:00
|
|
|
if (selector.documentId && collection.loader) {
|
|
|
|
collection.loader.clear(selector.documentId);
|
2017-04-25 12:57:08 +09:00
|
|
|
}
|
|
|
|
|
2018-06-19 11:00:20 +09:00
|
|
|
await runCallbacksAsync({ name: `${typeName.toLowerCase()}.delete.async`, properties: { document, currentUser, collection }});
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
2018-06-19 11:00:20 +09:00
|
|
|
await runCallbacksAsync(`${collectionName.toLowerCase()}.remove.async`, document, currentUser, collection);
|
2016-12-05 09:29:49 +09:00
|
|
|
|
2018-06-18 10:05:54 +09:00
|
|
|
debugGroupEnd();
|
|
|
|
debug(`--------------- end \x1b[35m${collectionName}\x1b[0m delete mutator ---------------`);
|
|
|
|
debug('');
|
|
|
|
|
2018-06-05 16:39:03 +09:00
|
|
|
return { data: document };
|
2016-11-07 11:47:33 +09:00
|
|
|
}
|
2017-12-25 15:39:22 +09:00
|
|
|
|
2018-06-02 18:49:53 +09:00
|
|
|
// OpenCRUD backwards compatibility
|
|
|
|
export const newMutation = createMutator;
|
|
|
|
export const editMutation = updateMutator;
|
|
|
|
export const removeMutation = deleteMutator;
|
|
|
|
export const newMutator = createMutator;
|
|
|
|
export const editMutator = updateMutator;
|
|
|
|
export const removeMutator = deleteMutator;
|