Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,27 @@ 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,
function afterDeleteFile($error /* , id */) {
done($error, file);
}
);
}
);
})
.catch((error) => {
done(error);
});

/*

*/
};

/* statics */
Expand Down Expand Up @@ -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
Expand Down
50 changes: 26 additions & 24 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,27 @@ 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,
function afterDeleteFile($error /* , id */) {
done($error, file);
}
);
}
);
})
.catch((error) => {
done(error);
});

/*

*/
};

/* statics */
Expand Down Expand Up @@ -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
Expand Down
48 changes: 25 additions & 23 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,27 @@ 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,
function afterDeleteFile($error /* , id */) {
done($error, file);
}
);
}
);
})
.catch((error) => {
done(error);
});

/*

*/
};

/* statics */
Expand Down Expand Up @@ -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
Expand Down