gstore-node
v8.x
v8.x
  • Introduction
  • Getting Started
    • Motivation
    • Installation
    • Create a gstore instance
  • Schema
    • About
    • Type validation
    • Value validation
    • Additional properties settings
    • Schema options
    • Joi Schema
    • Methods
      • path()
      • virtual()
    • Custom methods
  • Model
    • Creation
    • Methods
      • GET
      • UPDATE
      • DELETE
      • excludeFromIndexes()
      • key()
      • sanitize()
      • clearCache()
  • Entity
    • Creation
    • Properties
    • Methods
      • SAVE
      • plain()
      • populate()
      • model()
      • datastoreEntity()
      • validate()
  • Queries
    • @google-cloud Query
    • list()
    • findOne()
    • deleteAll()
    • findAround()
  • Populate
  • Middleware (hooks)
    • About
    • Pre hooks
    • Post hooks
  • Cache / Dataloader
    • Dataloader
    • Cache
  • gstore Methods
    • save()
  • Typescript
  • Appendix
    • Error Codes
    • Credits
Powered by GitBook
On this page

Was this helpful?

  1. Entity
  2. Methods

validate()

This methods validates an entity data.

@Returns an object with an error and a value property

If the error is null, it is valid. The value returned is the entityData sanitized (unknown properties removed).

const schema = new Schema({ firstname: { type: String }, lastname: { type: String } });
const User = gstore.model('User', schema);

const user = new User({ firstname: 'John', lastname: 'Snow' });
const { error } = user.validate();

// error === null --> valid

The validate() method also returns a Promise if you need to chain it

const user = new User({ firstname: 'John', lastname: 'Snow' });

user.validate()
    .then((value) => {
        // value is the entityData sanitized
    }, (err) => {
        // the validation Error
    });
PreviousdatastoreEntity()NextQueries

Last updated 6 years ago

Was this helpful?