From 797dcf2b8e5307b50237491e95e0b99c354671c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C4=81ns=20Djatlovs?= Date: Tue, 30 May 2023 16:08:45 +0300 Subject: [PATCH] Fix issue with Model.findById() no longer accepts a callback --- src/schema.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/schema.js b/src/schema.js index 1ee2bae..533205d 100644 --- a/src/schema.js +++ b/src/schema.js @@ -176,15 +176,12 @@ function createFileSchema(bucket) { */ FileSchema.methods.unlink = function unlink(done) { // obtain file details - return this.constructor.findById( - // eslint-disable-next-line no-underscore-dangle - this._id, - function afterFindFile(error, file) { - // back-off error - if (error) { - return done(error); - } - // remove file from gridfs + this.constructor + .findById( + // eslint-disable-next-line no-underscore-dangle + this._id + ) + .then((file) => { return bucket.deleteFile( // eslint-disable-next-line no-underscore-dangle file._id, @@ -192,8 +189,14 @@ function createFileSchema(bucket) { done($error, file); } ); - } - ); + }) + .catch((error) => { + done(error); + }); + + /* + + */ }; /* statics */