Constructor
new ValidateSchema(rules)
Constructs a ValidateSchema instance based on the provided rules.
Parameters:
| Name | Type | Description |
|---|---|---|
rules |
string | Object | A string indicating the collection name to use as schema, or an object specifying the Mongoose schema configurations. |
- Source:
Throws:
-
- Throws an error if the provided rules are invalid or the collection name is not found.
- Type
- Error
Methods
placeDefault(customSelfopt) → {Object}
Populates the schema fields with their default values if not provided in the input object.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
customSelf |
Object |
<optional> |
The custom object to be populated (optional, uses the instance itself by default). |
- Source:
Returns:
- The populated object with default values.
- Type
- Object
validate(data, returnValidObjopt) → {ValidationError|Object}
Validates the provided data against the schema and returns the validation result.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
data |
Object | The data to be validated against the schema. |
||
returnValidObj |
boolean |
<optional> |
false | A flag indicating whether to return the validated object. |
- Source:
Returns:
- If
returnValidObjis true, returns the validated object. Otherwise, returns the validation error object.
- Type
- ValidationError | Object