Skip to content

Commit

Permalink
feat(FormModel): await pre-validate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui committed Oct 5, 2020
1 parent 4ee1592 commit 5228450
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/app/models/form.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ const compileFormModel = (db: Mongoose): IFormModel => {
}

// Hooks
FormSchema.pre<IFormSchema>('validate', function (next) {
FormSchema.pre<IFormSchema>('validate', async function (next) {
// Reject save if form document is too large
if (bson.calculateObjectSize(this) > 10 * MB) {
const err = new Error('Form size exceeded.')
Expand All @@ -493,7 +493,7 @@ const compileFormModel = (db: Mongoose): IFormModel => {
}

// Validate that admin exists before form is created.
void User.findById(this.admin, function (error, admin) {
await User.findById(this.admin, function (error, admin) {
if (error) {
return next(Error(`Error validating admin for form.`))
}
Expand Down

0 comments on commit 5228450

Please sign in to comment.