This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 605
Expand file tree
/
Copy pathpost.js
More file actions
executable file
·65 lines (57 loc) · 1.48 KB
/
post.js
File metadata and controls
executable file
·65 lines (57 loc) · 1.48 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var bongo = require('../../lib');
// Library:
var JsPost = bongo.Model.extend({
// static properties (optional):
schema: {
title : String,
body : {
type : String,
pattern : [
{
errorCode : Math.E,
message : 'the body of your blog post must'
+ ' begin with a capital letter'
},
/^[A-Z]/
]
}
}
},{
// instance properties (named constructor is required):
// you should provide a name for your constructor:
constructor: function JsPost(data) {
// you can call the superconstructor using this.Uber (with a capital U)
this.Uber(data);
},
testMethod: function () {
console.log(this);
},
save: function (callback) {
//intercepted the call to save
console.log('hey from JavaScript!');
return this.uber('save', callback); // you can call a super method using this.uber (lowercase)
}
});
// Application:
JsPost/*or Model or bongo*/.setClient('localhost:27017/test');
new JsPost({
title : 'O hai',
body : 'this is my fantastic blog post!'
})
.on('error', function (err, docs) {
var model = this;
if(err.errors != null) {
err.errors.forEach(function(err){
if (err.errorCode === Math.E) {
model.body = bongo.Inflector.capitalize(model.body);
model.save();
}
})
}
})
.on('validate', log)
.on('save', function (docs) {
log('hooray!', this);
process.kill()
})
.save();