-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcartschema.js
More file actions
25 lines (21 loc) · 860 Bytes
/
cartschema.js
File metadata and controls
25 lines (21 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var mongoose = require('mongoose');
var schema = new mongoose.Schema({
_id: { type: Number, required: true },
quantity: { type: Number, required: true },
product: [{ type: String, ref: 'Product' }]
});
/* Returns the student's first name, which we will define
* to be everything up to the first space in the student's name.
* For instance, "William Bruce Bailey" -> "William" */
schema.virtual('title').get(function () {
//return 'Not Implemented!';
return this.name.split(' ')[0];
});
/* Returns the student's last name, which we will define
* to be everything after the last space in the student's name.
* For instance, "William Bruce Bailey" -> "Bailey" */
schema.virtual('lastName').get(function () {
//return 'Not Implemented!';
return this.name.split(' ')[this.name.split(' ').length - 1]
});
module.exports = schema;