Reaction: Use Extended Schemas in Validation

Created on 15 Aug 2016  Â·  7Comments  Â·  Source: reactioncommerce/reaction

Summary

We have extended a number of collections (Cart, Orders, Products) to make Reaction more customized to our needs. But many of the checks performed in the Inventory adjustment methods check only against a Single Schema. Especially in statusChange.js.

Expected Behavior:

I expect when a Collection is extended with a schema, that the Checks look at all of the Collections's schemas not the default one.

Actual Behavior

Throws error: Error: Match error: Match error: variants.gender is not allowed by the schema in field [0]

  "inventory/addReserve": function (cartItems) {
    check(cartItems, [Schemas.CartItem]);
    return Meteor.call("inventory/setStatus", cartItems);
  },
help wanted

Most helpful comment

Oh geez. Apparently this exists now...

https://github.com/aldeed/node-simple-schema

I smell an inevitable refactor...

All 7 comments

I’ve got a couple ideas cooking here trying to work out this issue, but one thing that just occurred to me is I think we probably can’t ever have an arg check use a core schema directly...

// bad
check(cart, Schemas.Cart);

It really has to always use a final attached schema so we will always be checking the result of any custom schemas being added.

So something more like this instead…

// good
check(cart, Cart.simpleSchema());

https://github.com/aldeed/meteor-collection2/#schema-format

Apparently there's an issue standing in the way of using that .simpleSchema() method when you have multiple schemas attached to the same collection...

https://github.com/aldeed/meteor-collection2-core/issues/6

And it's been there since March with no maintainer response. :(

Oh geez. Apparently this exists now...

https://github.com/aldeed/node-simple-schema

I smell an inevitable refactor...

of course there is....

I think we might want to keep this one open (or open another just for the transition to node-simple-schema?

@zenweasel you mean like #1343?

Hmmmm, yes. Very much like that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zikeji picture zikeji  Â·  4Comments

spencern picture spencern  Â·  3Comments

spencern picture spencern  Â·  3Comments

owenhoskins picture owenhoskins  Â·  3Comments

spencern picture spencern  Â·  4Comments