diff --git a/src/auth/operations/forgotPassword.js b/src/auth/operations/forgotPassword.js index 3c287ec65b..c8a112fe66 100644 --- a/src/auth/operations/forgotPassword.js +++ b/src/auth/operations/forgotPassword.js @@ -2,7 +2,7 @@ const crypto = require('crypto'); const { APIError } = require('../../errors'); async function forgotPassword(args) { - const { config, email } = this; + const { config, sendEmail: email } = this; if (!Object.prototype.hasOwnProperty.call(args.data, 'email')) { throw new APIError('Missing email.'); diff --git a/src/auth/operations/registerFirstUser.js b/src/auth/operations/registerFirstUser.js index dfa163a0da..57abfac9e5 100644 --- a/src/auth/operations/registerFirstUser.js +++ b/src/auth/operations/registerFirstUser.js @@ -1,5 +1,3 @@ -const register = require('./register'); -const login = require('./login'); const { Forbidden } = require('../../errors'); async function registerFirstUser(args) { @@ -17,7 +15,7 @@ async function registerFirstUser(args) { // 2. Perform register first user // ///////////////////////////////////// - let result = await register({ + let result = await this.operations.collections.auth.register({ ...args, overrideAccess: true, }); @@ -27,7 +25,7 @@ async function registerFirstUser(args) { // 3. Log in new user // ///////////////////////////////////// - const token = await login({ + const token = await this.operations.collections.auth.login({ ...args, }); diff --git a/src/collections/init.js b/src/collections/init.js index 8d3b92f0b6..3f82b6d9c0 100644 --- a/src/collections/init.js +++ b/src/collections/init.js @@ -43,14 +43,6 @@ function registerCollections() { delete: deleteHandler, } = this.requestHandlers.collections; - router.route(`/${slug}`) - .get(find) - .put(update); - - router.route(`/${slug}/:id`) - .get(findByID) - .delete(deleteHandler); - if (collection.auth) { const AuthCollection = this.collections[formattedCollection.slug]; passport.use(new LocalStrategy(AuthCollection.Model.authenticate())); @@ -108,12 +100,22 @@ function registerCollections() { .route(`/${slug}/register`) .post(register); + router.route(`/${slug}`) + .get(find); + router.route(`/${slug}/:id`) - .put(authUpdate); + .get(findByID) + .put(authUpdate) + .delete(deleteHandler); } else { router.route(`/${slug}`) .get(find) .post(create); + + router.route(`/${slug}/:id`) + .put(update) + .get(findByID) + .delete(deleteHandler); } this.router.use(router); diff --git a/src/collections/requestHandlers/delete.js b/src/collections/requestHandlers/delete.js index 40e83d34a6..4f44aac494 100644 --- a/src/collections/requestHandlers/delete.js +++ b/src/collections/requestHandlers/delete.js @@ -3,7 +3,7 @@ const { NotFound } = require('../../errors'); async function deleteHandler(req, res, next) { try { - const doc = await this.operations.collections.deleteQuery({ + const doc = await this.operations.collections.delete({ req, collection: req.collection, id: req.params.id, diff --git a/src/fields/performFieldOperations.js b/src/fields/performFieldOperations.js index 0a83d99a94..ee2e9ba6f4 100644 --- a/src/fields/performFieldOperations.js +++ b/src/fields/performFieldOperations.js @@ -21,7 +21,7 @@ async function performFieldOperations(entityConfig, operation) { depth = (operation.depth || operation.depth === 0) ? parseInt(operation.depth, 10) : this.config.defaultDepth; } - const currentDepth = operation.currentDepth || 0; + const currentDepth = operation.currentDepth || 1; const populateRelationship = async (dataReference, data, field, i) => { const dataToUpdate = dataReference; @@ -40,6 +40,7 @@ async function performFieldOperations(entityConfig, operation) { id: Array.isArray(field.relationTo) ? data.value : data, currentDepth: currentDepth + 1, disableErrors: true, + depth, }); }