Defining the Billing Schema

With the AddressSchema defined, you can now define the billing schema to keep track of credit card information as well as billing information. Listing 28.2 implements BillingSchema, which contains standard credit card data. Notice that the following implementation for cardtype requires entry of Visa, MasterCard, or Amex (not any other values):

cardtype: { type: String, enum: ['Visa', 'MasterCard', 'Amex'] },

Also notice that the address field is assigned the AddressSchema object type. Mongoose requires you to include nesting schemas in an array. You’ll see this in several places in this example, and you’ll see that throughout the example, that the address is accessed by using address[0] to get the first item in the array.

Listing 28.2 cart_model.js-BillingSchema: Defining a billing schema for credit card information


11 var BillingSchema = new Schema({
12   cardtype: { type: String, enum: ['Visa', 'MasterCard', 'Amex'] },
13   name: String,
14   number: String,
15   expiremonth: Number,
16   expireyear: Number,
17   address: [AddressSchema]
18 }, { _id: false });
19 mongoose.model('Billing', BillingSchema);


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.96.94