How to use the moleculer.ValidationError function in moleculer

To help you get started, we’ve selected a few moleculer 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 icebob / kantab / backend / mixins / database.js View on Github external
if (field.trim) {
					if (field.trim === true)
						value = value.trim();
					else if (field.trim === "right")
						value = value.trimRight();
					else if (field.trim === "left")
						value = value.trimLeft();
				}

				// TODO: more sanitization
				// - lowercase, uppercase, ...etc

				// Validating
				if (value == undefined) {
					if (field.required && isNew)
						promises.push(Promise.reject(new ValidationError(`The '${field.name}' field is missing.`))); // TODO
					return;
				}

				/**
				 * TODO:
				 * 	- custom validate fn
				 *  - min, max for number
				 *  - pattern for string
				 */


				_.set(entity, field.name, value);

				// Because the key is the path. Mongo overwrites a nested object if set a nested object
				updates[field.name] = value;
			};
github icebob / kantab / backend / services / config.service.js View on Github external
async handler(ctx) {
				if (ctx.params.key == null)
					throw new ValidationError("Param 'key' must be defined.", "ERR_KEY_NOT_DEFINED");

				return await this.transformDocuments(ctx, {}, await this.get(ctx.params.key));
			}
		},
github moleculerjs / moleculer-addons / packages / moleculer-db / src / index.js View on Github external
this.settings.entityValidator = entity => {
				const res = check(entity);
				if (res === true)
					return this.Promise.resolve();
				else
					return this.Promise.reject(new ValidationError("Entity validation error!", null, res));
			};
		}
github moleculerjs / moleculer-db / packages / moleculer-db / src / index.js View on Github external
this.settings.entityValidator = entity => {
				const res = check(entity);
				if (res === true)
					return Promise.resolve();
				else
					return Promise.reject(new ValidationError("Entity validation error!", null, res));
			};
		}