May 2017
Intermediate to advanced
388 pages
7h 30m
English
Every time we insert a new item, we set the quantity to one manually, which is what we need when a user adds one product to the cart.
We can specify defaults in the schema and let it take care of it:
quantity: { type: Number, defaultValue: 1, optional: false },
In the cartInsert method, we can clean the document before inserting it:
cartInsert: function(product) { CartCollection.schema.clean(product);
This will add the quantity field to the product document, which was not passed by the client.
Checks with the Schema:
cartInsert: function(product) { check( product, CartCollection.schema);
The way we've added the Schema is by importing the collection and then assigning the schema to it. Another, cleaner, way is to attach a schema ...
Read now
Unlock full access