How to use the simpl-schema.defineValidationErrorTransform function in simpl-schema

To help you get started, we’ve selected a few simpl-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Blockrazor / blockrazor / imports / api / problems / methods.js View on Github external
import { Meteor } from 'meteor/meteor'
import { UserData, Wallet, Problems, ProblemImages, ProblemComments, developmentValidationEnabledFalse } from '/imports/api/indexDB'
import SimpleSchema from 'simpl-schema';
import { check } from 'meteor/check'
import { sendMessage } from '/imports/api/activityLog/methods'


SimpleSchema.defineValidationErrorTransform(error => {
  const ddpError = new Meteor.Error(error.message);
  ddpError.error = 'validation-error';
  ddpError.details = error.details[0].message;
  return ddpError;
});



export const newProblem = new ValidatedMethod({
  name: 'newProblem',
	validate: new SimpleSchema(Problems.schema.pick("type","header","text","images","images.$","bounty"), {
		requiredByDefault: developmentValidationEnabledFalse
	}).validator({clean:true}),
  run({ type, header, text, images, bounty }) {
			if (Meteor.userId()) {
				if (bounty > 0) { // check if the user can finance the bounty
github ejfrancis / Meteor-Vue-Enterprise-Starter / src / imports / startup / server / server-index.js View on Github external
Meteor.startup(() => {
  // configure the password reset email via the accounts-password package
  setupPasswordResetEmail();
  // configure the account enrollment email via the accounts-password package
  setupEnrollAccountEmail();

  // configure accounts validation via the accounts-password package
  setupAccountsValidation();

  // publications
  // setupUsersAdminPublication();

  // enable Meteor.Error to be thrown for validation errors in from Meteor Methods
  SimpleSchema.defineValidationErrorTransform(error => {
    const ddpError = new Meteor.Error(error.message);
    ddpError.error = 'validation-error';
    ddpError.details = error.details;
    return ddpError;
  });
});
github reactioncommerce / reaction / imports / collections / schemas / schemaErrors.js View on Github external
import SimpleSchema from "simpl-schema";
import { Meteor } from "meteor/meteor";

// This is needed so that it throws a Meteor.Error as `check()` would do
// when we call schema.validate() in a Meteor method.
// https://github.com/aldeed/node-simple-schema/#customize-the-error-that-is-thrown
SimpleSchema.defineValidationErrorTransform((error) => {
  const ddpError = new Meteor.Error(error.message);
  ddpError.error = "validation-error";
  ddpError.details = error.details;
  return ddpError;
});
github JithinKS97 / dynamic-learning / imports / startup / simple-schema-configuration.js View on Github external
import { Meteor } from 'meteor/meteor';
import SimpleSchema from 'simpl-schema';

SimpleSchema.defineValidationErrorTransform(e => (
  new Meteor.Error(400, e.message)
));
github Blockrazor / blockrazor / imports / startup / both / index.js View on Github external
import SimpleSchema from 'simpl-schema';

//provides a reason for mdg validated method error throw to notify user from error.message generated by simpleSchema
SimpleSchema.defineValidationErrorTransform(error => {
  const ddpError = new Meteor.Error(error.message);
  ddpError.error = 'validation-error';
  ddpError.details = error.details;
  ddpError.reason = error.details.reduce((a,x)=>a+x.message+". ", "")
  return ddpError;
});

//methods
import '/imports/api/users/methods'
import '/imports/api/coins/methods.js'
import '/imports/api/miscellaneous/methods'
import '/imports/api/features/methods'
import '/imports/api/redflags/methods'
import '/imports/api/exchanges/methods'
import '/imports/api/coins/methods'
import '/imports/api/miscellaneous/mime'