add error callback for schema.post() fixes #12943

This commit is contained in:
Simon
2016-11-30 09:46:09 -05:00
parent 2fc5a264d6
commit 8c1639aeec
2 changed files with 19 additions and 4 deletions

10
mongoose/index.d.ts vendored
View File

@@ -609,9 +609,13 @@ declare module "mongoose" {
* @param method name of the method to hook
* @param fn callback
*/
post<T extends Document>(method: string, fn: (doc: T, next: (err?: NativeError) => void,
...otherArgs: any[]) => void): this;
post<T extends Document>(method: string, fn: (doc: T) => void, ...args: any[]): this;
post<T extends Document>(method: string, fn: (
error: mongodb.MongoError, doc: T, next: (err?: NativeError) => void
) => void): this;
post<T extends Document>(method: string, fn: (
doc: T, next: (err?: NativeError) => void
) => void): this;
/**
* Defines a pre hook for the document.

View File

@@ -266,8 +266,19 @@ schema.plugin(function (schema, opts) {
schema.get('path');
opts.hasOwnProperty('');
}).plugin(cb, {opts: true});
schema.post('post', function (doc) {}).post('post', function (doc, next) {
import { Schema, Model, Document, NativeError } from 'mongoose';
schema
.post('save', function (error, doc, next) {
error.stack;
doc.model;
next.apply;
})
.post('save', function (doc: mongoose.Document, next: Function) {
doc.model;
next(new Error());
})
.post('save', function (doc: mongoose.Document) {
doc.model;
});
schema.queue('m1', [1, 2, 3]).queue('m2', [[]]);
schema.remove('path');