diff --git a/es/index.js b/es/index.js index f8a645b..3825c4d 100644 --- a/es/index.js +++ b/es/index.js @@ -179,15 +179,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, @@ -195,8 +192,14 @@ function createFileSchema(bucket) { done($error, file); } ); - } - ); + }) + .catch((error) => { + done(error); + }); + + /* + + */ }; /* statics */ @@ -299,19 +302,18 @@ function createFileSchema(bucket) { * }); */ FileSchema.statics.unlink = function unlink(_id, done) { - return this.findById(_id, function afterFindById(error, file) { - // back-off error - if (error) { - return done(error); - } - - if (!file) { - return done(new Error('not found')); - } - - // remove file from gridfs - return file.unlink(done); - }); + this.findById(_id) + .then((file) => { + if (!file) { + return done(new Error('not found')); + } + + // remove file from gridfs + return file.unlink(done); + }) + .catch((error) => { + done(error); + }); }; // return grifs schema diff --git a/lib/index.js b/lib/index.js index 9488a35..c71af99 100644 --- a/lib/index.js +++ b/lib/index.js @@ -180,15 +180,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, @@ -196,8 +193,14 @@ function createFileSchema(bucket) { done($error, file); } ); - } - ); + }) + .catch((error) => { + done(error); + }); + + /* + + */ }; /* statics */ @@ -300,19 +303,18 @@ function createFileSchema(bucket) { * }); */ FileSchema.statics.unlink = function unlink(_id, done) { - return this.findById(_id, function afterFindById(error, file) { - // back-off error - if (error) { - return done(error); - } - - if (!file) { - return done(new Error('not found')); - } - - // remove file from gridfs - return file.unlink(done); - }); + this.findById(_id) + .then((file) => { + if (!file) { + return done(new Error('not found')); + } + + // remove file from gridfs + return file.unlink(done); + }) + .catch((error) => { + done(error); + }); }; // return grifs schema diff --git a/src/schema.js b/src/schema.js index 1ee2bae..00ad3a7 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 */ @@ -296,19 +299,18 @@ function createFileSchema(bucket) { * }); */ FileSchema.statics.unlink = function unlink(_id, done) { - return this.findById(_id, function afterFindById(error, file) { - // back-off error - if (error) { - return done(error); - } - - if (!file) { - return done(new Error('not found')); - } + this.findById(_id) + .then((file) => { + if (!file) { + return done(new Error('not found')); + } - // remove file from gridfs - return file.unlink(done); - }); + // remove file from gridfs + return file.unlink(done); + }) + .catch((error) => { + done(error); + }); }; // return grifs schema